π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat(settings):add-two-panel-sidebar-shell
Aswin Asok37769b9b9600
diff --git a/web/apps/photos/src/components/sidebar/ReferralSettings.tsx b/web/apps/photos/src/components/sidebar/ReferralSettings.tsxindex ce00002fbe..05241607d1 100644--- a/web/apps/photos/src/components/sidebar/ReferralSettings.tsx+++ b/web/apps/photos/src/components/sidebar/ReferralSettings.tsx@@ -271,6 +271,7 @@ export const ReferralSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({return (<TitledNestedSidebarDrawermaxWidth="440px"+ showBackButton={screen != "main" ? true : undefined}{...{ open }}onClose={handleClose}onRootClose={handleRootClose}diff --git a/web/apps/photos/src/components/sidebar/Sidebar.tsx b/web/apps/photos/src/components/sidebar/Sidebar.tsxindex 59b11548ef..0156835b04 100644--- a/web/apps/photos/src/components/sidebar/Sidebar.tsx+++ b/web/apps/photos/src/components/sidebar/Sidebar.tsx@@ -71,6 +71,7 @@ import { Trans } from "react-i18next";import { FreeUpSpace, type FreeUpSpaceAction } from "./FreeUpSpace";import { Help, type HelpAction } from "./Help";import { ReferralSettings } from "./ReferralSettings";+import { SidebarDrawerShell } from "./SidebarDrawerShell";import { WatchFolder } from "./WatchFolder";import { SubscriptionCard } from "./account/SubscriptionCard";import { Account, type AccountAction } from "./accounts/Account";@@ -89,12 +90,16 @@ type SidebarProps = ModalVisibilityProps & {isHiddenCollectionSummary?: boolean,) => Promise<void>;onShowExport: () => void;+ onCloseOverlays: () => void;+ children?: React.ReactNode;onAuthenticateUser: () => Promise<boolean>;};export const Sidebar: React.FC<SidebarProps> = ({open,- onClose,+ onClose: closeRoot,+ onCloseOverlays,+ children,normalCollectionSummaries,uncategorizedCollectionSummaryID,pendingAction,@@ -124,6 +129,39 @@ export const Sidebar: React.FC<SidebarProps> = ({const [pendingFreeUpSpaceAction, setPendingFreeUpSpaceAction] =useState<FreeUpSpaceAction>();+ const closeAccount = accountVisibilityProps.onClose;+ const closeReferrals = referralsVisibilityProps.onClose;+ const closePreferences = preferencesVisibilityProps.onClose;+ const closeHelp = helpVisibilityProps.onClose;+ const closeFreeUpSpace = freeUpSpaceVisibilityProps.onClose;+ const closeSections = useCallback(() => {+ closeAccount();+ closeReferrals();+ closePreferences();+ closeHelp();+ closeFreeUpSpace();+ setWatchFolderView(false);+ onCloseOverlays();+ }, [+ closeAccount,+ closeReferrals,+ closePreferences,+ closeHelp,+ closeFreeUpSpace,+ setWatchFolderView,+ onCloseOverlays,+ ]);++ const onClose = useCallback(() => {+ closeSections();+ closeRoot();+ }, [closeSections, closeRoot]);++ const selectSection = (show: () => void) => () => {+ closeSections();+ show();+ };+const handleLogout = useCallback(() =>showMiniDialog({@@ -165,8 +203,9 @@ export const Sidebar: React.FC<SidebarProps> = ({}, [onAuthenticateUser, onShowExport, showMiniDialog]);const performSidebarAction = useCallback(- async (actionID: SidebarActionID) =>- performSidebarRegistryAction(actionID, {+ async (actionID: SidebarActionID) => {+ closeSections();+ return performSidebarRegistryAction(actionID, {onClose,onShowCollectionSummary,onShowPlanSelector,@@ -196,8 +235,10 @@ export const Sidebar: React.FC<SidebarProps> = ({setPendingFreeUpSpaceAction(a as FreeUpSpaceAction | undefined,),- }),+ });+ },[+ closeSections,handleLogout,handleOpenWatchFolder,onClose,@@ -230,55 +271,67 @@ export const Sidebar: React.FC<SidebarProps> = ({}, [pendingAction]);return (- <RootSidebarDrawer open={open} onClose={onClose} maxWidth="440px">- <HeaderSection onCloseSidebar={onClose} />- <UserDetailsSection- sidebarOpen={open}- {...{ onShowPlanSelector }}- />- <Stack sx={{ gap: 0.5, mb: 3 }}>- <ShortcutSection- onCloseSidebar={onClose}- {...{- normalCollectionSummaries,- uncategorizedCollectionSummaryID,- onShowCollectionSummary,- }}- />- <UtilitySection- onCloseSidebar={onClose}- {...{- onShowExport: handleShowExport,- onAuthenticateUser,- onShowPlanSelector,- showAccount,- accountVisibilityProps,- showReferrals,- referralsVisibilityProps,- showPreferences,- preferencesVisibilityProps,- showHelp,- helpVisibilityProps,- showFreeUpSpace,- freeUpSpaceVisibilityProps,- watchFolderView,- onShowWatchFolder: handleOpenWatchFolder,- onCloseWatchFolder: handleCloseWatchFolder,- pendingAccountAction,- onAccountActionHandled: setPendingAccountAction,- pendingPreferencesAction,- onPreferencesActionHandled: setPendingPreferencesAction,- pendingHelpAction,- onHelpActionHandled: setPendingHelpAction,- pendingFreeUpSpaceAction,- onFreeUpSpaceActionHandled: setPendingFreeUpSpaceAction,- }}+ <SidebarDrawerShell open={open} onClose={onClose}>+ <RootSidebarDrawer+ open={open}+ onClose={onClose}+ maxWidth="440px"+ shellRoot+ >+ <HeaderSection onCloseSidebar={onClose} />+ <UserDetailsSection+ sidebarOpen={open}+ {...{ onShowPlanSelector }}/>- <Divider sx={{ my: "2px" }} />- <ExitSection onLogout={handleLogout} />- <InfoSection />- </Stack>- </RootSidebarDrawer>+ <Stack sx={{ gap: 0.5, mb: 3 }}>+ <ShortcutSection+ onCloseSidebar={onClose}+ {...{+ normalCollectionSummaries,+ uncategorizedCollectionSummaryID,+ onShowCollectionSummary,+ }}+ />+ <UtilitySection+ onCloseSidebar={onClose}+ {...{+ onShowExport: selectSection(handleShowExport),+ onAuthenticateUser,+ onShowPlanSelector,+ showAccount: selectSection(showAccount),+ accountVisibilityProps,+ showReferrals: selectSection(showReferrals),+ referralsVisibilityProps,+ showPreferences: selectSection(showPreferences),+ preferencesVisibilityProps,+ showHelp: selectSection(showHelp),+ helpVisibilityProps,+ showFreeUpSpace: selectSection(showFreeUpSpace),+ freeUpSpaceVisibilityProps,+ watchFolderView,+ onShowWatchFolder: selectSection(+ handleOpenWatchFolder,+ ),+ onCloseWatchFolder: handleCloseWatchFolder,+ pendingAccountAction,+ onAccountActionHandled: setPendingAccountAction,+ pendingPreferencesAction,+ onPreferencesActionHandled:+ setPendingPreferencesAction,+ pendingHelpAction,+ onHelpActionHandled: setPendingHelpAction,+ pendingFreeUpSpaceAction,+ onFreeUpSpaceActionHandled:+ setPendingFreeUpSpaceAction,+ }}+ />+ <Divider sx={{ my: "2px" }} />+ <ExitSection onLogout={handleLogout} />+ <InfoSection />+ </Stack>+ </RootSidebarDrawer>+ {children}+ </SidebarDrawerShell>);};diff --git a/web/apps/photos/src/components/sidebar/SidebarDrawerShell.tsx b/web/apps/photos/src/components/sidebar/SidebarDrawerShell.tsxnew file mode 100644index 0000000000..6fcf972359--- /dev/null+++ b/web/apps/photos/src/components/sidebar/SidebarDrawerShell.tsx@@ -0,0 +1,100 @@+import {+ Box,+ Dialog,+ ThemeProvider,+ useMediaQuery,+ useTheme,+} from "@mui/material";+import { SidebarPanelContext } from "ente-base/components/mui/SidebarDrawerContext";+import type { ModalVisibilityProps } from "ente-base/components/utils/modal";+import { t } from "i18next";+import React, { useRef } from "react";++/** Keeps the root Photos menu beside its nested settings. */+export function SidebarDrawerShell({+ open,+ onClose,+ children,+}: React.PropsWithChildren<ModalVisibilityProps>) {+ const theme = useTheme();+ const wide = useMediaQuery(theme.breakpoints.up("md"));+ const panel = useRef<HTMLDivElement>(null);+ const container = () => panel.current;++ // ponytail: retain the existing stacked layout on narrow screens.+ if (!wide) return children;++ return (+ <Dialog+ open={open}+ onClose={onClose}+ maxWidth={false}+ aria-label={t("settings")}+ slotProps={{+ paper: {+ sx: {+ width: "min(1200px, calc(100vw - 48px))",+ height: "calc(100dvh - 48px)",+ maxHeight: "none",+ m: 3,+ borderRadius: 3,+ overflow: "hidden",+ },+ },+ }}+ >+ <SidebarPanelContext.Provider value={container}>+ <ThemeProvider+ theme={{+ ...theme,+ components: {+ ...theme.components,+ MuiDialog: {+ ...theme.components?.MuiDialog,+ defaultProps: {+ ...theme.components?.MuiDialog+ ?.defaultProps,+ container,+ disableEnforceFocus: true,+ },+ styleOverrides: {+ ...theme.components?.MuiDialog+ ?.styleOverrides,+ root: [+ theme.components?.MuiDialog+ ?.styleOverrides?.root,+ { position: "absolute" },+ ],+ },+ },+ MuiBackdrop: {+ ...theme.components?.MuiBackdrop,+ styleOverrides: {+ ...theme.components?.MuiBackdrop+ ?.styleOverrides,+ root: [+ theme.components?.MuiBackdrop+ ?.styleOverrides?.root,+ { position: "absolute" },+ ],+ },+ },+ },+ }}+ >+ {children}+ <Box+ ref={panel}+ sx={{+ position: "absolute",+ inset: "0 0 0 360px",+ bgcolor: "background.default",+ borderLeft: 1,+ borderColor: "divider",+ }}+ />+ </ThemeProvider>+ </SidebarPanelContext.Provider>+ </Dialog>+ );+}diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 39e5ea8c82..6545de24cb 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -368,9 +368,20 @@ const Page: React.FC = () => {}}, []);+ const closeSidebarOverlays = useCallback(() => {+ exportVisibilityProps.onClose();+ planSelectorVisibilityProps.onClose();+ familyManagementVisibilityProps.onClose();+ }, [+ exportVisibilityProps.onClose,+ planSelectorVisibilityProps.onClose,+ familyManagementVisibilityProps.onClose,+ ]);+const handleSidebarClose = useCallback(() => {+ closeSidebarOverlays();sidebarVisibilityProps.onClose();- }, [sidebarVisibilityProps.onClose]);+ }, [closeSidebarOverlays, sidebarVisibilityProps.onClose]);const handleSidebarActionHandled = useCallback(() => setPendingSidebarAction(undefined),@@ -1846,15 +1857,8 @@ const Page: React.FC = () => {return <div></div>;}- return (- <FullScreenDropZone- message={- watchFolderView ? t("watch_folder_dropzone_hint") : undefined- }- disabled={shouldDisableDropzone || !!slideshow}- onDrop={setDragAndDropFiles}- >- {blockingLoad && <TranslucentLoadingOverlay />}+ const subscriptionDialogs = (+ <><PlanSelector{...planSelectorVisibilityProps}setLoading={(v) => setBlockingLoad(v)}@@ -1864,6 +1868,19 @@ const Page: React.FC = () => {{...familyManagementVisibilityProps}onShowPlanSelector={showPlanSelector}/>+ </>+ );++ return (+ <FullScreenDropZone+ message={+ watchFolderView ? t("watch_folder_dropzone_hint") : undefined+ }+ disabled={shouldDisableDropzone || !!slideshow}+ onDrop={setDragAndDropFiles}+ >+ {blockingLoad && <TranslucentLoadingOverlay />}+ {!sidebarVisibilityProps.open && subscriptionDialogs}<CollectionSelectoropen={openCollectionSelector}onClose={handleCloseCollectionSelector}@@ -2035,8 +2052,16 @@ const Page: React.FC = () => {onShowPlanSelector={showPlanSelector}onShowCollectionSummary={handleSidebarShowCollectionSummary}onShowExport={showExport}+ onCloseOverlays={closeSidebarOverlays}onAuthenticateUser={authenticateUser}- />+ >+ {sidebarVisibilityProps.open && subscriptionDialogs}+ <Export+ {...exportVisibilityProps}+ {...{ collectionNameByID }}+ onRootClose={handleSidebarClose}+ />+ </Sidebar><WhatsNew {...whatsNewVisibilityProps} /><AssignPersonDialog{...contextMenuAssignPersonProps}@@ -2163,11 +2188,6 @@ const Page: React.FC = () => {onSubmit={handleEditAlbumDetails}/>)}- <Export- {...exportVisibilityProps}- {...{ collectionNameByID }}- onRootClose={handleSidebarClose}- /><AuthenticateUseropen={authenticateUserVisibilityProps.open}onClose={handleCloseAuthenticateUser}diff --git a/web/packages/base/components/mui/SidebarDrawer.tsx b/web/packages/base/components/mui/SidebarDrawer.tsxindex c8aac76803..cc4df03538 100644--- a/web/packages/base/components/mui/SidebarDrawer.tsx+++ b/web/packages/base/components/mui/SidebarDrawer.tsx@@ -11,35 +11,68 @@ import {} from "@mui/material";import { isDesktop } from "ente-base/app";import type { ModalVisibilityProps } from "ente-base/components/utils/modal";-import React from "react";+import React, { useContext } from "react";+import {+ SidebarDrawerDepthContext,+ SidebarPanelContext,+} from "./SidebarDrawerContext";-type SidebarDrawerProps = DrawerProps & { maxWidth?: string };+type SidebarDrawerProps = DrawerProps & {+ maxWidth?: string;+ shellRoot?: boolean;+};export const SidebarDrawer: React.FC<SidebarDrawerProps> = ({slotProps,children,maxWidth = "375px",+ shellRoot = false,...rest-}) => (- <Drawer- {...rest}- slotProps={{- ...(slotProps ?? {}),- paper: {- sx: {- maxWidth,- width: "100%",- scrollbarWidth: "thin",- // Extra specificity overrides inherited padding.- "&&": { padding: 0 },+}) => {+ const container = useContext(SidebarPanelContext);+ const inShell = !!container;+ return (+ <Drawer+ {...rest}+ {...(inShell && {+ variant: shellRoot ? "permanent" : "temporary",+ ...(!shellRoot && {+ container,+ disableEnforceFocus: true,+ disableScrollLock: true,+ }),+ sx: { position: "absolute", inset: 0 },+ })}+ slotProps={{+ ...(slotProps ?? {}),+ ...(inShell && {+ backdrop: {+ sx: {+ position: "absolute",+ backgroundColor: "transparent",+ },+ },+ }),+ paper: {+ sx: {+ maxWidth: inShell ? "none" : maxWidth,+ width: inShell && shellRoot ? "360px" : "100%",+ ...(inShell && {+ position: "absolute",+ boxSizing: "border-box",+ }),+ scrollbarWidth: "thin",+ // Extra specificity overrides inherited padding.+ "&&": { padding: 0 },+ },},- },- }}- >- {isDesktop && <AppTitlebarBackdrop />}- <Box sx={{ p: 1 }}>{children}</Box>- </Drawer>-);+ }}+ >+ {isDesktop && <AppTitlebarBackdrop />}+ <Box sx={{ p: 1 }}>{children}</Box>+ </Drawer>+ );+};// Keep scrolling content behind the desktop titlebar and traffic lights.const AppTitlebarBackdrop = styled("div")(({ theme }) => ({@@ -93,6 +126,7 @@ type SidebarDrawerTitlebarProps = Pick<caption?: string;actionButton?: React.ReactNode;showRootCloseButton?: boolean;+ showBackButton?: boolean;};export const SidebarDrawerTitlebar: React.FC<SidebarDrawerTitlebarProps> = ({@@ -102,17 +136,25 @@ export const SidebarDrawerTitlebar: React.FC<SidebarDrawerTitlebarProps> = ({onRootClose,actionButton,showRootCloseButton = true,+ showBackButton = true,}) => (<Stack sx={{ gap: "4px" }}>- <Stack direction="row" sx={{ justifyContent: "space-between" }}>- <IconButton- aria-label="Back"- onClick={onClose}- color="primary"- sx={{ ml: "0.5rem" }}- >- <ArrowBackIcon />- </IconButton>+ <Stack+ direction="row"+ sx={{+ justifyContent: showBackButton ? "space-between" : "flex-end",+ }}+ >+ {showBackButton && (+ <IconButton+ aria-label="Back"+ onClick={onClose}+ color="primary"+ sx={{ ml: "0.5rem" }}+ >+ <ArrowBackIcon />+ </IconButton>+ )}<Stack direction="row" sx={{ gap: "4px" }}>{actionButton && actionButton}{showRootCloseButton && (@@ -150,11 +192,25 @@ export const TitledNestedSidebarDrawer: React.FC<Pick<SidebarDrawerProps, "anchor" | "maxWidth"> &SidebarDrawerTitlebarProps>-> = ({ open, onClose, onRootClose, anchor, maxWidth, children, ...rest }) => (- <NestedSidebarDrawer {...{ open, onClose, onRootClose, anchor, maxWidth }}>- <Stack sx={{ gap: "4px", py: "12px" }}>- <SidebarDrawerTitlebar {...{ onClose, onRootClose }} {...rest} />- {children}- </Stack>- </NestedSidebarDrawer>-);+> = ({ open, onClose, onRootClose, anchor, maxWidth, children, ...rest }) => {+ const container = useContext(SidebarPanelContext);+ const depth = useContext(SidebarDrawerDepthContext);+ return (+ <NestedSidebarDrawer+ {...{ open, onClose, onRootClose, anchor, maxWidth }}+ >+ <Stack sx={{ gap: "4px", py: "12px" }}>+ <SidebarDrawerTitlebar+ {...{ onClose, onRootClose }}+ {...rest}+ showBackButton={+ rest.showBackButton ?? (!container || depth > 0)+ }+ />+ <SidebarDrawerDepthContext.Provider value={depth + 1}>+ {children}+ </SidebarDrawerDepthContext.Provider>+ </Stack>+ </NestedSidebarDrawer>+ );+};diff --git a/web/packages/base/components/mui/SidebarDrawerContext.ts b/web/packages/base/components/mui/SidebarDrawerContext.tsnew file mode 100644index 0000000000..523255caad--- /dev/null+++ b/web/packages/base/components/mui/SidebarDrawerContext.ts@@ -0,0 +1,7 @@+import { createContext } from "react";++export const SidebarPanelContext = createContext<+ (() => HTMLElement | null) | undefined+>(undefined);++export const SidebarDrawerDepthContext = createContext(0);