From dea417340de16a758d8316149f1d7aba1b1e5241 Mon Sep 17 00:00:00 2001 From: clintonlunn Date: Sun, 19 Nov 2023 17:11:46 -0700 Subject: [PATCH] refactoring photogallerymodal to look more like recentmediacard --- src/components/media/GalleryImageCard.tsx | 83 +++++++++++++++++++ src/components/media/PhotoGalleryModal.tsx | 36 ++------ .../media/__tests__/PhotoGalleryModal.tsx | 3 +- src/components/ui/MobileDialog.tsx | 2 +- 4 files changed, 91 insertions(+), 33 deletions(-) create mode 100644 src/components/media/GalleryImageCard.tsx diff --git a/src/components/media/GalleryImageCard.tsx b/src/components/media/GalleryImageCard.tsx new file mode 100644 index 000000000..f2d448acf --- /dev/null +++ b/src/components/media/GalleryImageCard.tsx @@ -0,0 +1,83 @@ +import { useState } from 'react' +import Image from 'next/image' +import clx from 'classnames' +import Card from '../ui/Card/Card' +import TagList from '../media/TagList' +import { MobileLoader } from '../../js/sirv/util' +import { MediaWithTags } from '../../js/types' +import { getUploadDateSummary } from '../../js/utils' +import { PostHeader } from '../home/Post' + +const MOBILE_IMAGE_MAX_WIDITH = 600 + +interface GalleryImageCardProps { + header?: JSX.Element + mediaWithTags: MediaWithTags + onImageClick?: (event: React.MouseEvent, mediaWithTags: MediaWithTags) => void +} + +/** + * Image card for the gallery page + */ +export const GalleryImageCard = ({ + mediaWithTags, + onImageClick +}: GalleryImageCardProps): JSX.Element => { + const [loaded, setLoaded] = useState(false) + const { mediaUrl, width, height, username } = mediaWithTags + const imageRatio = width / height + return ( + } + image={ +
+ setLoaded(true)} + className='rounded-md' + onClick={(event) => { + if (onImageClick != null) { + console.log('onImageClick') + event.stopPropagation() + event.preventDefault() + onImageClick(event, mediaWithTags) + } + }} + /> +
+ {loaded} +
+
+ } + body={ + <> +
+ + + {getUploadDateSummary(mediaWithTags.uploadTime)} + +
+ + } + /> + ) +} diff --git a/src/components/media/PhotoGalleryModal.tsx b/src/components/media/PhotoGalleryModal.tsx index 4c26c8644..56c3004c0 100644 --- a/src/components/media/PhotoGalleryModal.tsx +++ b/src/components/media/PhotoGalleryModal.tsx @@ -1,11 +1,10 @@ import React, { Dispatch, SetStateAction, useState } from 'react' import { userMediaStore } from '../../js/stores/media' -import ResponsiveImage, { ResponsiveImage2 } from './slideshow/ResponsiveImage' +import ResponsiveImage from './slideshow/ResponsiveImage' import { MobileDialog, DialogContent } from '../ui/MobileDialog' import { XMarkIcon } from '@heroicons/react/24/outline' -import TagList from './TagList' -import clx from 'classnames' import { MediaWithTags } from '../../js/types' +import { GalleryImageCard } from './GalleryImageCard' export interface PhotoGalleryModalProps { setShowPhotoGalleryModal: Dispatch> @@ -23,7 +22,6 @@ const PhotoGalleryModal = ({ // Fetch the list of photos. const photoList = userMediaStore.use.photoList() - console.log('photoList', photoList) return (
{photoList.map((mediaWithTags) => { - const { mediaUrl, width, height, entityTags } = mediaWithTags - return (
setImageProperties(mediaWithTags)} - key={mediaUrl} - className='overflow-hidden mt-0 mb-2 lg:mb-4 hover:brightness-75 break-inside-avoid-column cursor-pointer break-inside-avoid relative block rounded-md' + key={mediaWithTags.mediaUrl} + className='overflow-hidden hover:brightness-75 break-inside-avoid-column cursor-pointer relative block rounded-md mb-4' > - -
- -
+ setImageProperties(mediaWithTags)} />
) })} diff --git a/src/components/media/__tests__/PhotoGalleryModal.tsx b/src/components/media/__tests__/PhotoGalleryModal.tsx index 77b2aa836..fbc5a2ce8 100644 --- a/src/components/media/__tests__/PhotoGalleryModal.tsx +++ b/src/components/media/__tests__/PhotoGalleryModal.tsx @@ -12,7 +12,8 @@ describe('', () => { mediaUrl: 'test.jpg', width: 200, height: 200, - entityTags: [] + entityTags: [], + uploadTime: 1667766325921 } ]) } diff --git a/src/components/ui/MobileDialog.tsx b/src/components/ui/MobileDialog.tsx index e6eece3a9..ed33b457d 100644 --- a/src/components/ui/MobileDialog.tsx +++ b/src/components/ui/MobileDialog.tsx @@ -28,7 +28,7 @@ export const DialogContent = React.forwardRef( {children} {/* Use absolute positioning to place the close button on the upper left corner */} -