💚 End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Inline
Manav Rathia1b63b8ea4d1
diff --git a/web/apps/photos/src/components/Sidebar/index.tsx b/web/apps/photos/src/components/Sidebar.tsxsimilarity index 68%rename from web/apps/photos/src/components/Sidebar/index.tsxrename to web/apps/photos/src/components/Sidebar.tsxindex d9109dfe16..b39d594972 100644--- a/web/apps/photos/src/components/Sidebar/index.tsx+++ b/web/apps/photos/src/components/Sidebar.tsx@@ -84,42 +84,72 @@ import React, {import { Trans } from "react-i18next";import { getUncategorizedCollection } from "services/collectionService";import exportService from "services/export";-import { testUpload } from "../../../tests/upload.test";-import { Preferences } from "./Preferences";+import { testUpload } from "../../tests/upload.test";import { SubscriptionCard } from "./SubscriptionCard";-interface Iprops {+import {+ RowButtonGroup,+ RowButtonGroupHint,+ RowSwitch,+} from "@/base/components/RowButton";+import {+ NestedSidebarDrawer,+ SidebarDrawerTitlebar,+ type NestedSidebarDrawerVisibilityProps,+} from "@/base/components/mui/SidebarDrawer";+import {+ getLocaleInUse,+ setLocaleInUse,+ supportedLocales,+ type SupportedLocale,+} from "@/base/i18n";+import { DropdownInput } from "@/new/photos/components/DropdownInput";+import { MLSettings } from "@/new/photos/components/sidebar/MLSettings";+import {+ confirmDisableMapsDialogAttributes,+ confirmEnableMapsDialogAttributes,+} from "@/new/photos/components/utils/dialog";+import { useSettingsSnapshot } from "@/new/photos/components/utils/use-snapshot";+import { isMLSupported } from "@/new/photos/services/ml";+import {+ syncSettings,+ updateCFProxyDisabledPreference,+ updateMapEnabled,+} from "@/new/photos/services/settings";+import ChevronRightIcon from "@mui/icons-material/ChevronRight";+import { useColorScheme } from "@mui/material";+import { useCallback } from "react";++interface SidebarProps {collectionSummaries: CollectionSummaries;sidebarView: boolean;closeSidebar: () => void;}-export default function Sidebar({+export const Sidebar: React.FC<SidebarProps> = ({collectionSummaries,sidebarView,closeSidebar,-}: Iprops) {- return (- <RootSidebarDrawer open={sidebarView} onClose={closeSidebar}>- <HeaderSection closeSidebar={closeSidebar} />+}) => (+ <RootSidebarDrawer open={sidebarView} onClose={closeSidebar}>+ <HeaderSection closeSidebar={closeSidebar} />+ <Divider />+ <UserDetailsSection sidebarView={sidebarView} />+ <Stack sx={{ gap: 0.5, mb: 3 }}>+ <ShortcutSection+ closeSidebar={closeSidebar}+ collectionSummaries={collectionSummaries}+ />+ <UtilitySection closeSidebar={closeSidebar} /><Divider />- <UserDetailsSection sidebarView={sidebarView} />- <Stack sx={{ gap: 0.5, mb: 3 }}>- <ShortcutSection- closeSidebar={closeSidebar}- collectionSummaries={collectionSummaries}- />- <UtilitySection closeSidebar={closeSidebar} />- <Divider />- <HelpSection />- <Divider />- <ExitSection />- <Divider />- <DebugSection />- </Stack>- </RootSidebarDrawer>- );-}+ <HelpSection />+ <Divider />+ <ExitSection />+ <Divider />+ <DebugSection />+ </Stack>+ </RootSidebarDrawer>+);const RootSidebarDrawer = styled(SidebarDrawer)(({ theme }) => ({"& .MuiPaper-root": {@@ -713,3 +743,270 @@ const DebugSection: React.FC = () => {</>);};++const Preferences: React.FC<NestedSidebarDrawerVisibilityProps> = ({+ open,+ onClose,+ onRootClose,+}) => {+ const { show: showMapSettings, props: mapSettingsVisibilityProps } =+ useModalVisibility();+ const {+ show: showAdvancedSettings,+ props: advancedSettingsVisibilityProps,+ } = useModalVisibility();+ const { show: showMLSettings, props: mlSettingsVisibilityProps } =+ useModalVisibility();++ useEffect(() => {+ if (open) void syncSettings();+ }, [open]);++ const handleRootClose = () => {+ onClose();+ onRootClose();+ };++ return (+ <NestedSidebarDrawer {...{ open, onClose }} onRootClose={onRootClose}>+ <Stack sx={{ gap: "4px", py: "12px" }}>+ <SidebarDrawerTitlebar+ onClose={onClose}+ title={t("preferences")}+ onRootClose={handleRootClose}+ />+ <Stack sx={{ px: "16px", py: "8px", gap: "24px" }}>+ <LanguageSelector />+ <ThemeSelector />+ <Divider sx={{ my: "2px", opacity: 0.1 }} />+ {isMLSupported && (+ <RowButtonGroup>+ <RowButton+ endIcon={<ChevronRightIcon />}+ label={t("ml_search")}+ onClick={showMLSettings}+ />+ </RowButtonGroup>+ )}+ <RowButton+ endIcon={<ChevronRightIcon />}+ label={t("map")}+ onClick={showMapSettings}+ />+ <RowButton+ endIcon={<ChevronRightIcon />}+ label={t("advanced")}+ onClick={showAdvancedSettings}+ />+ </Stack>+ </Stack>+ <MapSettings+ {...mapSettingsVisibilityProps}+ onRootClose={onRootClose}+ />+ <AdvancedSettings+ {...advancedSettingsVisibilityProps}+ onRootClose={onRootClose}+ />+ <MLSettings+ {...mlSettingsVisibilityProps}+ onRootClose={handleRootClose}+ />+ </NestedSidebarDrawer>+ );+};++const LanguageSelector = () => {+ const locale = getLocaleInUse();++ const updateCurrentLocale = (newLocale: SupportedLocale) => {+ setLocaleInUse(newLocale);+ // [Note: Changing locale causes a full reload]+ //+ // A full reload is needed because we use the global `t` instance+ // instead of the useTranslation hook.+ //+ // We also rely on this behaviour by caching various formatters in+ // module static variables that not get updated if the i18n.language+ // changes unless there is a full reload.+ window.location.reload();+ };++ const options = supportedLocales.map((locale) => ({+ label: localeName(locale),+ value: locale,+ }));++ return (+ <Stack sx={{ gap: 1 }}>+ <Typography variant="small" sx={{ px: 1, color: "text.muted" }}>+ {t("language")}+ </Typography>+ <DropdownInput+ options={options}+ selected={locale}+ onSelect={updateCurrentLocale}+ />+ </Stack>+ );+};++/**+ * Human readable name for each supported locale.+ */+const localeName = (locale: SupportedLocale) => {+ switch (locale) {+ case "en-US":+ return "English";+ case "fr-FR":+ return "Français";+ case "de-DE":+ return "Deutsch";+ case "zh-CN":+ return "中文";+ case "nl-NL":+ return "Nederlands";+ case "es-ES":+ return "Español";+ case "pt-PT":+ return "Português";+ case "pt-BR":+ return "Português Brasileiro";+ case "ru-RU":+ return "Русский";+ case "pl-PL":+ return "Polski";+ case "it-IT":+ return "Italiano";+ case "lt-LT":+ return "Lietuvių kalba";+ case "uk-UA":+ return "Українська";+ case "vi-VN":+ return "Tiếng Việt";+ }+};++const ThemeSelector = () => {+ const { mode, setMode } = useColorScheme();++ // During SSR, mode is always undefined.+ if (!mode) return null;++ return (+ <Stack sx={{ gap: 1 }}>+ <Typography variant="small" sx={{ px: 1, color: "text.muted" }}>+ {t("theme")}+ </Typography>+ <DropdownInput+ options={[+ { label: t("system"), value: "system" },+ { label: t("light"), value: "light" },+ { label: t("dark"), value: "dark" },+ ]}+ selected={mode}+ onSelect={setMode}+ />+ </Stack>+ );+};++const MapSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({+ open,+ onClose,+ onRootClose,+}) => {+ const { showMiniDialog } = useAppContext();++ const { mapEnabled } = useSettingsSnapshot();++ const confirmToggle = useCallback(+ () =>+ showMiniDialog(+ mapEnabled+ ? confirmDisableMapsDialogAttributes(() =>+ updateMapEnabled(false),+ )+ : confirmEnableMapsDialogAttributes(() =>+ updateMapEnabled(true),+ ),+ ),+ [showMiniDialog, mapEnabled],+ );++ const handleRootClose = () => {+ onClose();+ onRootClose();+ };++ return (+ <NestedSidebarDrawer+ {...{ open, onClose }}+ onRootClose={handleRootClose}+ >+ <Stack sx={{ gap: "4px", py: "12px" }}>+ <SidebarDrawerTitlebar+ onClose={onClose}+ onRootClose={handleRootClose}+ title={t("map")}+ />++ <Stack sx={{ px: "16px", py: "20px" }}>+ <RowButtonGroup>+ <RowSwitch+ label={t("enabled")}+ checked={mapEnabled}+ onClick={confirmToggle}+ />+ </RowButtonGroup>+ </Stack>+ </Stack>+ </NestedSidebarDrawer>+ );+};++const AdvancedSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({+ open,+ onClose,+ onRootClose,+}) => {+ const { cfUploadProxyDisabled } = useSettingsSnapshot();++ const handleRootClose = () => {+ onClose();+ onRootClose();+ };++ const toggle = () =>+ void updateCFProxyDisabledPreference(!cfUploadProxyDisabled);++ return (+ <NestedSidebarDrawer+ {...{ open, onClose }}+ onRootClose={handleRootClose}+ >+ <Stack sx={{ gap: "4px", py: "12px" }}>+ <SidebarDrawerTitlebar+ onClose={onClose}+ onRootClose={handleRootClose}+ title={t("advanced")}+ />++ <Stack sx={{ px: "16px", py: "20px" }}>+ <Stack sx={{ gap: "4px" }}>+ <RowButtonGroup>+ <RowSwitch+ label={t("faster_upload")}+ checked={!cfUploadProxyDisabled}+ onClick={toggle}+ />+ </RowButtonGroup>+ <RowButtonGroupHint>+ {t("faster_upload_description")}+ </RowButtonGroupHint>+ </Stack>+ </Stack>+ </Stack>+ </NestedSidebarDrawer>+ );+};diff --git a/web/apps/photos/src/components/Sidebar/Preferences.tsx b/web/apps/photos/src/components/Sidebar/Preferences.tsxdeleted file mode 100644index 282a4aa873..0000000000--- a/web/apps/photos/src/components/Sidebar/Preferences.tsx+++ /dev/null@@ -1,303 +0,0 @@-import {- RowButton,- RowButtonGroup,- RowButtonGroupHint,- RowSwitch,-} from "@/base/components/RowButton";-import {- NestedSidebarDrawer,- SidebarDrawerTitlebar,- type NestedSidebarDrawerVisibilityProps,-} from "@/base/components/mui/SidebarDrawer";-import { useModalVisibility } from "@/base/components/utils/modal";-import {- getLocaleInUse,- setLocaleInUse,- supportedLocales,- type SupportedLocale,-} from "@/base/i18n";-import { DropdownInput } from "@/new/photos/components/DropdownInput";-import { MLSettings } from "@/new/photos/components/sidebar/MLSettings";-import {- confirmDisableMapsDialogAttributes,- confirmEnableMapsDialogAttributes,-} from "@/new/photos/components/utils/dialog";-import { useSettingsSnapshot } from "@/new/photos/components/utils/use-snapshot";-import { isMLSupported } from "@/new/photos/services/ml";-import {- syncSettings,- updateCFProxyDisabledPreference,- updateMapEnabled,-} from "@/new/photos/services/settings";-import { useAppContext } from "@/new/photos/types/context";-import ChevronRightIcon from "@mui/icons-material/ChevronRight";-import { Divider, Stack, Typography, useColorScheme } from "@mui/material";-import { t } from "i18next";-import React, { useCallback, useEffect } from "react";--export const Preferences: React.FC<NestedSidebarDrawerVisibilityProps> = ({- open,- onClose,- onRootClose,-}) => {- const { show: showMapSettings, props: mapSettingsVisibilityProps } =- useModalVisibility();- const {- show: showAdvancedSettings,- props: advancedSettingsVisibilityProps,- } = useModalVisibility();- const { show: showMLSettings, props: mlSettingsVisibilityProps } =- useModalVisibility();-- useEffect(() => {- if (open) void syncSettings();- }, [open]);-- const handleRootClose = () => {- onClose();- onRootClose();- };-- return (- <NestedSidebarDrawer {...{ open, onClose }} onRootClose={onRootClose}>- <Stack sx={{ gap: "4px", py: "12px" }}>- <SidebarDrawerTitlebar- onClose={onClose}- title={t("preferences")}- onRootClose={handleRootClose}- />- <Stack sx={{ px: "16px", py: "8px", gap: "24px" }}>- <LanguageSelector />- <ThemeSelector />- <Divider sx={{ my: "2px", opacity: 0.1 }} />- {isMLSupported && (- <RowButtonGroup>- <RowButton- endIcon={<ChevronRightIcon />}- label={t("ml_search")}- onClick={showMLSettings}- />- </RowButtonGroup>- )}- <RowButton- endIcon={<ChevronRightIcon />}- label={t("map")}- onClick={showMapSettings}- />- <RowButton- endIcon={<ChevronRightIcon />}- label={t("advanced")}- onClick={showAdvancedSettings}- />- </Stack>- </Stack>- <MapSettings- {...mapSettingsVisibilityProps}- onRootClose={onRootClose}- />- <AdvancedSettings- {...advancedSettingsVisibilityProps}- onRootClose={onRootClose}- />- <MLSettings- {...mlSettingsVisibilityProps}- onRootClose={handleRootClose}- />- </NestedSidebarDrawer>- );-};--const LanguageSelector = () => {- const locale = getLocaleInUse();-- const updateCurrentLocale = (newLocale: SupportedLocale) => {- setLocaleInUse(newLocale);- // [Note: Changing locale causes a full reload]- //- // A full reload is needed because we use the global `t` instance- // instead of the useTranslation hook.- //- // We also rely on this behaviour by caching various formatters in- // module static variables that not get updated if the i18n.language- // changes unless there is a full reload.- window.location.reload();- };-- const options = supportedLocales.map((locale) => ({- label: localeName(locale),- value: locale,- }));-- return (- <Stack sx={{ gap: 1 }}>- <Typography variant="small" sx={{ px: 1, color: "text.muted" }}>- {t("language")}- </Typography>- <DropdownInput- options={options}- selected={locale}- onSelect={updateCurrentLocale}- />- </Stack>- );-};--/**- * Human readable name for each supported locale.- */-const localeName = (locale: SupportedLocale) => {- switch (locale) {- case "en-US":- return "English";- case "fr-FR":- return "Français";- case "de-DE":- return "Deutsch";- case "zh-CN":- return "中文";- case "nl-NL":- return "Nederlands";- case "es-ES":- return "Español";- case "pt-PT":- return "Português";- case "pt-BR":- return "Português Brasileiro";- case "ru-RU":- return "Русский";- case "pl-PL":- return "Polski";- case "it-IT":- return "Italiano";- case "lt-LT":- return "Lietuvių kalba";- case "uk-UA":- return "Українська";- case "vi-VN":- return "Tiếng Việt";- }-};--const ThemeSelector = () => {- const { mode, setMode } = useColorScheme();-- // During SSR, mode is always undefined.- if (!mode) return null;-- return (- <Stack sx={{ gap: 1 }}>- <Typography variant="small" sx={{ px: 1, color: "text.muted" }}>- {t("theme")}- </Typography>- <DropdownInput- options={[- { label: t("system"), value: "system" },- { label: t("light"), value: "light" },- { label: t("dark"), value: "dark" },- ]}- selected={mode}- onSelect={setMode}- />- </Stack>- );-};--export const MapSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({- open,- onClose,- onRootClose,-}) => {- const { showMiniDialog } = useAppContext();-- const { mapEnabled } = useSettingsSnapshot();-- const confirmToggle = useCallback(- () =>- showMiniDialog(- mapEnabled- ? confirmDisableMapsDialogAttributes(() =>- updateMapEnabled(false),- )- : confirmEnableMapsDialogAttributes(() =>- updateMapEnabled(true),- ),- ),- [showMiniDialog, mapEnabled],- );-- const handleRootClose = () => {- onClose();- onRootClose();- };-- return (- <NestedSidebarDrawer- {...{ open, onClose }}- onRootClose={handleRootClose}- >- <Stack sx={{ gap: "4px", py: "12px" }}>- <SidebarDrawerTitlebar- onClose={onClose}- onRootClose={handleRootClose}- title={t("map")}- />-- <Stack sx={{ px: "16px", py: "20px" }}>- <RowButtonGroup>- <RowSwitch- label={t("enabled")}- checked={mapEnabled}- onClick={confirmToggle}- />- </RowButtonGroup>- </Stack>- </Stack>- </NestedSidebarDrawer>- );-};--export const AdvancedSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({- open,- onClose,- onRootClose,-}) => {- const { cfUploadProxyDisabled } = useSettingsSnapshot();-- const handleRootClose = () => {- onClose();- onRootClose();- };-- const toggle = () =>- void updateCFProxyDisabledPreference(!cfUploadProxyDisabled);-- return (- <NestedSidebarDrawer- {...{ open, onClose }}- onRootClose={handleRootClose}- >- <Stack sx={{ gap: "4px", py: "12px" }}>- <SidebarDrawerTitlebar- onClose={onClose}- onRootClose={handleRootClose}- title={t("advanced")}- />-- <Stack sx={{ px: "16px", py: "20px" }}>- <Stack sx={{ gap: "4px" }}>- <RowButtonGroup>- <RowSwitch- label={t("faster_upload")}- checked={!cfUploadProxyDisabled}- onClick={toggle}- />- </RowButtonGroup>- <RowButtonGroupHint>- {t("faster_upload_description")}- </RowButtonGroupHint>- </Stack>- </Stack>- </Stack>- </NestedSidebarDrawer>- );-};diff --git a/web/apps/photos/src/components/Sidebar/SubscriptionCard.tsx b/web/apps/photos/src/components/SubscriptionCard.tsxsimilarity index 100%rename from web/apps/photos/src/components/Sidebar/SubscriptionCard.tsxrename to web/apps/photos/src/components/SubscriptionCard.tsxdiff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex d699bdeeae..672115e525 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -102,7 +102,7 @@ import { FixCreationTime } from "components/FixCreationTime";import GalleryEmptyState from "components/GalleryEmptyState";import PhotoFrame from "components/PhotoFrame";import { ITEM_TYPE, TimeStampListItem } from "components/PhotoList";-import Sidebar from "components/Sidebar";+import {Sidebar} from "components/Sidebar";import { type UploadTypeSelectorIntent } from "components/Upload/UploadTypeSelector";import Uploader from "components/Upload/Uploader";import { UploadSelectorInputs } from "components/UploadSelectorInputs";