import React from 'react' import styled from 'styled-components' import { ProtectedImage } from './ProtectedMedia' import { MediaType } from '../../__generated__/globalTypes' import { ReactComponent as VideoThumbnailIconSVG } from './icons/videoThumbnailIcon.svg' import { MediaGalleryFields } from './__generated__/MediaGalleryFields' const MediaContainer = styled.div` flex-grow: 1; flex-basis: 0; height: 200px; margin: 2px; background-color: #eee; position: relative; overflow: hidden; ` const StyledPhoto = styled(ProtectedImage)` height: 200px; min-width: 100%; position: relative; object-fit: cover; transition: opacity 300ms; ` type LazyPhotoProps = { src?: string blurhash: string | null } const LazyPhoto = (photoProps: LazyPhotoProps) => { return } const PhotoOverlay = styled.div<{ active: boolean }>` width: 100%; height: 100%; position: absolute; top: 0; left: 0; ${({ active }) => active && ` outline: 4px solid rgba(65, 131, 196, 0.6); outline-offset: -4px; `} ` const HoverIcon = styled.button` font-size: 1.5em; margin: 160px 10px 0 10px; color: white; text-shadow: 0 0 4px black; opacity: 0; position: relative; border-radius: 50%; width: 34px; height: 34px; ${MediaContainer}:hover &, ${MediaContainer}:focus-within & { opacity: 1 !important; } &:hover, &:focus { background-color: rgba(0, 0, 0, 0.4); } transition: opacity 100ms, background-color 100ms; ` type FavoriteIconProps = { favorite: boolean onClick(e: React.MouseEvent): void } const FavoriteIcon = ({ favorite, onClick }: FavoriteIconProps) => { return ( ) } type SidebarIconProps = { onClick(e: React.MouseEvent): void } const SidebarIcon = ({ onClick }: SidebarIconProps) => ( ) const SidebarIconWrapper = styled(HoverIcon)` margin: 10px !important; position: absolute; top: 0; right: 0; ` const VideoThumbnailIcon = styled(VideoThumbnailIconSVG)` color: rgba(255, 255, 255, 0.8); position: absolute; left: calc(50% - 17.5px); top: calc(50% - 22px); ` const Caption = styled.div` position: absolute; right: 6px; bottom: 4px; color: #ffd400; font-size: 12px; font-weight: 600; line-height: 1.2; white-space: nowrap; pointer-events: none; text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff, 0 0 2px rgba(0, 0, 0, 0.35); ` type MediaThumbnailProps = { media: MediaGalleryFields active: boolean caption?: string | null selectImage(): void clickPresent(): void clickFavorite(): void } export const MediaThumbnail = ({ media, active, caption, selectImage, clickPresent, clickFavorite, }: MediaThumbnailProps) => { let heartIcon = null if (media.favorite !== undefined) { heartIcon = ( { e.stopPropagation() clickFavorite() }} /> ) } let videoIcon = null if (media.type == MediaType.Video) { videoIcon = } let minWidth = 100 if (media.thumbnail) { minWidth = Math.floor( (media.thumbnail.width / media.thumbnail.height) * 200 ) } return ( { clickPresent() }} >
{videoIcon} { e.stopPropagation() selectImage() }} /> {heartIcon} {caption && {caption}}
) } export const MediaPlaceholder = styled.div` flex-grow: 1; height: 200px; width: 300px; margin: 2px; background-color: #eee; position: relative; `