Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

wip checkpoint

Manav Rathid6a39ae45262
diff --git a/web/apps/auth/src/pages/_app.tsx b/web/apps/auth/src/pages/_app.tsx
index f11505073f..e18b0684ff 100644
--- a/web/apps/auth/src/pages/_app.tsx
+++ b/web/apps/auth/src/pages/_app.tsx
@@ -2,12 +2,13 @@ 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,
- AttributedMiniDialog,
-} from "@/base/components/MiniDialog";
+import { AttributedMiniDialog } from "@/base/components/MiniDialog";
import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";
import { AppNavbar } from "@/base/components/Navbar";
+import {
+ genericErrorDialogAttributes,
+ useAttributedMiniDialog,
+} from "@/base/components/utils/mini-dialog";
import { setupI18n } from "@/base/i18n";
import {
logStartupBanner,
@@ -39,6 +40,7 @@ import React, {
useState,
} from "react";
import LoadingBar, { type LoadingBarRef } from "react-top-loading-bar";
+
import "../../public/css/global.css";
/**
@@ -68,10 +70,8 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
const [showNavbar, setShowNavBar] = useState(false);
const isLoadingBarRunning = useRef<boolean>(false);
const loadingBar = useRef<LoadingBarRef>(null);
- const [dialogBoxAttributeV2, setDialogBoxAttributesV2] = useState<
- MiniDialogAttributes | undefined
- >();
- const [dialogBoxV2View, setDialogBoxV2View] = useState(false);
+
+ const { showMiniDialog, miniDialogProps } = useAttributedMiniDialog();
const [themeColor, setThemeColor] = useLocalState(
LS_KEYS.THEME,
THEME_COLOR.DARK,
@@ -111,16 +111,13 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
};
}, []);
- useEffect(() => {
- setDialogBoxV2View(true);
- }, [dialogBoxAttributeV2]);
-
const showNavBar = (show: boolean) => setShowNavBar(show);
const startLoading = () => {
!isLoadingBarRunning.current && loadingBar.current?.continuousStart();
isLoadingBarRunning.current = true;
};
+
const finishLoading = () => {
setTimeout(() => {
isLoadingBarRunning.current && loadingBar.current?.complete();
@@ -128,14 +125,8 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
}, 100);
};
- const closeDialogBoxV2 = () => setDialogBoxV2View(false);
-
const somethingWentWrong = () =>
- setDialogBoxAttributesV2({
- title: t("error"),
- close: { variant: "critical" },
- message: t("generic_error_retry"),
- });
+ showMiniDialog(genericErrorDialogAttributes());
const logout = () => {
void accountLogout().then(() => router.push("/"));
@@ -144,7 +135,7 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
const appContext = {
logout,
showNavBar,
- setDialogBoxAttributesV2,
+ showMiniDialog,
startLoading,
finishLoading,
themeColor,
@@ -167,11 +158,7 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
<LoadingBar color="#51cd7c" ref={loadingBar} />
- <AttributedMiniDialog
- open={dialogBoxV2View}
- onClose={closeDialogBoxV2}
- attributes={dialogBoxAttributeV2}
- />
+ <AttributedMiniDialog {...miniDialogProps} />
<AppContext.Provider value={appContext}>
{(loading || !isI18nReady) && (
diff --git a/web/apps/auth/src/pages/auth.tsx b/web/apps/auth/src/pages/auth.tsx
index 917808bd83..6fb996cf3f 100644
--- a/web/apps/auth/src/pages/auth.tsx
+++ b/web/apps/auth/src/pages/auth.tsx
@@ -1,3 +1,4 @@
+import { sessionExpiredDialogAttributes } from "@/accounts/components/LoginComponents";
import { stashRedirect } from "@/accounts/services/redirect";
import { EnteLogo } from "@/base/components/EnteLogo";
import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";
@@ -7,7 +8,6 @@ import {
HorizontalFlex,
VerticallyCentered,
} from "@ente/shared/components/Container";
-import { sessionExpiredDialogAttributes } from "@ente/shared/components/LoginComponents";
import OverflowMenu from "@ente/shared/components/OverflowMenu/menu";
import { OverflowMenuOption } from "@ente/shared/components/OverflowMenu/option";
import { AUTH_PAGES as PAGES } from "@ente/shared/constants/pages";
@@ -23,7 +23,7 @@ import { getAuthCodes } from "services/remote";
import { AppContext } from "./_app";
const Page: React.FC = () => {
- const { logout, showNavBar, setDialogBoxAttributesV2 } = ensure(
+ const { logout, showNavBar, showMiniDialog } = ensure(
useContext(AppContext),
);
const router = useRouter();
@@ -32,7 +32,7 @@ const Page: React.FC = () => {
const [searchTerm, setSearchTerm] = useState("");
const showSessionExpiredDialog = () =>
- setDialogBoxAttributesV2(sessionExpiredDialogAttributes(logout));
+ showMiniDialog(sessionExpiredDialogAttributes(logout));
useEffect(() => {
const fetchCodes = async () => {
diff --git a/web/apps/photos/src/components/AuthenticateUserModal.tsx b/web/apps/photos/src/components/AuthenticateUserModal.tsx
index 0b6a83b7f9..6f17a61bc7 100644
--- a/web/apps/photos/src/components/AuthenticateUserModal.tsx
+++ b/web/apps/photos/src/components/AuthenticateUserModal.tsx
@@ -24,8 +24,7 @@ export default function AuthenticateUserModal({
onClose,
onAuthenticate,
}: Iprops) {
- const { setDialogMessage, setDialogBoxAttributesV2, logout } =
- useContext(AppContext);
+ const { setDialogMessage, showMiniDialog, logout } = useContext(AppContext);
const [user, setUser] = useState<User>();
const [keyAttributes, setKeyAttributes] = useState<KeyAttributes>();
@@ -46,7 +45,7 @@ export default function AuthenticateUserModal({
const session = await checkSessionValidity();
if (session.status != "valid") {
onClose();
- setDialogBoxAttributesV2(
+ showMiniDialog(
passwordChangedElsewhereDialogAttributes(logout),
);
}
@@ -55,7 +54,7 @@ export default function AuthenticateUserModal({
// potentially transient issues.
log.warn("Ignoring error when determining session validity", e);
}
- }, [setDialogBoxAttributesV2, logout]);
+ }, [showMiniDialog, logout]);
useEffect(() => {
const main = async () => {
@@ -127,10 +126,8 @@ const passwordChangedElsewhereDialogAttributes = (
): MiniDialogAttributes => ({
title: t("password_changed_elsewhere"),
message: t("password_changed_elsewhere_message"),
- proceed: {
+ continue: {
text: t("login"),
action: onLogin,
- variant: "accent",
},
- close: { text: t("cancel") },
});
diff --git a/web/apps/photos/src/components/DeleteAccountModal.tsx b/web/apps/photos/src/components/DeleteAccountModal.tsx
index 8b75b2a630..82cd039c44 100644
--- a/web/apps/photos/src/components/DeleteAccountModal.tsx
+++ b/web/apps/photos/src/components/DeleteAccountModal.tsx
@@ -1,7 +1,6 @@
import { TitledMiniDialog } 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 { Link, Stack, useMediaQuery } from "@mui/material";
@@ -28,7 +27,7 @@ interface FormValues {
}
const DeleteAccountModal = ({ open, onClose }: Iprops) => {
- const { setDialogBoxAttributesV2, logout } = useContext(AppContext);
+ const { showMiniDialog, onGenericError, logout } = useContext(AppContext);
const { authenticateUser } = useContext(GalleryContext);
const [loading, setLoading] = useState(false);
@@ -39,13 +38,6 @@ const DeleteAccountModal = ({ open, onClose }: Iprops) => {
const isMobile = useMediaQuery("(max-width: 428px)");
- const somethingWentWrong = () =>
- setDialogBoxAttributesV2({
- title: t("error"),
- close: { variant: "critical" },
- message: t("generic_error_retry"),
- });
-
const initiateDelete = async (
{ reason, feedback }: FormValues,
{ setFieldError }: FormikHelpers<FormValues>,
@@ -76,30 +68,28 @@ const DeleteAccountModal = ({ open, onClose }: Iprops) => {
askToMailForDeletion();
}
} catch (e) {
- log.error("Error while initiating account deletion", e);
- somethingWentWrong();
+ onGenericError(e);
} finally {
setLoading(false);
}
};
const confirmAccountDeletion = () => {
- setDialogBoxAttributesV2({
+ showMiniDialog({
title: t("delete_account"),
message: <Trans i18nKey="delete_account_confirm_message" />,
- proceed: {
+ continue: {
text: t("delete"),
+ color: "critical",
action: solveChallengeAndDeleteAccount,
- variant: "critical",
},
- close: { text: t("cancel") },
});
};
const askToMailForDeletion = () => {
const emailID = "[email protected]";
- setDialogBoxAttributesV2({
+ showMiniDialog({
title: t("delete_account"),
message: (
<Trans
@@ -108,15 +98,15 @@ const DeleteAccountModal = ({ open, onClose }: Iprops) => {
values={{ emailID }}
/>
),
- proceed: {
+ continue: {
text: t("delete"),
+ color: "critical",
action: () => initiateEmail(emailID),
- variant: "critical",
},
- close: { text: t("cancel") },
});
};
+ /* mark: uses-loading */
const solveChallengeAndDeleteAccount = async (
setLoading: (value: boolean) => void,
) => {
@@ -129,8 +119,7 @@ const DeleteAccountModal = ({ open, onClose }: Iprops) => {
await deleteAccount(decryptedChallenge, reason, feedback);
logout();
} catch (e) {
- log.error("solveChallengeAndDeleteAccount failed", e);
- somethingWentWrong();
+ onGenericError(e);
} finally {
setLoading(false);
}
diff --git a/web/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx b/web/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx
index f558b2e480..9c39ae3f87 100644
--- a/web/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx
+++ b/web/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx
@@ -1,4 +1,5 @@
import { EnteDrawer } from "@/base/components/EnteDrawer";
+import type { MiniDialogAttributes } from "@/base/components/MiniDialog";
import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";
import { Titlebar } from "@/base/components/Titlebar";
import { EllipsizedTypography } from "@/base/components/Typography";
@@ -53,12 +54,9 @@ import LinkButton from "components/pages/gallery/LinkButton";
import { t } from "i18next";
import { GalleryContext } from "pages/gallery";
import React, { useContext, useEffect, useMemo, useState } from "react";
+import { Trans } from "react-i18next";
import { changeFileName, updateExistingFilePubMetadata } from "utils/file";
import { PublicCollectionGalleryContext } from "utils/publicCollectionGallery";
-import {
- getMapDisableConfirmationDialog,
- getMapEnableConfirmationDialog,
-} from "utils/ui";
import { FileNameEditDialog } from "./FileNameEditDialog";
import InfoItem from "./InfoItem";
import MapBox from "./MapBox";
@@ -101,7 +99,7 @@ export const FileInfo: React.FC<FileInfoProps> = ({
closePhotoViewer,
onSelectPerson,
}) => {
- const { mapEnabled, updateMapEnabled, setDialogBoxAttributesV2 } =
+ const { mapEnabled, updateMapEnabled, showMiniDialog } =
useContext(AppContext);
const galleryContext = useContext(GalleryContext);
const publicCollectionGalleryContext = useContext(
@@ -151,13 +149,13 @@ export const FileInfo: React.FC<FileInfoProps> = ({
};
const openEnableMapConfirmationDialog = () =>
- setDialogBoxAttributesV2(
- getMapEnableConfirmationDialog(() => updateMapEnabled(true)),
+ showMiniDialog(
+ confirmEnableMapsDialogAttributes(() => updateMapEnabled(true)),
);
const openDisableMapConfirmationDialog = () =>
- setDialogBoxAttributesV2(
- getMapDisableConfirmationDialog(() => updateMapEnabled(false)),
+ showMiniDialog(
+ confirmDisableMapsDialogAttributes(() => updateMapEnabled(false)),
);
const handleSelectFace = (annotatedFaceID: AnnotatedFaceID) => {
@@ -379,6 +377,35 @@ const parseExifInfo = (
return info;
};
+const confirmEnableMapsDialogAttributes = (
+ onConfirm: () => void,
+): MiniDialogAttributes => ({
+ title: t("ENABLE_MAPS"),
+ message: (
+ <Trans
+ i18nKey={"ENABLE_MAP_DESCRIPTION"}
+ components={{
+ a: (
+ <Link
+ target="_blank"
+ rel="noopener"
+ href="https://www.openstreetmap.org/"
+ />
+ ),
+ }}
+ />
+ ),
+ continue: { text: t("enable"), action: onConfirm },
+});
+
+const confirmDisableMapsDialogAttributes = (
+ onConfirm: () => void,
+): MiniDialogAttributes => ({
+ title: t("DISABLE_MAPS"),
+ message: <Trans i18nKey={"DISABLE_MAP_DESCRIPTION"} />,
+ continue: { text: t("disable"), action: onConfirm },
+});
+
const FileInfoSidebar = styled((props: DialogProps) => (
<EnteDrawer {...props} anchor="right" />
))({
diff --git a/web/apps/photos/src/utils/ui/index.tsx b/web/apps/photos/src/utils/ui/index.tsx
index ecd25edb64..4d259f2310 100644
--- a/web/apps/photos/src/utils/ui/index.tsx
+++ b/web/apps/photos/src/utils/ui/index.tsx
@@ -1,3 +1,4 @@
+import type { MiniDialogAttributes } from "@/base/components/MiniDialog";
import { ensureElectron } from "@/base/electron";
import { AppUpdate } from "@/base/types/ipc";
import { openURL } from "@/new/photos/utils/web";
@@ -136,45 +137,6 @@ export const getSessionExpiredMessage = (
},
});
-export const getMapEnableConfirmationDialog = (
- enableMapHelper,
-): DialogBoxAttributes => ({
- title: t("ENABLE_MAPS"),
- content: (
- <Trans
- i18nKey={"ENABLE_MAP_DESCRIPTION"}
- components={{
- a: (
- <Link
- target="_blank"
- rel="noopener"
- href="https://www.openstreetmap.org/"
- />
- ),
- }}
- />
- ),
- proceed: {
- action: enableMapHelper,
- text: t("enable"),
- variant: "accent",
- },
- close: { text: t("cancel") },
-});
-
-export const getMapDisableConfirmationDialog = (
- disableMapHelper,
-): DialogBoxAttributes => ({
- title: t("DISABLE_MAPS"),
- content: <Trans i18nKey={"DISABLE_MAP_DESCRIPTION"} />,
- proceed: {
- action: disableMapHelper,
- text: t("disable"),
- variant: "accent",
- },
- close: { text: t("cancel") },
-});
-
export const getEditorCloseConfirmationMessage = (
doClose: () => void,
): DialogBoxAttributes => ({
diff --git a/web/packages/accounts/components/LoginComponents.tsx b/web/packages/accounts/components/LoginComponents.tsx
index b7bdb675c3..cece699417 100644
--- a/web/packages/accounts/components/LoginComponents.tsx
+++ b/web/packages/accounts/components/LoginComponents.tsx
@@ -75,7 +75,7 @@ interface VerifyingPasskeyProps {
onRetry: () => void;
/** Perform the (possibly app specific) logout sequence. */
logout: () => void;
- setDialogBoxAttributesV2: (attrs: MiniDialogAttributes) => void;
+ showMiniDialog: (attrs: MiniDialogAttributes) => void;
}
export const VerifyingPasskey: React.FC<VerifyingPasskeyProps> = ({
@@ -83,7 +83,7 @@ export const VerifyingPasskey: React.FC<VerifyingPasskeyProps> = ({
email,
onRetry,
logout,
- setDialogBoxAttributesV2,
+ showMiniDialog,
}) => {
type VerificationStatus = "waiting" | "checking" | "pending";
const [verificationStatus, setVerificationStatus] =
@@ -105,7 +105,7 @@ export const VerifyingPasskey: React.FC<VerifyingPasskeyProps> = ({
else router.push(await saveCredentialsAndNavigateTo(response));
} catch (e) {
log.error("Passkey verification status check failed", e);
- setDialogBoxAttributesV2(
+ showMiniDialog(
e instanceof Error &&
e.message == passkeySessionExpiredErrorMessage
? sessionExpiredDialogAttributes(logout)
diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsx
index ca8245258f..5287a7fbcf 100644
--- a/web/packages/accounts/pages/credentials.tsx
+++ b/web/packages/accounts/pages/credentials.tsx
@@ -66,7 +66,7 @@ import type { PageProps } from "../types/page";
import type { SRPAttributes } from "../types/srp";
const Page: React.FC<PageProps> = ({ appContext }) => {
- const { logout, showNavBar, setDialogBoxAttributesV2 } = appContext;
+ const { logout, showNavBar, showMiniDialog } = appContext;
const [srpAttributes, setSrpAttributes] = useState<SRPAttributes>();
const [keyAttributes, setKeyAttributes] = useState<KeyAttributes>();
@@ -82,7 +82,7 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
const validateSession = useCallback(async () => {
const showSessionExpiredDialog = () =>
- setDialogBoxAttributesV2(sessionExpiredDialogAttributes(logout));
+ showMiniDialog(sessionExpiredDialogAttributes(logout));
try {
const session = await checkSessionValidity();
@@ -114,7 +114,7 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
// potentially transient issues.
log.warn("Ignoring error when determining session validity", e);
}
- }, [setDialogBoxAttributesV2, logout]);
+ }, [showMiniDialog, logout]);
useEffect(() => {
const main = async () => {
@@ -354,7 +354,7 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
onRetry={() =>
openPasskeyVerificationURL(passkeyVerificationData)
}
- {...{ logout, setDialogBoxAttributesV2 }}
+ {...{ logout, showMiniDialog }}
/>
);
}
diff --git a/web/packages/accounts/pages/verify.tsx b/web/packages/accounts/pages/verify.tsx
index c3b334cdd7..f11e77f2f8 100644
--- a/web/packages/accounts/pages/verify.tsx
+++ b/web/packages/accounts/pages/verify.tsx
@@ -46,7 +46,7 @@ import type { PageProps } from "../types/page";
import type { SRPAttributes, SRPSetupAttributes } from "../types/srp";
const Page: React.FC<PageProps> = ({ appContext }) => {
- const { logout, showNavBar, setDialogBoxAttributesV2 } = appContext;
+ const { logout, showNavBar, showMiniDialog } = appContext;
const [email, setEmail] = useState("");
const [resend, setResend] = useState(0);
@@ -202,7 +202,7 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
onRetry={() =>
openPasskeyVerificationURL(passkeyVerificationData)
}
- {...{ logout, setDialogBoxAttributesV2 }}
+ {...{ logout, showMiniDialog }}
/>
);
}