From 5e56485a8debf398a524ac3125a93c6462443e4c Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 30 Jan 2023 14:16:17 +0530 Subject: [PATCH] fix open uncategorized section --- src/components/Sidebar/ShortcutSection.tsx | 6 +++-- src/services/collectionService.ts | 26 +--------------------- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/src/components/Sidebar/ShortcutSection.tsx b/src/components/Sidebar/ShortcutSection.tsx index ca880808b..d12e1ee55 100644 --- a/src/components/Sidebar/ShortcutSection.tsx +++ b/src/components/Sidebar/ShortcutSection.tsx @@ -11,6 +11,7 @@ import ShortcutButton from './ShortcutButton'; import DeleteOutline from '@mui/icons-material/DeleteOutline'; import ArchiveOutlined from '@mui/icons-material/ArchiveOutlined'; import CategoryIcon from '@mui/icons-material/Category'; +import { getUncategorizedCollection } from 'services/collectionService'; interface Iprops { closeSidebar: () => void; collectionSummaries: CollectionSummaries; @@ -22,8 +23,9 @@ export default function ShortcutSection({ }: Iprops) { const galleryContext = useContext(GalleryContext); - const openUncategorizedSection = () => { - galleryContext.setActiveCollection(UNCATEGORIZED_SECTION); + const openUncategorizedSection = async () => { + const uncategorisedCollection = await getUncategorizedCollection(); + galleryContext.setActiveCollection(uncategorisedCollection.id); closeSidebar(); }; diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index f774f8478..ba7650de5 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -37,7 +37,6 @@ import { COLLECTION_SORT_ORDER, ALL_SECTION, CollectionSummaryType, - UNCATEGORIZED_SECTION, UNCATEGORIZED_COLLECTION_NAME, FAVORITE_COLLECTION_NAME, } from 'constants/collection'; @@ -850,14 +849,6 @@ export function getCollectionSummaries( ) ); - collectionSummaries.set( - UNCATEGORIZED_SECTION, - getUncategorizedCollectionSummaries( - collectionFilesCount, - collectionLatestFiles - ) - ); - return collectionSummaries; } @@ -934,22 +925,7 @@ function getTrashedCollectionSummaries( }; } -function getUncategorizedCollectionSummaries( - collectionFilesCount: CollectionFilesCount, - collectionsLatestFile: CollectionLatestFiles -): CollectionSummary { - return { - id: UNCATEGORIZED_SECTION, - name: constants.UNCATEGORIZED, - type: CollectionSummaryType.uncategorized, - latestFile: collectionsLatestFile.get(UNCATEGORIZED_SECTION), - fileCount: collectionFilesCount.get(UNCATEGORIZED_SECTION) ?? 0, - updationTime: collectionsLatestFile.get(UNCATEGORIZED_SECTION) - ?.updationTime, - }; -} - -async function getUncategorizedCollection(): Promise { +export async function getUncategorizedCollection(): Promise { const collections = await getLocalCollections(); let uncategorizedCollection = collections.find( (collection) => collection.type === CollectionType.uncategorized