From f11c1d6e5194e3ffd23cd96f51e1434df8191c06 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Tue, 26 Jul 2022 14:02:33 +0530 Subject: [PATCH] move getUser to top caller and add null check there itself --- src/pages/gallery/index.tsx | 13 +++++++++---- src/services/collectionService.ts | 5 +---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index f81714da7..395ea2e61 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -99,6 +99,8 @@ import { NotificationAttributes } from 'types/Notification'; import { ITEM_TYPE, TimeStampListItem } from 'components/PhotoList'; import UploadInputs from 'components/UploadSelectorInputs'; import useFileInput from 'hooks/useFileInput'; +import { User } from 'types/user'; +import { getData, LS_KEYS } from 'utils/storage/localStorage'; export const DeadCenter = styled('div')` flex: 1; @@ -260,7 +262,11 @@ export default function Gallery() { }, []); useEffect(() => { - setDerivativeState(collections, files); + const user: User = getData(LS_KEYS.USER); + if (!user || !files || !collections) { + return; + } + setDerivativeState(user, collections, files); }, [collections, files]); useEffect( @@ -375,18 +381,17 @@ export default function Gallery() { }; const setDerivativeState = async ( + user: User, collections: Collection[], files: EnteFile[] ) => { - if (!collections || !files) { - return; - } const favItemIds = await getFavItemIds(files); setFavItemIds(favItemIds); const archivedCollections = getArchivedCollections(collections); setArchivedCollections(archivedCollections); const collectionSummaries = getCollectionSummaries( + user, collections, files, archivedCollections diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index d7b41b685..1f69e357a 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -770,14 +770,11 @@ function compareCollectionsLatestFile(first: EnteFile, second: EnteFile) { } export function getCollectionSummaries( + user: User, collections: Collection[], files: EnteFile[], archivedCollections: Set ): CollectionSummaries { - const user: User = getData(LS_KEYS.USER); - if (!user) { - return; - } const collectionSummaries: CollectionSummaries = new Map(); const collectionLatestFiles = getCollectionLatestFiles( files,