π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Move
Manav Rathi832a8c77c979
diff --git a/web/apps/accounts/src/pages/_app.tsx b/web/apps/accounts/src/pages/_app.tsxindex 2451b12329..e23692b86e 100644--- a/web/apps/accounts/src/pages/_app.tsx+++ b/web/apps/accounts/src/pages/_app.tsx@@ -1,13 +1,15 @@import { staticAppTitle } from "@/base/app";import { CustomHead } from "@/base/components/Head";+import {+ type MiniDialogAttributes,+ MiniDialog,+} from "@/base/components/MiniDialog";import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";import { AppNavbar } from "@/base/components/Navbar";import { setupI18n } from "@/base/i18n";import { disableDiskLogs } from "@/base/log";import { logUnhandledErrorsAndRejections } from "@/base/log-web";import { Overlay } from "@ente/shared/components/Container";-import type { DialogBoxAttributesV2 } from "@ente/shared/components/DialogBoxV2";-import DialogBoxV2 from "@ente/shared/components/DialogBoxV2";import { getTheme } from "@ente/shared/themes";import { THEME_COLOR } from "@ente/shared/themes/constants";import { CssBaseline } from "@mui/material";@@ -23,7 +25,7 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {const [isI18nReady, setIsI18nReady] = useState<boolean>(false);const [showNavbar, setShowNavbar] = useState(false);const [dialogBoxAttributeV2, setDialogBoxAttributesV2] = useState<- DialogBoxAttributesV2 | undefined+ MiniDialogAttributes | undefined>();const [dialogBoxV2View, setDialogBoxV2View] = useState(false);@@ -53,7 +55,7 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {<ThemeProvider theme={getTheme(THEME_COLOR.DARK, "photos")}><CssBaseline enableColorScheme />- <DialogBoxV2+ <MiniDialogsx={{ zIndex: 1600 }}open={dialogBoxV2View}onClose={closeDialogBoxV2}diff --git a/web/apps/accounts/src/types/context.ts b/web/apps/accounts/src/types/context.tsindex a6410ee57d..e095490524 100644--- a/web/apps/accounts/src/types/context.ts+++ b/web/apps/accounts/src/types/context.ts@@ -1,5 +1,5 @@+import type { MiniDialogAttributes } from "@/base/components/MiniDialog";import { ensure } from "@/utils/ensure";-import type { DialogBoxAttributesV2 } from "@ente/shared/components/DialogBoxV2";import { createContext, useContext } from "react";/**@@ -8,7 +8,7 @@ import { createContext, useContext } from "react";interface AppContextT {/** Show or hide the app's navigation bar. */showNavBar: (show: boolean) => void;- setDialogBoxAttributesV2: (attrs: DialogBoxAttributesV2) => void;+ setDialogBoxAttributesV2: (attrs: MiniDialogAttributes) => void;}/**diff --git a/web/apps/auth/src/pages/_app.tsx b/web/apps/auth/src/pages/_app.tsxindex dd8ad5f2f1..fc7ec04577 100644--- a/web/apps/auth/src/pages/_app.tsx+++ b/web/apps/auth/src/pages/_app.tsx@@ -2,6 +2,10 @@ import { accountLogout } from "@/accounts/services/logout";import type { AccountsContextT } from "@/accounts/types/context";import { clientPackageName, staticAppTitle } from "@/base/app";import { CustomHead } from "@/base/components/Head";+import {+ type MiniDialogAttributes,+ MiniDialog,+} from "@/base/components/MiniDialog";import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";import { AppNavbar } from "@/base/components/Navbar";import { setupI18n } from "@/base/i18n";@@ -11,8 +15,6 @@ import {} from "@/base/log-web";import { ensure } from "@/utils/ensure";import { Overlay } from "@ente/shared/components/Container";-import type { DialogBoxAttributesV2 } from "@ente/shared/components/DialogBoxV2";-import DialogBoxV2 from "@ente/shared/components/DialogBoxV2";import { MessageContainer } from "@ente/shared/components/MessageContainer";import { useLocalState } from "@ente/shared/hooks/useLocalState";import HTTPService from "@ente/shared/network/HTTPService";@@ -67,7 +69,7 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {const isLoadingBarRunning = useRef<boolean>(false);const loadingBar = useRef<LoadingBarRef>(null);const [dialogBoxAttributeV2, setDialogBoxAttributesV2] = useState<- DialogBoxAttributesV2 | undefined+ MiniDialogAttributes | undefined>();const [dialogBoxV2View, setDialogBoxV2View] = useState(false);const [themeColor, setThemeColor] = useLocalState(@@ -165,7 +167,7 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {<LoadingBar color="#51cd7c" ref={loadingBar} />- <DialogBoxV2+ <MiniDialogsx={{ zIndex: 1600 }}open={dialogBoxV2View}onClose={closeDialogBoxV2}diff --git a/web/apps/photos/src/components/AuthenticateUserModal.tsx b/web/apps/photos/src/components/AuthenticateUserModal.tsxindex c4de939371..e8d3c76626 100644--- a/web/apps/photos/src/components/AuthenticateUserModal.tsx+++ b/web/apps/photos/src/components/AuthenticateUserModal.tsx@@ -1,8 +1,10 @@import { checkSessionValidity } from "@/accounts/services/session";+import {+ DialogBoxV2,+ type MiniDialogAttributes,+} from "@/base/components/MiniDialog";import log from "@/base/log";import { AppContext } from "@/new/photos/types/context";-import type { DialogBoxAttributesV2 } from "@ente/shared/components/DialogBoxV2";-import DialogBoxV2 from "@ente/shared/components/DialogBoxV2";import VerifyMasterPasswordForm, {type VerifyMasterPasswordFormProps,} from "@ente/shared/components/VerifyMasterPasswordForm";@@ -124,7 +126,7 @@ export default function AuthenticateUserModal({*/const passwordChangedElsewhereDialogAttributes = (onLogin: () => void,-): DialogBoxAttributesV2 => ({+): MiniDialogAttributes => ({title: t("password_changed_elsewhere"),content: t("password_changed_elsewhere_message"),proceed: {diff --git a/web/apps/photos/src/components/Collections/AlbumCastDialog.tsx b/web/apps/photos/src/components/Collections/AlbumCastDialog.tsxindex 18253c351d..109620b880 100644--- a/web/apps/photos/src/components/Collections/AlbumCastDialog.tsx+++ b/web/apps/photos/src/components/Collections/AlbumCastDialog.tsx@@ -1,9 +1,9 @@+import { DialogBoxV2 } from "@/base/components/MiniDialog";import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";import { boxSeal } from "@/base/crypto/libsodium";import log from "@/base/log";import type { Collection } from "@/media/collection";import { loadCast } from "@/new/photos/utils/chromecast-sender";-import DialogBoxV2 from "@ente/shared/components/DialogBoxV2";import SingleInputForm, {type SingleInputFormProps,} from "@ente/shared/components/SingleInputForm";diff --git a/web/apps/photos/src/components/Collections/CollectionNamer.tsx b/web/apps/photos/src/components/Collections/CollectionNamer.tsxindex 05ea5140a8..7294b44ed6 100644--- a/web/apps/photos/src/components/Collections/CollectionNamer.tsx+++ b/web/apps/photos/src/components/Collections/CollectionNamer.tsx@@ -1,4 +1,4 @@-import DialogBoxV2 from "@ente/shared/components/DialogBoxV2";+import { DialogBoxV2 } from "@/base/components/MiniDialog";import SingleInputForm, {type SingleInputFormProps,} from "@ente/shared/components/SingleInputForm";diff --git a/web/apps/photos/src/components/DeleteAccountModal.tsx b/web/apps/photos/src/components/DeleteAccountModal.tsxindex 3b3ec7b513..e30180e8d6 100644--- a/web/apps/photos/src/components/DeleteAccountModal.tsx+++ b/web/apps/photos/src/components/DeleteAccountModal.tsx@@ -1,9 +1,9 @@+import { DialogBoxV2 } from "@/base/components/MiniDialog";import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton";import { LoadingButton } from "@/base/components/mui/LoadingButton";import log from "@/base/log";import { AppContext } from "@/new/photos/types/context";import { initiateEmail } from "@/new/photos/utils/web";-import DialogBoxV2 from "@ente/shared/components/DialogBoxV2";import { Link, Stack, useMediaQuery } from "@mui/material";import { Formik, type FormikHelpers } from "formik";import { t } from "i18next";diff --git a/web/apps/photos/src/components/ExportPendingList.tsx b/web/apps/photos/src/components/ExportPendingList.tsxindex 51b8ac87e9..2f8888b734 100644--- a/web/apps/photos/src/components/ExportPendingList.tsx+++ b/web/apps/photos/src/components/ExportPendingList.tsx@@ -1,7 +1,7 @@+import { DialogBoxV2 } from "@/base/components/MiniDialog";import { ItemCard, PreviewItemTile } from "@/new/photos/components/Tiles";import { EnteFile } from "@/new/photos/types/file";import { FlexWrapper } from "@ente/shared/components/Container";-import DialogBoxV2 from "@ente/shared/components/DialogBoxV2";import { Box, styled } from "@mui/material";import ItemList from "components/ItemList";import { t } from "i18next";diff --git a/web/apps/photos/src/components/PhotoViewer/FileInfo/FileNameEditDialog.tsx b/web/apps/photos/src/components/PhotoViewer/FileInfo/FileNameEditDialog.tsxindex d6c11fbf6b..b69570c4d3 100644--- a/web/apps/photos/src/components/PhotoViewer/FileInfo/FileNameEditDialog.tsx+++ b/web/apps/photos/src/components/PhotoViewer/FileInfo/FileNameEditDialog.tsx@@ -1,4 +1,4 @@-import DialogBoxV2 from "@ente/shared/components/DialogBoxV2";+import { DialogBoxV2 } from "@/base/components/MiniDialog";import SingleInputForm, {type SingleInputFormProps,} from "@ente/shared/components/SingleInputForm";diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsxindex 3bdeb3ddd9..a0f1ca1536 100644--- a/web/apps/photos/src/pages/_app.tsx+++ b/web/apps/photos/src/pages/_app.tsx@@ -1,5 +1,7 @@import { clientPackageName, staticAppTitle } from "@/base/app";import { CustomHead } from "@/base/components/Head";+import type { MiniDialogAttributes } from "@/base/components/MiniDialog";+import { DialogBoxV2 } from "@/base/components/MiniDialog";import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";import { AppNavbar } from "@/base/components/Navbar";import { setupI18n } from "@/base/i18n";@@ -16,8 +18,6 @@ import { AppContext } from "@/new/photos/types/context";import { Overlay } from "@ente/shared/components/Container";import DialogBox from "@ente/shared/components/DialogBox";import { DialogBoxAttributes } from "@ente/shared/components/DialogBox/types";-import type { DialogBoxAttributesV2 } from "@ente/shared/components/DialogBoxV2";-import DialogBoxV2 from "@ente/shared/components/DialogBoxV2";import { MessageContainer } from "@ente/shared/components/MessageContainer";import { useLocalState } from "@ente/shared/hooks/useLocalState";import HTTPService from "@ente/shared/network/HTTPService";@@ -71,7 +71,7 @@ export default function App({ Component, pageProps }: AppProps) {const loadingBar = useRef(null);const [dialogMessage, setDialogMessage] = useState<DialogBoxAttributes>();const [dialogBoxAttributeV2, setDialogBoxAttributesV2] = useState<- DialogBoxAttributesV2 | undefined+ MiniDialogAttributes | undefined>();const [messageDialogView, setMessageDialogView] = useState(false);const [dialogBoxV2View, setDialogBoxV2View] = useState(false);diff --git a/web/packages/accounts/pages/two-factor/recover.tsx b/web/packages/accounts/pages/two-factor/recover.tsxindex fe681f3824..820a0707e4 100644--- a/web/packages/accounts/pages/two-factor/recover.tsx+++ b/web/packages/accounts/pages/two-factor/recover.tsx@@ -5,12 +5,12 @@ import {} from "@/accounts/api/user";import { PAGES } from "@/accounts/constants/pages";import type { AccountsContextT } from "@/accounts/types/context";+import type { MiniDialogAttributes } from "@/base/components/MiniDialog";import { sharedCryptoWorker } from "@/base/crypto";import type { B64EncryptionResult } from "@/base/crypto/libsodium";import log from "@/base/log";import { ensure } from "@/utils/ensure";import { VerticallyCentered } from "@ente/shared/components/Container";-import type { DialogBoxAttributesV2 } from "@ente/shared/components/DialogBoxV2";import FormPaper from "@ente/shared/components/Form/FormPaper";import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer";import FormPaperTitle from "@ente/shared/components/Form/FormPaper/Title";@@ -146,7 +146,7 @@ const Page: React.FC<RecoverPageProps> = ({ appContext, twoFactorType }) => {};const showContactSupportDialog = (- dialogClose?: DialogBoxAttributesV2["close"],+ dialogClose?: MiniDialogAttributes["close"],) => {appContext.setDialogBoxAttributesV2({title: t("contact_support"),diff --git a/web/packages/accounts/types/context.ts b/web/packages/accounts/types/context.tsindex deba96a681..ae9fd7b9b6 100644--- a/web/packages/accounts/types/context.ts+++ b/web/packages/accounts/types/context.ts@@ -1,4 +1,4 @@-import type { DialogBoxAttributesV2 } from "@ente/shared/components/DialogBoxV2";+import type { MiniDialogAttributes } from "@/base/components/MiniDialog";/*** Properties expected to be present in the AppContext types for pages that@@ -9,5 +9,5 @@ export interface AccountsContextT {logout: () => void;/** Show or hide the app's navigation bar. */showNavBar: (show: boolean) => void;- setDialogBoxAttributesV2: (attrs: DialogBoxAttributesV2) => void;+ setDialogBoxAttributesV2: (attrs: MiniDialogAttributes) => void;}diff --git a/web/packages/shared/components/DialogBoxV2.tsx b/web/packages/base/components/MiniDialog.tsxsimilarity index 56%rename from web/packages/shared/components/DialogBoxV2.tsxrename to web/packages/base/components/MiniDialog.tsxindex db091d3f8a..448e19a3ff 100644--- a/web/packages/shared/components/DialogBoxV2.tsx+++ b/web/packages/base/components/MiniDialog.tsx@@ -1,3 +1,7 @@+// TODO:+/* eslint-disable @typescript-eslint/prefer-optional-chain */+/* eslint-disable @typescript-eslint/no-unnecessary-condition */+/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton";import { LoadingButton } from "@/base/components/mui/LoadingButton";import { dialogCloseHandler } from "@ente/shared/components/DialogBox/TitleWithCloseButton";@@ -19,7 +23,7 @@ import React, { useState } from "react";* meant to confirm some user action. If more customization is needed, it might* be a better idea to reach out for a bespoke MUI {@link DialogBox} instead.*/-export interface DialogBoxAttributesV2 {+export interface MiniDialogAttributes {icon?: React.ReactNode;/*** The dialog's title@@ -87,20 +91,158 @@ export interface DialogBoxAttributesV2 {buttonDirection?: "row" | "column";}-type IProps = React.PropsWithChildren<+type MiniDialogProps = React.PropsWithChildren<Omit<DialogProps, "onClose"> & {onClose: () => void;- attributes?: DialogBoxAttributesV2;+ attributes?: MiniDialogAttributes;}>;-export default function DialogBoxV2({+/**+ * A small, mostly predefined, MUI {@link Dialog} that can be used to notify the+ * user, or ask for confirmation before actions.+ *+ * The rendered dialog can be customized by modifying the {@link attributes}+ * prop. If you find yourself wanting to customize it further, consider just+ * creating a new bespoke instantiation of a {@link Dialog}.+ */+export function MiniDialog({+ attributes,+ children,+ open,+ onClose,+ ...props+}: MiniDialogProps) {+ const [loading, setLoading] = useState(false);+ if (!attributes) {+ return <></>;+ }++ const handleClose = dialogCloseHandler({+ staticBackdrop: attributes.staticBackdrop,+ nonClosable: attributes.nonClosable,+ onClose: onClose,+ });++ const { PaperProps, ...rest } = props;++ return (+ <Dialog+ open={open}+ onClose={handleClose}+ PaperProps={{+ ...PaperProps,+ sx: {+ padding: "8px 12px",+ maxWidth: "360px",+ ...PaperProps?.sx,+ },+ }}+ {...rest}+ >+ <Stack spacing={"36px"} p={"16px"}>+ <Stack spacing={"19px"}>+ {attributes.icon && (+ <Box+ sx={{+ "& > svg": {+ fontSize: "32px",+ },+ }}+ >+ {attributes.icon}+ </Box>+ )}+ {attributes.title && (+ <Typography variant="large" fontWeight={"bold"}>+ {attributes.title}+ </Typography>+ )}+ {children ||+ (attributes?.content && (+ <Typography color="text.muted">+ {attributes.content}+ </Typography>+ ))}+ </Stack>+ {(attributes.proceed ||+ attributes.close ||+ attributes.buttons?.length) && (+ <Stack+ spacing={"8px"}+ direction={+ attributes.buttonDirection === "row"+ ? "row-reverse"+ : "column"+ }+ flex={1}+ >+ {attributes.proceed && (+ <LoadingButton+ loading={loading}+ size="large"+ color={attributes.proceed?.variant}+ onClick={async () => {+ await attributes.proceed?.action(+ setLoading,+ );++ onClose();+ }}+ disabled={attributes.proceed.disabled}+ >+ {attributes.proceed.text}+ </LoadingButton>+ )}+ {attributes.close && (+ <FocusVisibleButton+ size="large"+ color={attributes.close?.variant ?? "secondary"}+ onClick={() => {+ attributes.close?.action &&+ attributes.close?.action();+ onClose();+ }}+ >+ {attributes.close?.text ?? t("ok")}+ </FocusVisibleButton>+ )}+ {attributes.buttons &&+ attributes.buttons.map((b) => (+ <FocusVisibleButton+ size="large"+ key={b.text}+ color={b.variant}+ onClick={() => {+ b.action();+ onClose();+ }}+ disabled={b.disabled}+ >+ {b.text}+ </FocusVisibleButton>+ ))}+ </Stack>+ )}+ </Stack>+ </Dialog>+ );+}++/**+ * TODO This is a duplicate of MiniDialog. This is for use by call sites that+ * were using the MiniDialog not as a dialog but as a base container. Such use+ * cases are better served by directly using the MUI {@link Dialog}, so these+ * are considered deprecated. Splitting these here so that we can streamline the+ * API for the notify/confirm case separately.+ */+export function DialogBoxV2({attributes,children,open,onClose,...props-}: IProps) {+}: MiniDialogProps) {const [loading, setLoading] = useState(false);if (!attributes) {return <></>;diff --git a/web/packages/shared/components/LoginComponents.tsx b/web/packages/shared/components/LoginComponents.tsxindex b888b81d95..4f0366a834 100644--- a/web/packages/shared/components/LoginComponents.tsx+++ b/web/packages/shared/components/LoginComponents.tsx@@ -3,6 +3,7 @@ import {passkeySessionExpiredErrorMessage,saveCredentialsAndNavigateTo,} from "@/accounts/services/passkey";+import type { MiniDialogAttributes } from "@/base/components/MiniDialog";import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton";import log from "@/base/log";import { customAPIHost } from "@/base/origins";@@ -11,7 +12,6 @@ import { t } from "i18next";import { useRouter } from "next/router";import React, { useEffect, useState } from "react";import { VerticallyCentered } from "./Container";-import type { DialogBoxAttributesV2 } from "./DialogBoxV2";import FormPaper from "./Form/FormPaper";import FormPaperFooter from "./Form/FormPaper/Footer";import LinkButton from "./LinkButton";@@ -74,7 +74,7 @@ interface VerifyingPasskeyProps {onRetry: () => void;/** Perform the (possibly app specific) logout sequence. */logout: () => void;- setDialogBoxAttributesV2: (attrs: DialogBoxAttributesV2) => void;+ setDialogBoxAttributesV2: (attrs: MiniDialogAttributes) => void;}export const VerifyingPasskey: React.FC<VerifyingPasskeyProps> = ({@@ -205,7 +205,7 @@ const ButtonStack = styled("div")`*/export const sessionExpiredDialogAttributes = (onLogin: () => void,-): DialogBoxAttributesV2 => ({+): MiniDialogAttributes => ({title: t("SESSION_EXPIRED"),content: t("SESSION_EXPIRED_MESSAGE"),nonClosable: true,@@ -219,7 +219,7 @@ export const sessionExpiredDialogAttributes = (/*** {@link DialogBoxAttributesV2} for showing a generic error.*/-const genericErrorAttributes = (): DialogBoxAttributesV2 => ({+const genericErrorAttributes = (): MiniDialogAttributes => ({title: t("error"),close: { variant: "critical" },content: t("generic_error_retry"),