π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat(photos):revamp-watched-folders-sidebar
Aswin Asokee56aec45292
diff --git a/web/apps/photos/src/components/sidebar/FreeUpSpace.tsx b/web/apps/photos/src/components/sidebar/FreeUpSpace.tsxindex c987757f83..190eefd1a9 100644--- a/web/apps/photos/src/components/sidebar/FreeUpSpace.tsx+++ b/web/apps/photos/src/components/sidebar/FreeUpSpace.tsx@@ -68,8 +68,6 @@ export const FreeUpSpace: React.FC<FreeUpSpaceProps> = ({onRootClose={handleRootClose}title={t("free_up_space")}caption="Review large files and duplicates to reclaim storage."- contentInset="0.5rem"- titleFontSize="22px"><Stack sx={{ px: 2, py: 1, gap: 1 }}><RowCarddiff --git a/web/apps/photos/src/components/sidebar/Help.tsx b/web/apps/photos/src/components/sidebar/Help.tsxindex 23376dfdb0..beb5d8d771 100644--- a/web/apps/photos/src/components/sidebar/Help.tsx+++ b/web/apps/photos/src/components/sidebar/Help.tsx@@ -115,8 +115,6 @@ export const Help: React.FC<HelpProps> = ({{...{ open, onClose }}onRootClose={handleRootClose}title={t("help")}- contentInset="0.5rem"- titleFontSize="22px"><Stack sx={{ px: 2, py: 1, gap: 1 }}><RowCarddiff --git a/web/apps/photos/src/components/sidebar/Sidebar.tsx b/web/apps/photos/src/components/sidebar/Sidebar.tsxindex e6a5e11dc0..404bca7551 100644--- a/web/apps/photos/src/components/sidebar/Sidebar.tsx+++ b/web/apps/photos/src/components/sidebar/Sidebar.tsx@@ -670,6 +670,7 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({<WatchFolderopen={watchFolderView}onClose={onCloseWatchFolder}+ onRootClose={onCloseSidebar}/>)}<Accountdiff --git a/web/apps/photos/src/components/sidebar/WatchFolder.tsx b/web/apps/photos/src/components/sidebar/WatchFolder.tsxindex 59fc2d725e..2b60cd7eeb 100644--- a/web/apps/photos/src/components/sidebar/WatchFolder.tsx+++ b/web/apps/photos/src/components/sidebar/WatchFolder.tsx@@ -1,33 +1,25 @@import { CollectionMappingChoice } from "@/components/CollectionMappingChoice";import watcher from "@/services/watch";-import AddIcon from "@mui/icons-material/Add";import CheckIcon from "@mui/icons-material/Check";-import DoNotDisturbOutlinedIcon from "@mui/icons-material/DoNotDisturbOutlined";-import FolderCopyOutlinedIcon from "@mui/icons-material/FolderCopyOutlined";-import FolderOpenIcon from "@mui/icons-material/FolderOpen";+import ChevronRightIcon from "@mui/icons-material/ChevronRight";import RefreshIcon from "@mui/icons-material/Refresh";-import WarningAmberIcon from "@mui/icons-material/WarningAmber";+import StopCircleOutlinedIcon from "@mui/icons-material/StopCircleOutlined";import {CircularProgress,- Dialog,- DialogContent,- DialogTitle,+ Divider,+ IconButton,Stack,Tooltip,Typography,+ useTheme,} from "@mui/material";-import { CenteredFill, SpacedRow } from "ente-base/components/containers";-import { DialogCloseIconButton } from "ente-base/components/mui/DialogCloseIconButton";-import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";+import { CenteredFill } from "ente-base/components/containers";import {- OverflowMenu,- OverflowMenuOption,-} from "ente-base/components/OverflowMenu";-import { EllipsizedTypography } from "ente-base/components/Typography";-import {- useModalVisibility,- type ModalVisibilityProps,-} from "ente-base/components/utils/modal";+ TitledNestedSidebarDrawer,+ type NestedSidebarDrawerVisibilityProps,+} from "ente-base/components/mui/SidebarDrawer";+import { useModalVisibility } from "ente-base/components/utils/modal";+import { RowCard } from "ente-base/components/v2/RowCard";import { useBaseContext } from "ente-base/context";import {ensureElectron,@@ -38,10 +30,12 @@ import type { CollectionMapping, FolderWatch } from "ente-base/types/ipc";import { t } from "i18next";import React, { useEffect, useRef, useState } from "react";-export const WatchFolder: React.FC<ModalVisibilityProps> = ({+export const WatchFolder: React.FC<NestedSidebarDrawerVisibilityProps> = ({open,onClose,+ onRootClose,}) => {+ const theme = useTheme();const [watches, setWatches] = useState<FolderWatch[] | undefined>();const [savedFolderPath, setSavedFolderPath] = useState<string | undefined@@ -49,6 +43,11 @@ export const WatchFolder: React.FC<ModalVisibilityProps> = ({const { show: showMappingChoice, props: mappingChoiceVisibilityProps } =useModalVisibility();+ const handleRootClose = () => {+ onClose();+ onRootClose();+ };+const refreshWatches = async () => {const ws = await watcher.getWatches();setWatches(ws);@@ -127,36 +126,62 @@ export const WatchFolder: React.FC<ModalVisibilityProps> = ({return (<>- <Dialog- open={open}- onClose={onClose}- fullWidth- slotProps={{- paper: { sx: { height: "448px", maxWidth: "444px" } },- }}+ <TitledNestedSidebarDrawer+ {...{ open, onClose }}+ onRootClose={handleRootClose}+ title={t("watch_folders")}+ caption="Folders on this computer that are backed up automatically whenever files change.">- <SpacedRow sx={{ p: "16px 8px 0px 8px" }}>- <DialogTitle variant="h3">- {t("watched_folders")}- </DialogTitle>- <DialogCloseIconButton {...{ onClose }} />- </SpacedRow>- <DialogContent sx={{ flex: 1 }}>- <Stack sx={{ gap: 1, p: 1.5, height: "100%" }}>- <WatchList- {...{ watches, removeWatch, refreshWatches }}- />- <FocusVisibleButton- fullWidth- color="accent"- onClick={addNewWatch}- startIcon={<AddIcon />}+ <Stack sx={{ px: 2, py: 1, gap: 1 }}>+ <WatchList {...{ watches, removeWatch, refreshWatches }} />+ <Divider sx={{ opacity: 0.4 }} />+ <button+ type="button"+ onClick={addNewWatch}+ style={{+ display: "flex",+ width: "100%",+ padding: "8px 8px 8px 0.5rem",+ alignItems: "center",+ justifyContent: "space-between",+ border: 0,+ background: "transparent",+ color: "inherit",+ font: "inherit",+ textAlign: "left",+ cursor: "pointer",+ }}+ >+ <span+ style={{ display: "flex", flexDirection: "column" }}>- {t("add_folder")}- </FocusVisibleButton>- </Stack>- </DialogContent>- </Dialog>+ <span+ style={{+ color: theme.vars.palette.accent.main,+ }}+ >+ {t("add_folder")}+ </span>+ <span+ style={{+ fontSize: "14px",+ lineHeight: "20px",+ fontWeight: 400,+ color: theme.vars.palette.text.muted,+ }}+ >+ Choose a folder to watch+ </span>+ </span>+ <span style={{ display: "flex", padding: "8px" }}>+ <ChevronRightIcon+ sx={{ fontSize: "20px", color: "text.muted" }}+ />+ </span>+ </button>+ <Divider sx={{ opacity: 0.4 }} />+ </Stack>+ </TitledNestedSidebarDrawer><CollectionMappingChoice{...mappingChoiceVisibilityProps}onSelect={handleCollectionMappingSelect}@@ -177,7 +202,7 @@ const WatchList: React.FC<WatchListProps> = ({refreshWatches,}) =>watches?.length ? (- <Stack sx={{ gap: 2, flex: 1, overflowY: "auto", pb: 2, pr: 1 }}>+ <Stack sx={{ gap: 1 }}>{watches.map((watch) => (<WatchEntrykey={watch.folderPath}@@ -261,103 +286,56 @@ const WatchEntry: React.FC<WatchEntryProps> = ({retryTimerRef.current = setTimeout(() => setIsRetrying(false), 1000);};+ const count = watch.syncedFiles.length;+ const mapping =+ watch.collectionMapping == "root"+ ? `synced to "${basename(watch.folderPath)}"`+ : "synced to separate albums";+ const subtitle = !isAccessible+ ? t("folder_not_accessible")+ : `${count.toLocaleString()} ${count == 1 ? "file" : "files"} Β· ${watcher.isSyncingFolder(watch.folderPath) ? "Syncing" : mapping}`;+return (- <SpacedRow- sx={{- overflow: "hidden",- flexShrink: 0,- opacity: isAccessible ? 1 : 0.7,- }}- >- <Stack direction="row" sx={{ overflow: "hidden", gap: 1.5 }}>- {isRetrying ? (- <CircularProgress- size={24}- sx={{ color: "stroke.muted" }}- />- ) : !isAccessible ? (- <Tooltip title={t("folder_not_accessible")}>- <WarningAmberIcon color="warning" />- </Tooltip>- ) : watch.collectionMapping == "root" ? (- <Tooltip title={t("uploaded_to_single_collection")}>- <FolderOpenIcon color="secondary" />- </Tooltip>- ) : (- <Tooltip title={t("uploaded_to_separate_collections")}>- <FolderCopyOutlinedIcon color="secondary" />+ <RowCard+ title={`/${watch.folderPath+ .split(/[\\/]/)+ .filter(Boolean)+ .slice(-2)+ .join("/")}`}+ subtitle={subtitle}+ endIcon={+ <Stack+ direction="row"+ sx={{ alignItems: "center", flexShrink: 0 }}+ >+ {!isAccessible && (+ <Tooltip title={t("retry_watching")}>+ <IconButton+ aria-label={`${t("retry_watching")}: ${watch.folderPath}`}+ onClick={handleRetry}+ disabled={isRetrying}+ >+ {isRetrying ? (+ <CircularProgress size={20} />+ ) : (+ <RefreshIcon />+ )}+ </IconButton>+ </Tooltip>+ )}+ <Tooltip title={t("stop_watching")}>+ <IconButton+ aria-label={`${t("stop_watching")}: ${watch.folderPath}`}+ onClick={confirmStopWatching}+ >+ <StopCircleOutlinedIcon />+ </IconButton></Tooltip>- )}- <Stack sx={{ overflow: "hidden" }}>- <EntryHeading watch={watch} />- <FolderPath>{watch.folderPath}</FolderPath></Stack>- </Stack>- <EntryOptions- confirmStopWatching={confirmStopWatching}- isAccessible={isAccessible}- onRetry={handleRetry}- />- </SpacedRow>+ }+ />);};-interface EntryHeadingProps {- watch: FolderWatch;-}--const EntryHeading: React.FC<EntryHeadingProps> = ({- watch: { folderPath },-}) => (- <Stack- direction="row"- sx={{ gap: 1.5, alignItems: "center", justifyContent: "flex-start" }}- >- <Typography>{basename(folderPath)}</Typography>- {watcher.isSyncingFolder(folderPath) && (- <CircularProgress- size={15}- sx={{ flexShrink: 0, color: "stroke.muted" }}- />- )}- </Stack>-);--const FolderPath: React.FC<React.PropsWithChildren> = ({ children }) => (- <EllipsizedTypography variant="small" color="text.muted">- {children}- </EllipsizedTypography>-);--interface EntryOptionsProps {- confirmStopWatching: () => void;- isAccessible: boolean;- onRetry: () => void;-}--const EntryOptions: React.FC<EntryOptionsProps> = ({- confirmStopWatching,- isAccessible,- onRetry,-}) => (- <OverflowMenu- ariaID={"watch-mapping-option"}- menuPaperSxProps={{ backgroundColor: "background.paper2" }}- >- {!isAccessible && (- <OverflowMenuOption onClick={onRetry} startIcon={<RefreshIcon />}>- {t("retry_watching")}- </OverflowMenuOption>- )}- <OverflowMenuOption- color="critical"- onClick={confirmStopWatching}- startIcon={<DoNotDisturbOutlinedIcon />}- >- {t("stop_watching")}- </OverflowMenuOption>- </OverflowMenu>-);-const areAllInSameDirectory = (paths: string[]) =>new Set(paths.map(dirname)).size == 1;diff --git a/web/packages/base/components/mui/SidebarDrawer.tsx b/web/packages/base/components/mui/SidebarDrawer.tsxindex 7506f4662c..5a8c596fde 100644--- a/web/packages/base/components/mui/SidebarDrawer.tsx+++ b/web/packages/base/components/mui/SidebarDrawer.tsx@@ -24,7 +24,7 @@ export const SidebarDrawer: React.FC<DrawerProps> = ({...(slotProps ?? {}),paper: {sx: {- maxWidth: "375px",+ maxWidth: "440px",width: "100%",scrollbarWidth: "thin",// Extra specificity overrides inherited padding.@@ -88,9 +88,6 @@ type SidebarDrawerTitlebarProps = Pick<> & {title: string;caption?: string;- // TODO: Default to the new UI's inset and title size once it is adopted.- contentInset?: string;- titleFontSize?: string;actionButton?: React.ReactNode;showRootCloseButton?: boolean;};@@ -98,8 +95,6 @@ type SidebarDrawerTitlebarProps = Pick<export const SidebarDrawerTitlebar: React.FC<SidebarDrawerTitlebarProps> = ({title,caption,- contentInset,- titleFontSize,onClose,onRootClose,actionButton,@@ -107,11 +102,7 @@ export const SidebarDrawerTitlebar: React.FC<SidebarDrawerTitlebarProps> = ({}) => (<Stack sx={{ gap: "4px" }}><Stack direction="row" sx={{ justifyContent: "space-between" }}>- <IconButton- onClick={onClose}- color="primary"- sx={{ ml: contentInset }}- >+ <IconButton onClick={onClose} color="primary" sx={{ ml: "0.5rem" }}><ArrowBackIcon /></IconButton><Stack direction="row" sx={{ gap: "4px" }}>@@ -123,14 +114,8 @@ export const SidebarDrawerTitlebar: React.FC<SidebarDrawerTitlebarProps> = ({)}</Stack></Stack>- <Stack- sx={{- pl: contentInset ? `calc(16px + ${contentInset})` : "16px",- pr: "16px",- gap: "4px",- }}- >- <Typography variant="h3" sx={{ fontSize: titleFontSize }}>+ <Stack sx={{ pl: "calc(16px + 0.5rem)", pr: "16px", gap: "4px" }}>+ <Typography variant="h3" sx={{ fontSize: "22px" }}>{title}</Typography><Typography@@ -138,7 +123,6 @@ export const SidebarDrawerTitlebar: React.FC<SidebarDrawerTitlebarProps> = ({sx={{color: "text.muted",wordBreak: "break-all",- px: contentInset ? 0 : "1px",minHeight: "17px",}}>diff --git a/web/packages/base/components/v2/RowCard.tsx b/web/packages/base/components/v2/RowCard.tsxindex 0179027ac0..a044b5d638 100644--- a/web/packages/base/components/v2/RowCard.tsx+++ b/web/packages/base/components/v2/RowCard.tsx@@ -1,24 +1,28 @@import ChevronRightIcon from "@mui/icons-material/ChevronRight";-import { Stack, Typography } from "@mui/material";+import { Box, Stack, Typography } from "@mui/material";import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";import React from "react";interface RowCardProps {title: string;subtitle: string;- onClick: () => void;+ onClick?: () => void;+ endIcon?: React.ReactNode;}export const RowCard: React.FC<RowCardProps> = ({title,subtitle,onClick,+ endIcon = <ChevronRightIcon />,}) => (- <FocusVisibleButton- fullWidth+ <Box+ component={onClick ? FocusVisibleButton : "div"}onClick={onClick}sx={[{+ display: "flex",+ width: "100%",p: "14px 8px 14px 0.5rem",gap: 1,justifyContent: "space-between",@@ -52,6 +56,6 @@ export const RowCard: React.FC<RowCardProps> = ({{subtitle}</Typography></Stack>- <ChevronRightIcon />- </FocusVisibleButton>+ {endIcon}+ </Box>);