From 446b7bbd009a170031ab7ff8ebc9b1dadade3ea3 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Tue, 17 Jun 2025 17:18:09 +0530 Subject: [PATCH] Conv --- web/apps/photos/src/components/Sidebar.tsx | 52 ++++++++----------- web/apps/photos/src/pages/gallery.tsx | 3 ++ .../photos/src/services/collectionService.ts | 22 ++------ 3 files changed, 31 insertions(+), 46 deletions(-) diff --git a/web/apps/photos/src/components/Sidebar.tsx b/web/apps/photos/src/components/Sidebar.tsx index 9c76ba958e..ecb5da5ce7 100644 --- a/web/apps/photos/src/components/Sidebar.tsx +++ b/web/apps/photos/src/components/Sidebar.tsx @@ -78,7 +78,6 @@ import { useSettingsSnapshot, useUserDetailsSnapshot, } from "ente-new/photos/components/utils/use-snapshot"; -import { DUMMY_UNCATEGORIZED_COLLECTION } from "ente-new/photos/services/collection"; import { CollectionSummaryID, type CollectionSummaries, @@ -122,18 +121,22 @@ import React, { useState, } from "react"; import { Trans } from "react-i18next"; -import { getUncategorizedCollection } from "services/collectionService"; import { testUpload } from "../../tests/upload.test"; import { SubscriptionCard } from "./SubscriptionCard"; type SidebarProps = ModalVisibilityProps & { /** - * The latest UI collections. + * The latest set of collections, sections and pseudo-collections. * - * These are used to obtain data about the uncategorized, hidden and other - * items shown in the shortcut section within the sidebar. + * These are used to obtain data about the archive, hidden and trash + * "section" entries shown within the shortcut section of the sidebar. */ collectionSummaries: CollectionSummaries; + /** + * The ID of the collection summary that should be shown when the user + * activates the "Uncategorized" section shortcut. + */ + uncategorizedCollectionSummaryID: number; /** * Called when the plan selection modal should be shown. */ @@ -155,6 +158,7 @@ export const Sidebar: React.FC = ({ open, onClose, collectionSummaries, + uncategorizedCollectionSummaryID, onShowPlanSelector, onShowExport, onAuthenticateUser, @@ -165,7 +169,7 @@ export const Sidebar: React.FC = ({ = ({ ); }; -type ShortcutSectionProps = SectionProps & { - collectionSummaries: SidebarProps["collectionSummaries"]; -}; +type ShortcutSectionProps = SectionProps & + Pick< + SidebarProps, + "collectionSummaries" | "uncategorizedCollectionSummaryID" + >; const ShortcutSection: React.FC = ({ onCloseSidebar, collectionSummaries, + uncategorizedCollectionSummaryID, }) => { const galleryContext = useContext(GalleryContext); - const [uncategorizedCollectionID, setUncategorizedCollectionID] = - useState(CollectionSummaryID.uncategorizedPlaceholder); - - useEffect(() => { - void getUncategorizedCollection().then((uncat) => - setUncategorizedCollectionID( - uncat?.id ?? DUMMY_UNCATEGORIZED_COLLECTION, - ), - ); - }, []); const openUncategorizedSection = () => { - galleryContext.setActiveCollectionID(uncategorizedCollectionID); + galleryContext.setActiveCollectionID(uncategorizedCollectionSummaryID); onCloseSidebar(); }; @@ -471,22 +468,21 @@ const ShortcutSection: React.FC = ({ }); }; + const summaryCaption = (collectionSummaryID: number) => + collectionSummaries.get(collectionSummaryID)?.fileCount.toString(); + return ( <> } label={t("section_uncategorized")} - caption={collectionSummaries - .get(uncategorizedCollectionID) - ?.fileCount.toString()} + caption={summaryCaption(uncategorizedCollectionSummaryID)} onClick={openUncategorizedSection} /> } label={t("section_archive")} - caption={collectionSummaries - .get(CollectionSummaryID.archiveItems) - ?.fileCount.toString()} + caption={summaryCaption(CollectionSummaryID.archiveItems)} onClick={openArchiveSection} /> = ({ } label={t("section_trash")} - caption={collectionSummaries - .get(CollectionSummaryID.trash) - ?.fileCount.toString()} + caption={summaryCaption(CollectionSummaryID.trash)} onClick={openTrashSection} /> diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx index 1a296ec2aa..15a6c6bb93 100644 --- a/web/apps/photos/src/pages/gallery.tsx +++ b/web/apps/photos/src/pages/gallery.tsx @@ -1068,6 +1068,9 @@ const Page: React.FC = () => { c.type == "uncategorized") ?? + (await createUncategorizedCollection()); + await moveToCollection( sourceCollectionID, uncategorizedCollection, @@ -286,19 +287,6 @@ function compareCollectionsLatestFile( } } -export async function getUncategorizedCollection( - collections?: Collection[], -): Promise { - if (!collections) { - collections = await getLocalCollections(); - } - const uncategorizedCollection = collections.find( - (collection) => collection.type == "uncategorized", - ); - - return uncategorizedCollection; -} - export async function getDefaultHiddenCollection(): Promise { const collections = await getLocalCollections("hidden"); const hiddenCollection = collections.find((collection) =>