Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[web][photos] Move collection shortcuts to Albums sidebar

Aswin Asokf6d0d8271962
diff --git a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
index 850adc8a0f..77191317db 100644
--- a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
+++ b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
@@ -26,7 +26,6 @@ import {
} from "ente-new/photos/components/gallery/ListHeader";
import {
collectionsSortBy,
- haveOnlySystemCollections,
PseudoCollectionID,
sortCollectionSummaries,
type CollectionsSortBy,
@@ -82,6 +81,9 @@ export const GalleryBarAndListHeader: React.FC<
mode,
user,
barCollectionSummaries: toShowCollectionSummaries,
+ normalCollectionSummaries,
+ uncategorizedCollectionSummaryID,
+ onShowCollectionSummary,
activeCollection,
activeCollectionID,
setActiveCollectionID,
@@ -135,14 +137,6 @@ export const GalleryBarAndListHeader: React.FC<
const [peopleSortBy, setPeopleSortBy] =
useState<PeopleSortBy>("count-desc");
- const shouldBeHidden = useMemo(
- () =>
- shouldHide ||
- (haveOnlySystemCollections(toShowCollectionSummaries) &&
- activeCollectionID === PseudoCollectionID.all),
- [shouldHide, toShowCollectionSummaries, activeCollectionID],
- );
-
const sortedCollectionSummaries = useMemo(
() =>
sortCollectionSummaries(
@@ -259,7 +253,7 @@ export const GalleryBarAndListHeader: React.FC<
// people,
]);
- if (shouldBeHidden) {
+ if (shouldHide) {
return <></>;
}
@@ -275,6 +269,9 @@ export const GalleryBarAndListHeader: React.FC<
peopleSortBy,
collapsed,
mobileDrawerProps,
+ normalCollectionSummaries,
+ uncategorizedCollectionSummaryID,
+ onShowCollectionSummary,
}}
onSelectCollectionID={selectCollection}
onSelectPerson={selectPerson}
@@ -282,12 +279,17 @@ export const GalleryBarAndListHeader: React.FC<
onChangePeopleSortBy={setPeopleSortBy}
onShowAllAlbums={showAllAlbums}
onShowAllPeople={showAllPeople}
- collectionSummaries={sortedCollectionSummaries.filter((cs) =>
- mode == "albums"
- ? !cs.attributes.has("system") ||
- (cs.id > 0 && cs.type == "uncategorized")
- : !cs.attributes.has("hideFromCollectionBar") &&
- !cs.attributes.has("quickLink"),
+ collectionSummaries={sortedCollectionSummaries.filter(
+ (cs) =>
+ cs.id !== uncategorizedCollectionSummaryID &&
+ cs.id !== PseudoCollectionID.hiddenItems &&
+ cs.id !== PseudoCollectionID.archiveItems &&
+ cs.id !== PseudoCollectionID.trash &&
+ (mode == "albums"
+ ? !cs.attributes.has("system") ||
+ (cs.id > 0 && cs.type == "uncategorized")
+ : !cs.attributes.has("hideFromCollectionBar") &&
+ !cs.attributes.has("quickLink")),
)}
/>
diff --git a/web/apps/photos/src/components/gallery/BarImpl.tsx b/web/apps/photos/src/components/gallery/BarImpl.tsx
index a04eeb60ae..45ac3f47a4 100644
--- a/web/apps/photos/src/components/gallery/BarImpl.tsx
+++ b/web/apps/photos/src/components/gallery/BarImpl.tsx
@@ -6,15 +6,25 @@ import {
type AlbumFilter,
} from "@/utils/album-filters";
import type { PeopleSortBy } from "@/utils/people-sort";
-import { Link05Icon, PinIcon, StarIcon } from "@hugeicons/core-free-icons";
+import {
+ Delete02Icon,
+ Download05Icon,
+ GeometricShapes01Icon,
+ Link05Icon,
+ PinIcon,
+ StarIcon,
+ ViewOffSlashIcon,
+} from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import ArchiveIcon from "@mui/icons-material/Archive";
import CloseIcon from "@mui/icons-material/Close";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
+import LockOutlinedIcon from "@mui/icons-material/LockOutlined";
import PeopleIcon from "@mui/icons-material/People";
import {
Box,
ButtonBase,
+ Divider,
Drawer,
IconButton,
Stack,
@@ -26,12 +36,15 @@ import {
} from "@mui/material";
import type { ModalVisibilityProps } from "ente-base/components/utils/modal";
import { ItemCard } from "ente-new/photos/components/Tiles";
-import type {
- CollectionSummary,
- CollectionSummaryAttribute,
- CollectionsSortBy,
+import {
+ PseudoCollectionID,
+ type CollectionSummaries,
+ type CollectionSummary,
+ type CollectionSummaryAttribute,
+ type CollectionsSortBy,
} from "ente-new/photos/services/collection-summary";
import type { Person } from "ente-new/photos/services/ml/people";
+import { wait } from "ente-utils/promise";
import { t } from "i18next";
import React, {
memo,
@@ -57,6 +70,12 @@ export interface GalleryBarPresentationProps {
export interface GalleryBarImplProps extends GalleryBarPresentationProps {
mode: GalleryBarMode;
collectionSummaries: CollectionSummary[];
+ normalCollectionSummaries: CollectionSummaries;
+ uncategorizedCollectionSummaryID: number;
+ onShowCollectionSummary: (
+ collectionSummaryID: number,
+ isHiddenCollectionSummary?: boolean,
+ ) => Promise<boolean>;
activeCollectionID: number | undefined;
onSelectCollectionID: (collectionID: number) => void;
onShowAllAlbums: () => void;
@@ -73,6 +92,9 @@ export interface GalleryBarImplProps extends GalleryBarPresentationProps {
export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
mode,
collectionSummaries,
+ normalCollectionSummaries,
+ uncategorizedCollectionSummaryID,
+ onShowCollectionSummary,
activeCollectionID,
onSelectCollectionID,
onShowAllAlbums,
@@ -195,7 +217,12 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
mode == "albums"
? getItemCount(itemData) * (mobile ? 46 : 50)
: undefined,
- minHeight: 0,
+ minHeight:
+ mode == "albums" && getItemCount(itemData) > 0
+ ? mobile
+ ? 46
+ : 50
+ : 0,
minWidth: 0,
}}
>
@@ -318,7 +345,12 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
<Stack
role="group"
aria-label={t("filter_albums")}
- sx={{ flex: 1, minHeight: 0, gap: "2px" }}
+ sx={{
+ flex: 1,
+ minHeight: 0,
+ gap: "2px",
+ overflowY: "auto",
+ }}
>
{visibleAlbumFilters.map((filter) => (
<React.Fragment key={filter.value}>
@@ -366,6 +398,76 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
) : (
items
)}
+ {mode != "people" && (
+ <Stack sx={{ flexShrink: 0, gap: "2px", pb: "8px" }}>
+ <Divider sx={{ mb: "8px" }} />
+ {[
+ {
+ id: uncategorizedCollectionSummaryID,
+ label: t("section_uncategorized"),
+ icon: GeometricShapes01Icon,
+ active:
+ activeCollectionID ==
+ uncategorizedCollectionSummaryID,
+ },
+ {
+ id: PseudoCollectionID.hiddenItems,
+ label: t("section_hidden"),
+ icon: ViewOffSlashIcon,
+ active: mode == "hidden-albums",
+ },
+ {
+ id: PseudoCollectionID.archiveItems,
+ label: t("section_archive"),
+ icon: Download05Icon,
+ active: mode == "archive-albums",
+ },
+ {
+ id: PseudoCollectionID.trash,
+ label: t("section_trash"),
+ icon: Delete02Icon,
+ active:
+ activeCollectionID == PseudoCollectionID.trash,
+ },
+ ].map(({ id, label, icon, active }) => (
+ <BarCard
+ key={id}
+ aria-label={label}
+ aria-current={active ? "true" : undefined}
+ onClick={() => {
+ void onShowCollectionSummary(
+ id,
+ id == PseudoCollectionID.hiddenItems,
+ ).then(async (success) => {
+ if (!success || !mobile) return;
+ if (id == PseudoCollectionID.hiddenItems)
+ await wait(10);
+ mobileDrawerProps.onClose();
+ });
+ }}
+ sx={{ flexShrink: 0 }}
+ >
+ <HugeiconsIcon icon={icon} size={20} aria-hidden />
+ <CardText>{label}</CardText>
+ {id == PseudoCollectionID.hiddenItems ? (
+ <LockOutlinedIcon
+ sx={{ color: "text.muted", fontSize: 19 }}
+ />
+ ) : (
+ <Typography
+ variant="small"
+ sx={{ color: "text.muted" }}
+ >
+ {
+ normalCollectionSummaries.get(id)
+ ?.fileCount
+ }
+ </Typography>
+ )}
+ </BarCard>
+ ))}
+ </Stack>
+ )}
</Stack>
);
diff --git a/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx b/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx
index 81bbf133a4..843a4a2b0a 100644
--- a/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx
+++ b/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx
@@ -76,13 +76,7 @@ export const PhotosNavigationShell: React.FC<
}, [props.mode, props.isInSearchMode]);
useEffect(() => {
if (!mobile) closeMobileNavigation();
- else if (
- props.mode == "hidden-albums" ||
- props.mode == "archive-albums"
- ) {
- showMobileNavigation();
- }
- }, [mobile, props.mode, closeMobileNavigation, showMobileNavigation]);
+ }, [mobile, closeMobileNavigation]);
const handleChangeMode = (mode: GalleryBarMode) => {
const reopeningSection =
mobile &&
@@ -315,7 +309,10 @@ const NormalNavigationRail: React.FC<
aria-pressed={
navigationOpen &&
!props.isInSearchMode &&
- mode == item
+ (mode == item ||
+ (item == "albums" &&
+ (mode == "hidden-albums" ||
+ mode == "archive-albums")))
}
aria-haspopup={opensDialog ? "dialog" : undefined}
onClick={() => onChangeMode(item)}
diff --git a/web/apps/photos/src/components/gallery/helpers.ts b/web/apps/photos/src/components/gallery/helpers.ts
index 4217cdb0d3..9d6ae459b7 100644
--- a/web/apps/photos/src/components/gallery/helpers.ts
+++ b/web/apps/photos/src/components/gallery/helpers.ts
@@ -13,6 +13,47 @@ import {
restoreToCollection,
} from "ente-new/photos/services/collection";
import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";
+import type { SidebarActionID } from "ente-new/photos/services/search/types";
+
+export const albumShortcutCollectionID = (
+ actionID: SidebarActionID,
+ uncategorizedCollectionSummaryID: number,
+): number | undefined => {
+ switch (actionID) {
+ case "shortcuts.uncategorized":
+ return uncategorizedCollectionSummaryID;
+ case "shortcuts.hidden":
+ return PseudoCollectionID.hiddenItems;
+ case "shortcuts.archive":
+ return PseudoCollectionID.archiveItems;
+ case "shortcuts.trash":
+ return PseudoCollectionID.trash;
+ default:
+ return undefined;
+ }
+};
+
+export const showCollectionSummaryWithAuthentication = async (
+ collectionSummaryID: number | undefined,
+ requiresAuthentication: boolean,
+ lastAuthentication: { current: number },
+ authenticateUser: () => Promise<boolean>,
+ onShowCollectionSummary: (id: number | undefined) => void,
+): Promise<boolean> => {
+ if (
+ requiresAuthentication &&
+ Date.now() - lastAuthentication.current > 5 * 60 * 1e3
+ ) {
+ try {
+ if (!(await authenticateUser())) return false;
+ lastAuthentication.current = Date.now();
+ } catch {
+ return false;
+ }
+ }
+ onShowCollectionSummary(collectionSummaryID);
+ return true;
+};
export const findCollectionCreatingIfNeeded = async (
collections: Collection[],
diff --git a/web/apps/photos/src/components/sidebar/Sidebar.tsx b/web/apps/photos/src/components/sidebar/Sidebar.tsx
index 78aa26565e..5e03c757ea 100644
--- a/web/apps/photos/src/components/sidebar/Sidebar.tsx
+++ b/web/apps/photos/src/components/sidebar/Sidebar.tsx
@@ -2,15 +2,7 @@ import { Export } from "@/components/Export";
import { downloadAppDialogAttributes } from "@/components/utils/download";
import exportService from "@/services/export";
import { performSidebarAction as performSidebarRegistryAction } from "@/services/search/sidebar-search-registry";
-import {
- Delete02Icon,
- Download05Icon,
- GeometricShapes01Icon,
- ViewOffSlashIcon,
-} from "@hugeicons/core-free-icons";
-import { HugeiconsIcon } from "@hugeicons/react";
import CloseIcon from "@mui/icons-material/Close";
-import LockOutlinedIcon from "@mui/icons-material/LockOutlined";
import {
Box,
Dialog,
@@ -25,10 +17,7 @@ import Typography from "@mui/material/Typography";
import { isDesktop } from "ente-base/app";
import { LinkButton } from "ente-base/components/LinkButton";
import { AttributedMiniDialog } from "ente-base/components/MiniDialog";
-import {
- RowButton,
- RowButtonEndActivityIndicator,
-} from "ente-base/components/RowButton";
+import { RowButtonEndActivityIndicator } from "ente-base/components/RowButton";
import { SpacedRow } from "ente-base/components/containers";
import { SidebarDrawer } from "ente-base/components/mui/SidebarDrawer";
import { SidebarPanelContext } from "ente-base/components/mui/SidebarDrawerContext";
@@ -43,10 +32,6 @@ import { useBaseContext } from "ente-base/context";
import log from "ente-base/log";
import { customAPIHost } from "ente-base/origins";
import { useUserDetailsSnapshot } from "ente-new/photos/components/utils/use-snapshot";
-import {
- PseudoCollectionID,
- type CollectionSummaries,
-} from "ente-new/photos/services/collection-summary";
import type { SidebarActionID } from "ente-new/photos/services/search/types";
import {
hasExceededStorageQuota,
@@ -64,7 +49,6 @@ import {
type UserDetails,
} from "ente-new/photos/services/user-details";
import { usePhotosAppContext } from "ente-new/photos/types/context";
-import { wait } from "ente-utils/promise";
import { t } from "i18next";
import React, {
useCallback,
@@ -87,17 +71,11 @@ import { Preferences, type PreferencesAction } from "./preferences/Preferences";
import { sidebarTheme } from "./theme";
type SidebarProps = ModalVisibilityProps & {
- normalCollectionSummaries: CollectionSummaries;
- uncategorizedCollectionSummaryID: number;
pendingAction?: SidebarActionID;
onActionHandled?: (actionID: SidebarActionID) => void;
onShowLargeFiles: () => void;
onShowDuplicates: () => void;
onShowPlanSelector: () => void;
- onShowCollectionSummary: (
- collectionSummaryID: number,
- isHiddenCollectionSummary?: boolean,
- ) => Promise<void>;
collectionNameByID: Map<number, string>;
onCloseOverlays: () => void;
children?: React.ReactNode;
@@ -109,14 +87,11 @@ export const Sidebar: React.FC<SidebarProps> = ({
onClose: closeRoot,
onCloseOverlays,
children,
- normalCollectionSummaries,
- uncategorizedCollectionSummaryID,
pendingAction,
onActionHandled,
onShowPlanSelector,
onShowLargeFiles,
onShowDuplicates,
- onShowCollectionSummary,
collectionNameByID,
onAuthenticateUser,
}) => {
@@ -250,7 +225,6 @@ export const Sidebar: React.FC<SidebarProps> = ({
if (actionID !== "utility.export") closeSections();
return performSidebarRegistryAction(actionID, {
onClose,
- onShowCollectionSummary,
onShowPlanSelector,
showAccount,
showReferrals,
@@ -260,12 +234,6 @@ export const Sidebar: React.FC<SidebarProps> = ({
onShowExport: handleShowExport,
onLogout: handleLogout,
onShowWatchFolder: handleOpenWatchFolder,
- pseudoIDs: {
- uncategorized: uncategorizedCollectionSummaryID,
- archive: PseudoCollectionID.archiveItems,
- hidden: PseudoCollectionID.hiddenItems,
- trash: PseudoCollectionID.trash,
- },
setPendingAccountAction: (a) =>
setPendingAccountAction(a as AccountAction | undefined),
setPendingPreferencesAction: (a) =>
@@ -285,7 +253,6 @@ export const Sidebar: React.FC<SidebarProps> = ({
handleLogout,
handleOpenWatchFolder,
onClose,
- onShowCollectionSummary,
onShowPlanSelector,
handleShowExport,
showAccount,
@@ -293,7 +260,6 @@ export const Sidebar: React.FC<SidebarProps> = ({
showHelp,
showPreferences,
showReferrals,
- uncategorizedCollectionSummaryID,
],
);
@@ -350,14 +316,6 @@ export const Sidebar: React.FC<SidebarProps> = ({
},
}}
>
- <ShortcutSection
- onCloseSidebar={onClose}
- {...{
- normalCollectionSummaries,
- uncategorizedCollectionSummaryID,
- onShowCollectionSummary,
- }}
- />
<UtilitySection
{...{
showExport: handleShowExport,
@@ -816,122 +774,6 @@ const SubscriptionStatus: React.FC<SubscriptionStatusProps> = ({
);
};
-type ShortcutSectionProps = SectionProps &
- Pick<
- SidebarProps,
- | "normalCollectionSummaries"
- | "uncategorizedCollectionSummaryID"
- | "onShowCollectionSummary"
- >;
-
-const ShortcutSection: React.FC<ShortcutSectionProps> = ({
- onCloseSidebar,
- normalCollectionSummaries,
- uncategorizedCollectionSummaryID,
- onShowCollectionSummary,
-}) => {
- const shortcutIconSize = 20;
-
- const handleOpenUncategorizedSection = () =>
- void onShowCollectionSummary(uncategorizedCollectionSummaryID).then(
- onCloseSidebar,
- );
-
- const handleOpenTrashSection = () =>
- void onShowCollectionSummary(PseudoCollectionID.trash).then(
- onCloseSidebar,
- );
-
- const handleOpenArchiveSection = () =>
- void onShowCollectionSummary(PseudoCollectionID.archiveItems).then(
- onCloseSidebar,
- );
-
- const handleOpenHiddenSection = () =>
- void onShowCollectionSummary(PseudoCollectionID.hiddenItems, true)
- // Let focus settle before closing to avoid aria-hidden warnings.
- .then(() => wait(10))
- .then(onCloseSidebar);
-
- const summaryCaption = (summaryID: number) =>
- normalCollectionSummaries.get(summaryID)?.fileCount.toString();
-
- return (
- <Stack
- sx={(theme) => ({
- mx: 0.5,
- gap: 0.5,
- "&&& > .MuiButton-root": {
- bgcolor: theme.colorSchemes.light?.palette.fill.faint,
- "&:hover": {
- bgcolor: theme.colorSchemes.light?.palette.fill.muted,
- },
- ...theme.applyStyles("dark", {
- bgcolor: theme.colorSchemes.dark?.palette.fill.faint,
- "&:hover": {
- bgcolor:
- theme.colorSchemes.dark?.palette.fill.muted,
- },
- }),
- },
- })}
- >
- <RowButton
- startIcon={
- <HugeiconsIcon
- icon={GeometricShapes01Icon}
- size={shortcutIconSize}
- aria-hidden
- />
- }
- label={t("section_uncategorized")}
- caption={summaryCaption(uncategorizedCollectionSummaryID)}
- onClick={handleOpenUncategorizedSection}
- />
- <RowButton
- startIcon={
- <HugeiconsIcon
- icon={Download05Icon}
- size={shortcutIconSize}
- />
- }
- label={t("section_archive")}
- caption={summaryCaption(PseudoCollectionID.archiveItems)}
- onClick={handleOpenArchiveSection}
- />
- <RowButton
- startIcon={
- <HugeiconsIcon
- icon={ViewOffSlashIcon}
- size={shortcutIconSize}
- />
- }
- label={t("section_hidden")}
- caption={
- <LockOutlinedIcon
- sx={{
- verticalAlign: "middle",
- fontSize: "19px !important",
- }}
- />
- }
- onClick={handleOpenHiddenSection}
- />
- <RowButton
- startIcon={
- <HugeiconsIcon
- icon={Delete02Icon}
- size={shortcutIconSize}
- />
- }
- label={t("section_trash")}
- caption={summaryCaption(PseudoCollectionID.trash)}
- onClick={handleOpenTrashSection}
- />
- </Stack>
- );
-};
-
interface UtilitySectionProps {
showExport: () => void;
showAccount: () => void;
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 882419fe84..77d726330a 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -39,8 +39,10 @@ import { LargeFilesView } from "@/components/gallery/LargeFilesView";
import { PhotosNavigationShell } from "@/components/gallery/PhotosNavigationShell";
import { TrashFilesDialog } from "@/components/gallery/TrashFilesDialog";
import {
+ albumShortcutCollectionID,
findCollectionCreatingIfNeeded,
performCollectionOp,
+ showCollectionSummaryWithAuthentication,
} from "@/components/gallery/helpers";
import {
useGalleryReducer,
@@ -1359,8 +1361,21 @@ const Page: React.FC = () => {
options?: { shouldExitSearchMode?: boolean },
) => {
if (searchOption) {
- setCleanupView(undefined);
const type = searchOption.suggestion.type;
+ if (type == "sidebarAction") {
+ const collectionID = albumShortcutCollectionID(
+ searchOption.suggestion.actionID,
+ state.uncategorizedCollectionSummaryID,
+ );
+ if (collectionID !== undefined) {
+ void showCollectionSummary(
+ collectionID,
+ collectionID == PseudoCollectionID.hiddenItems,
+ );
+ return;
+ }
+ }
+ setCleanupView(undefined);
if (type == "collection") {
dispatch({
type: "showCollectionSummary",
@@ -1413,27 +1428,17 @@ const Page: React.FC = () => {
);
const showCollectionSummary = useCallback(
- async (
+ (
collectionSummaryID: number | undefined,
- isHiddenCollectionSummary: boolean | undefined,
- ) => {
- const lastAuthAt = lastAuthenticationForHiddenTimestamp.current;
-
- if (
- isHiddenCollectionSummary &&
- barMode != "hidden-albums" &&
- Date.now() - lastAuthAt > 5 * 60 * 1e3
- ) {
- try {
- if (!(await authenticateUser())) return;
- lastAuthenticationForHiddenTimestamp.current = Date.now();
- } catch {
- return;
- }
- }
-
- handleShowCollectionSummaryWithID(collectionSummaryID);
- },
+ isHiddenCollectionSummary?: boolean,
+ ) =>
+ showCollectionSummaryWithAuthentication(
+ collectionSummaryID,
+ !!isHiddenCollectionSummary && barMode != "hidden-albums",
+ lastAuthenticationForHiddenTimestamp,
+ authenticateUser,
+ handleShowCollectionSummaryWithID,
+ ),
[authenticateUser, handleShowCollectionSummaryWithID, barMode],
);
@@ -1462,8 +1467,6 @@ const Page: React.FC = () => {
[handleShowCleanupView],
);
- const handleSidebarShowCollectionSummary = showCollectionSummary;
-
const handleDownloadStatusNotificationsShowCollectionSummary = useCallback(
(
collectionSummaryID: number | undefined,
@@ -2014,6 +2017,10 @@ const Page: React.FC = () => {
mode: barMode,
shouldHide: isInSearchMode,
barCollectionSummaries,
+ normalCollectionSummaries,
+ uncategorizedCollectionSummaryID:
+ state.uncategorizedCollectionSummaryID,
+ onShowCollectionSummary: showCollectionSummary,
emailByUserID: state.emailByUserID,
shareSuggestionEmails:
state.shareSuggestionEmails,
@@ -2194,14 +2201,9 @@ const Page: React.FC = () => {
onClose={handleSidebarClose}
onShowLargeFiles={handleShowLargeFiles}
onShowDuplicates={handleShowDuplicates}
- normalCollectionSummaries={normalCollectionSummaries}
- uncategorizedCollectionSummaryID={
- state.uncategorizedCollectionSummaryID
- }
pendingAction={pendingSidebarAction}
onActionHandled={handleSidebarActionHandled}
onShowPlanSelector={showPlanSelector}
- onShowCollectionSummary={handleSidebarShowCollectionSummary}
collectionNameByID={collectionNameByID}
onCloseOverlays={closeSidebarOverlays}
onAuthenticateUser={authenticateUser}
diff --git a/web/apps/photos/src/services/search/sidebar-search-registry.ts b/web/apps/photos/src/services/search/sidebar-search-registry.ts
index 133c22e7fe..85da3c45a2 100644
--- a/web/apps/photos/src/services/search/sidebar-search-registry.ts
+++ b/web/apps/photos/src/services/search/sidebar-search-registry.ts
@@ -5,7 +5,6 @@ import type {
SearchOption,
SidebarActionID,
} from "ente-new/photos/services/search/types";
-import { wait } from "ente-utils/promise";
import { t } from "i18next";
interface SidebarAction {
@@ -18,10 +17,6 @@ interface SidebarAction {
interface SidebarActionContext {
onClose: () => void;
- onShowCollectionSummary: (
- collectionSummaryID: number,
- isHidden?: boolean,
- ) => Promise<void>;
showAccount: () => void;
showReferrals: () => void;
showPreferences: () => void;
@@ -31,12 +26,6 @@ interface SidebarActionContext {
onShowPlanSelector: () => void;
onLogout: () => void;
onShowWatchFolder: () => void;
- pseudoIDs: {
- uncategorized: number;
- archive: number;
- hidden: number;
- trash: number;
- };
setPendingAccountAction: (a: SidebarActionID | undefined) => void;
setPendingPreferencesAction: (a: SidebarActionID | undefined) => void;
setPendingHelpAction: (a: SidebarActionID | undefined) => void;
@@ -46,7 +35,7 @@ interface SidebarActionContext {
// Construct sidebar actions at call time so we always use initialized i18n
// strings instead of whatever was available when this module was first loaded.
const sidebarActions = (): SidebarAction[] => {
- const shortcutsCategory = t("shortcuts", { defaultValue: "Shortcuts" });
+ const albumsCategory = t("albums");
const preferencesCategory = t("preferences");
const accountCategory = t("account");
const helpCategory = t("help");
@@ -61,25 +50,25 @@ const sidebarActions = (): SidebarAction[] => {
{
id: "shortcuts.uncategorized",
label: t("section_uncategorized"),
- path: [shortcutsCategory, t("section_uncategorized")],
+ path: [albumsCategory, t("section_uncategorized")],
keywords: ["uncategorized", "ungrouped"],
},
{
id: "shortcuts.archive",
label: t("section_archive"),
- path: [shortcutsCategory, t("section_archive")],
+ path: [albumsCategory, t("section_archive")],
keywords: ["archive", "archived"],
},
{
id: "shortcuts.hidden",
label: t("section_hidden"),
- path: [shortcutsCategory, t("section_hidden")],
+ path: [albumsCategory, t("section_hidden")],
keywords: ["hidden", "private"],
},
{
id: "shortcuts.trash",
label: t("section_trash"),
- path: [shortcutsCategory, t("section_trash")],
+ path: [albumsCategory, t("section_trash")],
keywords: ["trash", "bin", "deleted"],
},
{
@@ -330,27 +319,6 @@ export const performSidebarAction = async (
ctx: SidebarActionContext,
): Promise<void> => {
switch (actionID) {
- case "shortcuts.uncategorized":
- return ctx
- .onShowCollectionSummary(ctx.pseudoIDs.uncategorized, false)
- .then(() => ctx.onClose());
- case "shortcuts.archive":
- return ctx
- .onShowCollectionSummary(ctx.pseudoIDs.archive, false)
- .then(() => ctx.onClose());
- case "shortcuts.hidden":
- return (
- ctx
- .onShowCollectionSummary(ctx.pseudoIDs.hidden, true)
- // Let focus settle before closing to avoid aria-hidden warnings.
- .then(() => wait(10))
- .then(() => ctx.onClose())
- );
- case "shortcuts.trash":
- return ctx
- .onShowCollectionSummary(ctx.pseudoIDs.trash, false)
- .then(() => ctx.onClose());
-
case "utility.account":
ctx.showAccount();
return Promise.resolve();
diff --git a/web/apps/photos/tests/gallery-helpers.test.ts b/web/apps/photos/tests/gallery-helpers.test.ts
index 77a4db0492..2d3470aed7 100644
--- a/web/apps/photos/tests/gallery-helpers.test.ts
+++ b/web/apps/photos/tests/gallery-helpers.test.ts
@@ -3,8 +3,10 @@ import type { EnteFile } from "ente-media/file";
import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";
import { beforeEach, describe, expect, test, vi } from "vitest";
import {
+ albumShortcutCollectionID,
findCollectionCreatingIfNeeded,
performCollectionOp,
+ showCollectionSummaryWithAuthentication,
} from "../src/components/gallery/helpers";
const collectionService = vi.hoisted(() => ({
@@ -68,3 +70,94 @@ describe("findCollectionCreatingIfNeeded", () => {
).resolves.toBe(defaultHiddenCollection);
});
});
+
+describe("album shortcut navigation", () => {
+ test("routes collection shortcuts without consuming settings actions", () => {
+ expect(albumShortcutCollectionID("shortcuts.uncategorized", 42)).toBe(
+ 42,
+ );
+ expect(albumShortcutCollectionID("shortcuts.hidden", 42)).toBe(
+ PseudoCollectionID.hiddenItems,
+ );
+ expect(albumShortcutCollectionID("shortcuts.archive", 42)).toBe(
+ PseudoCollectionID.archiveItems,
+ );
+ expect(albumShortcutCollectionID("shortcuts.trash", 42)).toBe(
+ PseudoCollectionID.trash,
+ );
+ expect(
+ albumShortcutCollectionID("utility.preferences", 42),
+ ).toBeUndefined();
+ });
+
+ test("cancelled or failed authentication does not navigate or refresh authentication", async () => {
+ for (const authenticate of [
+ vi.fn().mockResolvedValue(false),
+ vi.fn().mockRejectedValue(new Error("Authentication failed")),
+ ]) {
+ const lastAuthentication = { current: 0 };
+ const navigate = vi.fn();
+ await expect(
+ showCollectionSummaryWithAuthentication(
+ PseudoCollectionID.hiddenItems,
+ true,
+ lastAuthentication,
+ authenticate,
+ navigate,
+ ),
+ ).resolves.toBe(false);
+ expect(navigate).not.toHaveBeenCalled();
+ expect(lastAuthentication.current).toBe(0);
+ }
+ });
+
+ test("successful Hidden authentication is reused for five minutes", async () => {
+ const lastAuthentication = { current: 0 };
+ const authenticate = vi.fn().mockResolvedValue(true);
+ const navigate = vi.fn();
+ for (let i = 0; i < 2; i++) {
+ await expect(
+ showCollectionSummaryWithAuthentication(
+ PseudoCollectionID.hiddenItems,
+ true,
+ lastAuthentication,
+ authenticate,
+ navigate,
+ ),
+ ).resolves.toBe(true);
+ }
+ expect(authenticate).toHaveBeenCalledTimes(1);
+ expect(navigate).toHaveBeenCalledTimes(2);
+ lastAuthentication.current -= 5 * 60 * 1e3 + 1;
+ await showCollectionSummaryWithAuthentication(
+ PseudoCollectionID.hiddenItems,
+ true,
+ lastAuthentication,
+ authenticate,
+ navigate,
+ );
+ expect(authenticate).toHaveBeenCalledTimes(2);
+ });
+
+ test("regular collections and an already open Hidden section skip authentication", async () => {
+ const authenticate = vi.fn();
+ const navigate = vi.fn();
+ for (const id of [
+ 42,
+ PseudoCollectionID.trash,
+ PseudoCollectionID.hiddenItems,
+ ]) {
+ await expect(
+ showCollectionSummaryWithAuthentication(
+ id,
+ false,
+ { current: 0 },
+ authenticate,
+ navigate,
+ ),
+ ).resolves.toBe(true);
+ expect(navigate).toHaveBeenLastCalledWith(id);
+ }
+ expect(authenticate).not.toHaveBeenCalled();
+ });
+});