From 352382cd0523fa3b395696d3a46e66f58e8d5c63 Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Mon, 30 Jan 2023 11:49:34 -0500 Subject: [PATCH] Use Grid + Aspect to size MediaItem --- .../account-gallery/components/media-item.tsx | 9 +++------ app/soapbox/features/account-gallery/index.tsx | 12 ++---------- .../features/ui/components/group-media-panel.tsx | 3 +-- .../features/ui/components/profile-media-panel.tsx | 3 +-- 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/app/soapbox/features/account-gallery/components/media-item.tsx b/app/soapbox/features/account-gallery/components/media-item.tsx index 5a363aff8..f980c0217 100644 --- a/app/soapbox/features/account-gallery/components/media-item.tsx +++ b/app/soapbox/features/account-gallery/components/media-item.tsx @@ -11,11 +11,10 @@ import type { Attachment } from 'soapbox/types/entities'; interface IMediaItem { attachment: Attachment, - displayWidth: number, onOpenMedia: (attachment: Attachment) => void, } -const MediaItem: React.FC = ({ attachment, displayWidth, onOpenMedia }) => { +const MediaItem: React.FC = ({ attachment, onOpenMedia }) => { const settings = useSettings(); const autoPlayGif = settings.get('autoPlayGif'); const displayMedia = settings.get('displayMedia'); @@ -53,8 +52,6 @@ const MediaItem: React.FC = ({ attachment, displayWidth, onOpenMedia } }; - const width = `${Math.floor((displayWidth - 4) / 3) - 4}px`; - const height = width; const status = attachment.get('status'); const title = status.get('spoiler_text') || attachment.get('description'); @@ -124,8 +121,8 @@ const MediaItem: React.FC = ({ attachment, displayWidth, onOpenMedia } return ( -
- +
+ { const isLoading = useAppSelector((state) => state.timelines.get(`account:${accountId}:media`)?.isLoading); const hasMore = useAppSelector((state) => state.timelines.get(`account:${accountId}:media`)?.hasMore); - const [width, setWidth] = useState(323); const node = useRef(null); const handleScrollToBottom = () => { @@ -96,12 +95,6 @@ const AccountGallery = () => { } }; - useLayoutEffect(() => { - if (node.current) { - setWidth(node.current.offsetWidth); - } - }, [node.current]); - useEffect(() => { if (accountId && accountId !== -1) { dispatch(fetchAccount(accountId)); @@ -143,14 +136,13 @@ const AccountGallery = () => { return ( -
+
{attachments.map((attachment, index) => attachment === null ? ( 0 ? (attachments.get(index - 1)?.id || null) : null} onLoadMore={handleLoadMore} /> ) : ( ))} diff --git a/app/soapbox/features/ui/components/group-media-panel.tsx b/app/soapbox/features/ui/components/group-media-panel.tsx index 904ed77d5..d59b79236 100644 --- a/app/soapbox/features/ui/components/group-media-panel.tsx +++ b/app/soapbox/features/ui/components/group-media-panel.tsx @@ -50,12 +50,11 @@ const GroupMediaPanel: React.FC = ({ group }) => { if (!nineAttachments.isEmpty()) { return ( -
+
{nineAttachments.map((attachment, _index) => ( ))} diff --git a/app/soapbox/features/ui/components/profile-media-panel.tsx b/app/soapbox/features/ui/components/profile-media-panel.tsx index b958ca09a..0dbfaf7f3 100644 --- a/app/soapbox/features/ui/components/profile-media-panel.tsx +++ b/app/soapbox/features/ui/components/profile-media-panel.tsx @@ -51,12 +51,11 @@ const ProfileMediaPanel: React.FC = ({ account }) => { if (!nineAttachments.isEmpty()) { return ( -
+
{nineAttachments.map((attachment, _index) => ( ))}