import React, { useContext } from 'react' import styled from 'styled-components' import { MediaThumbnail, MediaPlaceholder } from './MediaThumbnail' import PresentView from './presentView/PresentView' import { openPresentModeAction, PhotoGalleryAction, MediaGalleryState, } from './mediaGalleryReducer' import { toggleFavoriteAction, useMarkFavoriteMutation, } from './photoGalleryMutations' import MediaSidebar from '../sidebar/MediaSidebar/MediaSidebar' import { SidebarContext } from '../sidebar/Sidebar' import { gql } from '@apollo/client' import { mediaCaption } from '../../helpers/mediaCaption' const Gallery = styled.div` display: flex; flex-wrap: wrap; align-items: center; min-height: 200px; position: relative; margin: -2px; @media (max-width: 1000px) { /* Compensate for tab bar on mobile */ margin-bottom: 76px; } ` export const PhotoFiller = styled.div` height: 200px; flex-grow: 999999; ` export const MEDIA_GALLERY_FRAGMENT = gql` fragment MediaGalleryFields on Media { id title type blurhash thumbnail { url width height } highRes { url } videoWeb { url } favorite } ` type MediaGalleryProps = { loading: boolean mediaState: MediaGalleryState dispatchMedia: React.Dispatch } const MediaGallery = ({ mediaState, dispatchMedia }: MediaGalleryProps) => { const [markFavorite] = useMarkFavoriteMutation() const { media, activeIndex, presenting } = mediaState const { updateSidebar } = useContext(SidebarContext) let mediaElements = [] if (media) { mediaElements = media.map((media, index) => { const active = activeIndex == index const caption = mediaCaption(media.title) const captionText = caption ? `${caption.date}${caption.city ? ` ${caption.city}` : ''}` : null return ( { dispatchMedia({ type: 'selectImage', index, }) updateSidebar() }} clickFavorite={() => { toggleFavoriteAction({ media, markFavorite, }) }} clickPresent={() => { dispatchMedia({ type: 'selectImage', index, }) updateSidebar() }} /> ) }) } else { for (let i = 0; i < 6; i++) { mediaElements.push() } } return ( <> {mediaElements} {/* PresentView disabled — click opens sidebar instead */} {/* presenting && ( ) */} ) } export default MediaGallery