π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Abstract
Manav Rathie1199222e1a7
diff --git a/web/apps/photos/src/components/Sidebar/index.tsx b/web/apps/photos/src/components/Sidebar/index.tsxindex d819ec8add..9a84b65257 100644--- a/web/apps/photos/src/components/Sidebar/index.tsx+++ b/web/apps/photos/src/components/Sidebar/index.tsx@@ -3,6 +3,7 @@ import { isDesktop } from "@/base/app";import { EnteDrawer } from "@/base/components/EnteDrawer";import { EnteLogo } from "@/base/components/EnteLogo";import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";+import { useModalVisibilityProps } from "@/base/components/utils/modal";import log from "@/base/log";import { savedLogs } from "@/base/log-web";import { customAPIHost } from "@/base/origins";@@ -435,16 +436,13 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {setThemeColor,} = appContext;- const [recoverModalView, setRecoveryModalView] = useState(false);+ const recoveryKeyVisibility = useModalVisibilityProps();const [twoFactorModalView, setTwoFactorModalView] = useState(false);const [preferencesView, setPreferencesView] = useState(false);const openPreferencesOptions = () => setPreferencesView(true);const closePreferencesOptions = () => setPreferencesView(false);- const openRecoveryKeyModal = () => setRecoveryModalView(true);- const closeRecoveryKeyModal = () => setRecoveryModalView(false);-const openTwoFactorModal = () => setTwoFactorModalView(true);const closeTwoFactorModal = () => setTwoFactorModalView(false);@@ -549,10 +547,7 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {onClick={openPreferencesOptions}label={t("preferences")}/>- <RecoveryKey- show={recoverModalView}- onHide={closeRecoveryKeyModal}- />+ <RecoveryKey {...recoveryKeyVisibility} /><TwoFactorModalshow={twoFactorModalView}onHide={closeTwoFactorModal}diff --git a/web/packages/base/components/mui/index.tsx b/web/packages/base/components/utils/modal.tssimilarity index 64%rename from web/packages/base/components/mui/index.tsxrename to web/packages/base/components/utils/modal.tsindex 17b1fab05e..6a7c0a97dc 100644--- a/web/packages/base/components/mui/index.tsx+++ b/web/packages/base/components/utils/modal.ts@@ -1,3 +1,5 @@+import { useCallback, useState } from "react";+/*** Common props that control the display of a modal (e.g. dialog, drawer)* component.@@ -24,3 +26,18 @@ export type NestedDrawerVisibilityProps = ModalVisibilityProps & {*/onRootClose: () => void;};++/**+ * A convenience hook for keeping the state for opening and closing a modal, and+ * exposing a function to close the modal whose identity is stable.+ *+ * These props can be passed verbatim to our components that expect+ * {@link ModalVisibilityProps}.+ */+export const useModalVisibilityProps = () => {+ const [open, setOpen] = useState(false);++ const onClose = useCallback(() => setOpen(false), []);++ return { open, onClose };+};diff --git a/web/packages/new/photos/components/AddPersonDialog.tsx b/web/packages/new/photos/components/AddPersonDialog.tsxindex f1a69d7f71..e283cba337 100644--- a/web/packages/new/photos/components/AddPersonDialog.tsx+++ b/web/packages/new/photos/components/AddPersonDialog.tsx@@ -1,4 +1,4 @@-import type { ModalVisibilityProps } from "@/base/components/mui";+import type { ModalVisibilityProps } from "@/base/components/utils/modal";import { pt } from "@/base/i18n";import { addCGroup, addClusterToCGroup } from "@/new/photos/services/ml";import { ensure } from "@/utils/ensure";diff --git a/web/packages/new/photos/components/CollectionMappingChoiceDialog.tsx b/web/packages/new/photos/components/CollectionMappingChoiceDialog.tsxindex 76fa39de7c..e2fe4e78ac 100644--- a/web/packages/new/photos/components/CollectionMappingChoiceDialog.tsx+++ b/web/packages/new/photos/components/CollectionMappingChoiceDialog.tsx@@ -1,4 +1,4 @@-import type { ModalVisibilityProps } from "@/base/components/mui";+import type { ModalVisibilityProps } from "@/base/components/utils/modal";import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton";import type { CollectionMapping } from "@/base/types/ipc";import FolderIcon from "@mui/icons-material/Folder";diff --git a/web/packages/new/photos/components/CollectionSelector.tsx b/web/packages/new/photos/components/CollectionSelector.tsxindex 4e91a627ea..cb052c7186 100644--- a/web/packages/new/photos/components/CollectionSelector.tsx+++ b/web/packages/new/photos/components/CollectionSelector.tsx@@ -1,4 +1,4 @@-import type { ModalVisibilityProps } from "@/base/components/mui";+import type { ModalVisibilityProps } from "@/base/components/utils/modal";import type { Collection } from "@/media/collection";import {ItemCard,diff --git a/web/packages/new/photos/components/MLSettings.tsx b/web/packages/new/photos/components/MLSettings.tsxindex 15480eddf4..2401899824 100644--- a/web/packages/new/photos/components/MLSettings.tsx+++ b/web/packages/new/photos/components/MLSettings.tsx@@ -1,8 +1,8 @@import { EnteDrawer } from "@/base/components/EnteDrawer";import { MenuItemGroup } from "@/base/components/Menu";-import type { NestedDrawerVisibilityProps } from "@/base/components/mui";import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";import { Titlebar } from "@/base/components/Titlebar";+import type { NestedDrawerVisibilityProps } from "@/base/components/utils/modal";import {disableML,enableML,diff --git a/web/packages/new/photos/components/NameInputDialog.tsx b/web/packages/new/photos/components/NameInputDialog.tsxindex 69912c1add..3e8790738b 100644--- a/web/packages/new/photos/components/NameInputDialog.tsx+++ b/web/packages/new/photos/components/NameInputDialog.tsx@@ -1,4 +1,4 @@-import type { ModalVisibilityProps } from "@/base/components/mui";+import type { ModalVisibilityProps } from "@/base/components/utils/modal";import log from "@/base/log";import SingleInputForm, {type SingleInputFormProps,diff --git a/web/packages/new/photos/components/RecoveryKey.tsx b/web/packages/new/photos/components/RecoveryKey.tsxindex f4a78cf4f2..873ac8a58b 100644--- a/web/packages/new/photos/components/RecoveryKey.tsx+++ b/web/packages/new/photos/components/RecoveryKey.tsx@@ -1,9 +1,11 @@+/* eslint-disable react/prop-types *//* eslint-disable @typescript-eslint/no-floating-promises *//* eslint-disable react-hooks/exhaustive-deps *//* eslint-disable @typescript-eslint/no-unsafe-return *//* eslint-disable @typescript-eslint/no-unsafe-assignment *//* eslint-disable @typescript-eslint/no-unsafe-call */import { errorDialogAttributes } from "@/base/components/utils/mini-dialog";+import type { ModalVisibilityProps } from "@/base/components/utils/modal";import { useIsMobileWidth } from "@/base/hooks";import log from "@/base/log";import { useAppContext } from "@/new/photos/types/context";@@ -30,12 +32,10 @@ bip39.setDefaultWordlist("english");const RECOVERY_KEY_FILE_NAME = "ente-recovery-key.txt";-interface Props {- show: boolean;- onHide: () => void;-}--export function RecoveryKey({ ...props }: Props) {+export const RecoveryKey: React.FC<ModalVisibilityProps> = ({+ open,+ onClose,+}) => {const { showMiniDialog } = useAppContext();const [recoveryKey, setRecoveryKey] = useState<string | null>(null);@@ -47,7 +47,7 @@ export function RecoveryKey({ ...props }: Props) {);useEffect(() => {- if (!props.show) {+ if (!open) {return;}const main = async () => {@@ -56,22 +56,22 @@ export function RecoveryKey({ ...props }: Props) {} catch (e) {log.error("Failed to generate recovery key", e);somethingWentWrong();- props.onHide();+ onClose();}};main();- }, [props.show]);+ }, [open]);function onSaveClick() {downloadAsFile(RECOVERY_KEY_FILE_NAME, ensure(recoveryKey));- props.onHide();+ onClose();}return (<DialogfullScreen={fullScreen}- open={props.show}- onClose={props.onHide}+ open={open}+ onClose={onClose}// [Note: maxWidth "xs" on MUI dialogs]//// While logically the "xs" breakpoint doesn't make sense as a@@ -81,7 +81,7 @@ export function RecoveryKey({ ...props }: Props) {maxWidth="xs"fullWidth>- <DialogTitleWithCloseButton onClose={props.onHide}>+ <DialogTitleWithCloseButton onClose={onClose}>{t("recovery_key")}</DialogTitleWithCloseButton><DialogContent>@@ -94,7 +94,7 @@ export function RecoveryKey({ ...props }: Props) {</DashedBorderWrapper></DialogContent><DialogActions>- <Button color="secondary" size="large" onClick={props.onHide}>+ <Button color="secondary" size="large" onClick={onClose}>{t("do_this_later")}</Button><Button color="accent" size="large" onClick={onSaveClick}>@@ -103,7 +103,7 @@ export function RecoveryKey({ ...props }: Props) {</DialogActions></Dialog>);-}+};const DashedBorderWrapper = styled(Box)(({ theme }) => ({border: `1px dashed ${theme.palette.grey.A400}`,diff --git a/web/packages/new/photos/components/SingleInputForm.tsx b/web/packages/new/photos/components/SingleInputForm.tsxindex 9816215d2c..78ea8193eb 100644--- a/web/packages/new/photos/components/SingleInputForm.tsx+++ b/web/packages/new/photos/components/SingleInputForm.tsx@@ -1,4 +1,4 @@-import type { ModalVisibilityProps } from "@/base/components/mui";+import type { ModalVisibilityProps } from "@/base/components/utils/modal";import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton";import { LoadingButton } from "@/base/components/mui/LoadingButton";import log from "@/base/log";diff --git a/web/packages/new/photos/components/mui/Dialog.tsx b/web/packages/new/photos/components/mui/Dialog.tsxindex 5a4fa48fa6..0e56df6a97 100644--- a/web/packages/new/photos/components/mui/Dialog.tsx+++ b/web/packages/new/photos/components/mui/Dialog.tsx@@ -1,4 +1,4 @@-import type { ModalVisibilityProps } from "@/base/components/mui";+import type { ModalVisibilityProps } from "@/base/components/utils/modal";import CloseIcon from "@mui/icons-material/Close";import { IconButton } from "@mui/material";import { t } from "i18next";