Skip to content

armgit / ente

Public Imported from GitHub
0

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

refactor(photos):move-settings-sidebar-into-navigation-shell

Aswin Asok99992323ac58
diff --git a/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx b/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx
index 1f91085c4b..497f8b4562 100644
--- a/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx
+++ b/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx
@@ -1,5 +1,6 @@
import { CreateAlbumDialog } from "@/components/collections/CreateAlbumDialog";
import { SearchBar, type SearchBarProps } from "@/components/SearchBar";
+import { Sidebar } from "@/components/sidebar/Sidebar";
import { useIsOffline } from "@/components/utils/use-is-offline";
import { uploadManager } from "@/services/upload-manager";
import {
@@ -24,6 +25,7 @@ import {
useTheme,
} from "@mui/material";
import { EnteLogo, EnteLogoBox } from "ente-base/components/EnteLogo";
+import { TranslucentLoadingOverlay } from "ente-base/components/loaders";
import type { ButtonishProps } from "ente-base/components/mui";
import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";
import { NavbarBase } from "ente-base/components/Navbar";
@@ -33,8 +35,15 @@ import { ut } from "ente-base/i18n";
import { thumbnailGridPadding } from "ente-new/photos/components/utils/thumbnail-grid-layout";
import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";
import { isMLSupported } from "ente-new/photos/services/ml";
+import type { SidebarActionID } from "ente-new/photos/services/search/types";
import { t } from "i18next";
-import { useCallback, useEffect, useState, type ReactNode } from "react";
+import {
+ useCallback,
+ useEffect,
+ useImperativeHandle,
+ useState,
+ type ReactNode,
+} from "react";
import type { RemotePullOpts } from ".";
import {
@@ -65,21 +74,50 @@ type PhotosNavigationShellProps = SearchBarProps & {
onChangeMode: (mode: GalleryBarMode) => boolean;
};
+export interface PhotosNavigationShellHandle {
+ showSettings: (action?: SidebarActionID) => void;
+}
+
export const PhotosNavigationShell: React.FC<
React.PropsWithChildren<
- PhotosNavigationShellProps & {
+ Omit<PhotosNavigationShellProps, "isSettingsOpen" | "onSidebar"> & {
+ ref?: React.Ref<PhotosNavigationShellHandle>;
isFirstLoad: boolean;
alternateHeader: ReactNode;
galleryNavigation: GalleryNavigation | undefined;
+ collectionNameByID: Map<number, string>;
+ onShowCleanupView: (view: "large-files" | "duplicates") => void;
+ onAuthenticateUser: () => Promise<boolean>;
}
>
> = ({
+ ref,
isFirstLoad,
alternateHeader,
galleryNavigation,
+ collectionNameByID,
+ onShowCleanupView,
+ onAuthenticateUser,
children,
...props
}) => {
+ const { show: showSidebar, props: sidebarVisibilityProps } =
+ useModalVisibility();
+ const [pendingSidebarAction, setPendingSidebarAction] =
+ useState<SidebarActionID>();
+ const [settingsLoading, setSettingsLoading] = useState(false);
+ const showSettings = useCallback(
+ (action?: SidebarActionID) => {
+ setPendingSidebarAction(action);
+ showSidebar();
+ },
+ [showSidebar],
+ );
+ const handleSidebarActionHandled = useCallback(
+ () => setPendingSidebarAction(undefined),
+ [],
+ );
+ useImperativeHandle(ref, () => ({ showSettings }), [showSettings]);
const isOffline = useIsOffline();
const reduceMotion = useMediaQuery("(prefers-reduced-motion: reduce)");
const [navigationCollapsed, setNavigationCollapsed] = useState(false);
@@ -250,6 +288,8 @@ export const PhotosNavigationShell: React.FC<
{alternateHeader == null && (
<NormalNavigationRail
{...props}
+ isSettingsOpen={sidebarVisibilityProps.open}
+ onSidebar={() => showSettings()}
onShowMap={() => {
props.onShowMap();
setNavigationCollapsed(false);
@@ -334,6 +374,17 @@ export const PhotosNavigationShell: React.FC<
</Stack>
</Stack>
</Stack>
+ <Sidebar
+ {...sidebarVisibilityProps}
+ pendingAction={pendingSidebarAction}
+ onActionHandled={handleSidebarActionHandled}
+ onShowLargeFiles={() => onShowCleanupView("large-files")}
+ onShowDuplicates={() => onShowCleanupView("duplicates")}
+ collectionNameByID={collectionNameByID}
+ onAuthenticateUser={onAuthenticateUser}
+ setLoading={setSettingsLoading}
+ />
+ {settingsLoading && <TranslucentLoadingOverlay />}
</Stack>
);
};
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index c592162363..17dd4d3ca2 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -35,7 +35,10 @@ import { AlbumsOverview } from "@/components/gallery/AlbumsOverview";
import { DuplicatesView } from "@/components/gallery/DuplicatesView";
import { LargeFilesView } from "@/components/gallery/LargeFilesView";
import { PeopleOverview } from "@/components/gallery/PeopleOverview";
-import { PhotosNavigationShell } from "@/components/gallery/PhotosNavigationShell";
+import {
+ PhotosNavigationShell,
+ type PhotosNavigationShellHandle,
+} from "@/components/gallery/PhotosNavigationShell";
import type { PlaceSelection } from "@/components/gallery/PlacesList";
import { PublicLinkDetails } from "@/components/gallery/PublicLinkDetails";
import {
@@ -49,7 +52,6 @@ import {
type GalleryBarMode,
} from "@/components/gallery/reducer";
import { useAlbumNavigationData } from "@/components/gallery/use-album-navigation-data";
-import { Sidebar } from "@/components/sidebar/Sidebar";
import {
notifyOthersFilesDialogAttributes,
notifyUnsupportedSharedFavoritesDialogAttributes,
@@ -168,10 +170,7 @@ import {
filterSearchableFiles,
updateSearchCollectionsAndFiles,
} from "ente-new/photos/services/search";
-import type {
- SearchOption,
- SidebarActionID,
-} from "ente-new/photos/services/search/types";
+import type { SearchOption } from "ente-new/photos/services/search/types";
import {
initSettings,
updateMapEnabled,
@@ -291,14 +290,10 @@ const Page: React.FC = () => {
CollectionOp | undefined
>(undefined);
const postCreateAlbumHidden = useRef(false);
- const [pendingSidebarAction, setPendingSidebarAction] = useState<
- SidebarActionID | undefined
- >(undefined);
+ const navigationRef = useRef<PhotosNavigationShellHandle>(null);
const lastAuthenticationForHiddenTimestamp = useRef<number>(0);
- const { show: showSidebar, props: sidebarVisibilityProps } =
- useModalVisibility();
const { show: showPeopleConsent, props: peopleConsentVisibilityProps } =
useModalVisibility();
const pendingPeopleSearchReset = useRef<(() => void) | undefined>(
@@ -384,16 +379,6 @@ const Page: React.FC = () => {
}
}, []);
- const showSubscriptionSettings = useCallback(() => {
- setPendingSidebarAction("subscription");
- showSidebar();
- }, [showSidebar]);
-
- const handleSidebarActionHandled = useCallback(
- () => setPendingSidebarAction(undefined),
- [],
- );
-
const {
user,
favoriteFileIDs,
@@ -870,7 +855,6 @@ const Page: React.FC = () => {
!filteredFiles.length ||
uploadTypeSelectorView ||
openCollectionSelector ||
- sidebarVisibilityProps.open ||
fixCreationTimeVisibilityProps.open ||
authenticateUserVisibilityProps.open ||
albumNameInputVisibilityProps.open ||
@@ -1515,8 +1499,9 @@ const Page: React.FC = () => {
personID: searchOption.suggestion.person.id,
});
} else if (type == "sidebarAction") {
- setPendingSidebarAction(searchOption.suggestion.actionID);
- showSidebar();
+ navigationRef.current?.showSettings(
+ searchOption.suggestion.actionID,
+ );
const shouldExitSearchMode =
options?.shouldExitSearchMode ?? true;
@@ -1595,15 +1580,6 @@ const Page: React.FC = () => {
[closeCollectionMap, closeSlideshow],
);
- const handleShowLargeFiles = useCallback(
- () => handleShowCleanupView("large-files"),
- [handleShowCleanupView],
- );
- const handleShowDuplicates = useCallback(
- () => handleShowCleanupView("duplicates"),
- [handleShowCleanupView],
- );
-
const handleDownloadStatusNotificationsShowCollectionSummary = useCallback(
(
collectionSummaryID: number | undefined,
@@ -2200,9 +2176,12 @@ const Page: React.FC = () => {
onRemotePull={remotePull}
/>
<PhotosNavigationShell
+ ref={navigationRef}
isFirstLoad={isFirstLoad}
isInSearchMode={isInSearchMode}
- isSettingsOpen={sidebarVisibilityProps.open}
+ collectionNameByID={collectionNameByID}
+ onShowCleanupView={handleShowCleanupView}
+ onAuthenticateUser={authenticateUser}
mode={barMode}
isMapView={isMapView}
isMapSelected={
@@ -2214,7 +2193,6 @@ const Page: React.FC = () => {
if (changed) setIsMapView(false);
return changed;
}}
- onSidebar={showSidebar}
onUpload={openUploader}
onShowMap={() => {
setSelectedPlace(undefined);
@@ -2525,20 +2503,12 @@ const Page: React.FC = () => {
onUploadFile={(file) =>
dispatch({ type: "uploadFile", file })
}
- onShowSubscription={showSubscriptionSettings}
+ onShowSubscription={() =>
+ navigationRef.current?.showSettings("subscription")
+ }
onShowSessionExpiredDialog={showSessionExpiredDialog}
isInHiddenSection={barMode == "hidden-albums"}
/>
- <Sidebar
- {...sidebarVisibilityProps}
- onShowLargeFiles={handleShowLargeFiles}
- onShowDuplicates={handleShowDuplicates}
- pendingAction={pendingSidebarAction}
- onActionHandled={handleSidebarActionHandled}
- collectionNameByID={collectionNameByID}
- setLoading={setBlockingLoad}
- onAuthenticateUser={authenticateUser}
- />
<DesktopWhatsNew />
<PeopleConsentDialog
{...peopleConsentVisibilityProps}