From 39b09abc507adbd2c25771f5e43d68c7eedd9161 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Mon, 23 Sep 2024 19:33:51 +0530 Subject: [PATCH] person --- .../Collections/CollectionListBar.tsx | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/web/apps/photos/src/components/Collections/CollectionListBar.tsx b/web/apps/photos/src/components/Collections/CollectionListBar.tsx index 2dfb72c336..d1be124094 100644 --- a/web/apps/photos/src/components/Collections/CollectionListBar.tsx +++ b/web/apps/photos/src/components/Collections/CollectionListBar.tsx @@ -97,7 +97,7 @@ export const CollectionListBar: React.FC = ({ setCollectionListSortBy, people, activePerson, - // onSelectPerson, + onSelectPerson, }) => { const isMobile = useIsMobileWidth(); @@ -162,13 +162,21 @@ export const CollectionListBar: React.FC = ({ useEffect(() => { if (!listRef.current) return; - - // scroll the active collection into view - const activeCollectionIndex = collectionSummaries.findIndex( - (item) => item.id === activeCollectionID, - ); - listRef.current.scrollToItem(activeCollectionIndex, "smart"); - }, [activeCollectionID]); + // Scroll the active item into view. + let i = -1; + switch (mode) { + case "albums": + case "hidden-albums": + i = collectionSummaries.findIndex( + ({ id }) => id == activeCollectionID, + ); + break; + case "people": + i = people.findIndex(({ id }) => id == activePerson?.id); + break; + } + if (i != -1) listRef.current.scrollToItem(i, "smart"); + }, [mode, collectionSummaries, activeCollectionID, people, activePerson]); const itemData = useMemo( () => @@ -180,7 +188,7 @@ export const CollectionListBar: React.FC = ({ onCollectionClick: (id?: number) => setActiveCollectionID(id ?? ALL_SECTION), } - : { type: "people", people, activePerson }, + : { type: "people", people, activePerson, onSelectPerson }, [ mode, collectionSummaries, @@ -188,6 +196,7 @@ export const CollectionListBar: React.FC = ({ setActiveCollectionID, people, activePerson, + onSelectPerson, ], );