From bc0399dfeb74f6ca5ffd48ef6531d59291a3bc03 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Thu, 3 Apr 2025 12:09:32 +0530 Subject: [PATCH] Prune 2 --- .../src/components/Collections/AllAlbums.tsx | 42 +++++++------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/web/apps/photos/src/components/Collections/AllAlbums.tsx b/web/apps/photos/src/components/Collections/AllAlbums.tsx index c1b50f852e..24bc6c089d 100644 --- a/web/apps/photos/src/components/Collections/AllAlbums.tsx +++ b/web/apps/photos/src/components/Collections/AllAlbums.tsx @@ -21,7 +21,6 @@ import { import type { CollectionSummary } from "ente-new/photos/services/collection/ui"; import { CollectionsSortBy } from "ente-new/photos/services/collection/ui"; import { FlexWrapper, FluidContainer } from "ente-shared/components/Container"; -import useWindowSize from "ente-shared/hooks/useWindowSize"; import { t } from "i18next"; import memoize from "memoize-one"; import React, { useEffect, useMemo, useRef, useState } from "react"; @@ -81,7 +80,7 @@ export const AllAlbums: React.FC = ({ ); }; -export const AllCollectionMobileBreakpoint = 559; +const Column3To2Breakpoint = 559; const AllAlbumsDialog = styled(Dialog)(({ theme }) => ({ "& .MuiDialog-container": { justifyContent: "flex-end" }, @@ -91,7 +90,7 @@ const AllAlbumsDialog = styled(Dialog)(({ theme }) => ({ paddingRight: theme.spacing(1), }, "& .MuiDialogContent-root": { padding: theme.spacing(2) }, - [theme.breakpoints.down(AllCollectionMobileBreakpoint)]: { + [theme.breakpoints.down(Column3To2Breakpoint)]: { "& .MuiPaper-root": { width: "324px" }, "& .MuiDialogContent-root": { padding: 6 }, }, @@ -139,9 +138,6 @@ const Title = ({ ); -const MobileColumns = 2; -const DesktopColumns = 3; - const CollectionRowItemSize = 154; interface ItemData { @@ -199,15 +195,16 @@ const AllAlbumsContent: React.FC = ({ collectionSummaries, onCollectionClick, }) => { + const isTwoColumn = useMediaQuery(`(width < ${Column3To2Breakpoint}px)`); + const columns = isTwoColumn ? 2 : 3; + const refreshInProgress = useRef(false); const shouldRefresh = useRef(false); const [collectionRowList, setCollectionRowList] = useState([]); - const windowSize = useWindowSize(); - useEffect(() => { - if (!windowSize.width || !collectionSummaries) { + if (!collectionSummaries) { return; } const main = async () => { @@ -219,10 +216,6 @@ const AllAlbumsContent: React.FC = ({ const collectionRowList: CollectionSummary[][] = []; let index = 0; - const columns = - windowSize.width > AllCollectionMobileBreakpoint - ? DesktopColumns - : MobileColumns; while (index < collectionSummaries.length) { const collectionRow: CollectionSummary[] = []; for ( @@ -242,23 +235,21 @@ const AllAlbumsContent: React.FC = ({ } }; main(); - }, [collectionSummaries, windowSize]); + }, [collectionSummaries]); // Bundle additional data to list items using the "itemData" prop. // It will be accessible to item renderers as props.data. // Memoize this data to avoid bypassing shouldComponentUpdate(). const itemData = createItemData(collectionRowList, onCollectionClick); - const maxListContentHeight = useMemo(() => { - // DesktopColumns give us an upper bound. - return ( - Math.ceil(collectionSummaries.length / DesktopColumns) * + const maxListContentHeight = useMemo( + () => + Math.ceil(collectionSummaries.length / columns) * CollectionRowItemSize + - 32 - ); - }, [collectionSummaries]); + 32 /* padding above first and below last row */, + [collectionSummaries], + ); - console.log(collectionSummaries.length, maxListContentHeight); return ( = ({ height: `min(80svh, ${maxListContentHeight}px)`, }} > - - {({ height }) => ( + + {({ width, height }) => (