Skip to content

armgit / ente

Public Imported from GitHub
0

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

Reuse app lock UI for initialization errors

Manav Rathic0a2eef1a0f1
diff --git a/web/apps/photos/src/components/Sidebar.tsx b/web/apps/photos/src/components/Sidebar.tsx
index 72128e4f7c..2ebbd629f3 100644
--- a/web/apps/photos/src/components/Sidebar.tsx
+++ b/web/apps/photos/src/components/Sidebar.tsx
@@ -47,7 +47,6 @@ import {
TitledNestedSidebarDrawer,
type NestedSidebarDrawerVisibilityProps,
} from "ente-base/components/mui/SidebarDrawer";
-import { logoutDialogAttributes } from "ente-base/components/utils/dialog";
import { useIsSmallWidth } from "ente-base/components/utils/hooks";
import {
useModalVisibility,
@@ -278,7 +277,16 @@ export const Sidebar: React.FC<SidebarProps> = ({
useState<FreeUpSpaceAction>();
const handleLogout = useCallback(
- () => showMiniDialog(logoutDialogAttributes(logout)),
+ () =>
+ showMiniDialog({
+ message: t("logout_message"),
+ continue: {
+ text: t("logout"),
+ color: "critical",
+ action: logout,
+ },
+ buttonDirection: "row",
+ }),
[logout, showMiniDialog],
);
diff --git a/web/apps/photos/src/components/app-lock/LockScreenContents.tsx b/web/apps/photos/src/components/app-lock/LockScreenContents.tsx
index ed934060d3..1e2582cff7 100644
--- a/web/apps/photos/src/components/app-lock/LockScreenContents.tsx
+++ b/web/apps/photos/src/components/app-lock/LockScreenContents.tsx
@@ -1,12 +1,29 @@
-import { Box } from "@mui/material";
+import ErrorOutlinedIcon from "@mui/icons-material/ErrorOutlined";
+import { Box, Modal, Stack, Typography } from "@mui/material";
import { EnteLogo } from "ente-base/components/EnteLogo";
import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";
+import { useBaseContext } from "ente-base/context";
+import { AppLockCard } from "ente-new/photos/components/app-lock/AppLockCard";
+import { AppLockLogoutConfirmation } from "ente-new/photos/components/app-lock/AppLockFeedback";
import { AppLockPrompt } from "ente-new/photos/components/app-lock/AppLockPrompt";
import { t } from "i18next";
-import type { CSSProperties } from "react";
+import type { CSSProperties, PropsWithChildren } from "react";
+import { useState } from "react";
-export const LockScreenContents = () => {
- return (
+export const AppLockScreen = ({ children }: PropsWithChildren) => (
+ <Modal
+ open
+ aria-label={t("app_lock")}
+ slotProps={{
+ backdrop: {
+ sx: (theme) => ({
+ backgroundColor: "secondary.main",
+ ...theme.applyStyles("dark", { backgroundColor: "#000" }),
+ }),
+ },
+ }}
+ sx={{ zIndex: "calc(var(--mui-zIndex-tooltip) + 1)" }}
+ >
<Box
sx={{
position: "fixed",
@@ -19,41 +36,118 @@ export const LockScreenContents = () => {
}}
style={{ WebkitAppRegion: "no-drag" } as CSSProperties}
>
- <AppLockPrompt
- lockScreenMode="lock"
- renderHeader={({ showLogoutConfirm, showLogout }) => (
- <Box
+ {children}
+ </Box>
+ </Modal>
+);
+
+interface LockScreenHeaderProps {
+ showLogout: boolean;
+ onLogout: () => void;
+}
+
+const LockScreenHeader = ({ showLogout, onLogout }: LockScreenHeaderProps) => (
+ <Box
+ sx={{
+ position: "absolute",
+ top: 0,
+ left: 0,
+ right: 0,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ p: 3,
+ }}
+ >
+ <EnteLogo />
+ {showLogout && (
+ <FocusVisibleButton
+ variant="text"
+ color="secondary"
+ size="small"
+ onClick={onLogout}
+ sx={{
+ textTransform: "none",
+ position: "absolute",
+ right: 24,
+ color: "text.muted",
+ }}
+ >
+ {t("logout")}
+ </FocusVisibleButton>
+ )}
+ </Box>
+);
+
+export const LockScreenContents = () => (
+ <AppLockPrompt
+ lockScreenMode="lock"
+ renderHeader={({ showLogoutConfirm, showLogout }) => (
+ <LockScreenHeader
+ showLogout={!showLogoutConfirm}
+ onLogout={showLogout}
+ />
+ )}
+ />
+);
+
+export const AppLockSetupError = ({ onRetry }: { onRetry: () => void }) => {
+ const { logout } = useBaseContext();
+ const [showLogoutConfirm, setShowLogoutConfirm] = useState(false);
+
+ return (
+ <AppLockScreen>
+ <LockScreenHeader
+ showLogout={!showLogoutConfirm}
+ onLogout={() => setShowLogoutConfirm(true)}
+ />
+ {showLogoutConfirm ? (
+ <AppLockLogoutConfirmation
+ onConfirm={logout}
+ onCancel={() => setShowLogoutConfirm(false)}
+ />
+ ) : (
+ <AppLockCard>
+ <Stack
+ spacing={0}
sx={{
- position: "absolute",
- top: 0,
- left: 0,
- right: 0,
- display: "flex",
+ width: 376,
+ maxWidth: "100%",
alignItems: "center",
- justifyContent: "center",
- p: 3,
}}
>
- <EnteLogo />
- {!showLogoutConfirm && (
- <FocusVisibleButton
- variant="text"
- color="secondary"
- size="small"
- onClick={showLogout}
- sx={{
- textTransform: "none",
- position: "absolute",
- right: 24,
- color: "text.muted",
- }}
- >
- {t("logout")}
- </FocusVisibleButton>
- )}
- </Box>
- )}
- />
- </Box>
+ <ErrorOutlinedIcon
+ sx={{ fontSize: 48, color: "text.muted", mb: 3 }}
+ />
+ <Typography
+ sx={{
+ maxWidth: 320,
+ fontSize: 20,
+ fontWeight: 600,
+ lineHeight: "26px",
+ textAlign: "center",
+ mb: 4,
+ }}
+ >
+ {t("app_lock_unavailable")}
+ </Typography>
+ <FocusVisibleButton
+ fullWidth
+ color="secondary"
+ onClick={onRetry}
+ sx={{
+ minHeight: 56,
+ borderRadius: "20px",
+ fontSize: 16,
+ fontWeight: 600,
+ lineHeight: "20px",
+ }}
+ >
+ {t("retry")}
+ </FocusVisibleButton>
+ </Stack>
+ </AppLockCard>
+ )}
+ </AppLockScreen>
);
};
diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsx
index 8f2a54a0b6..36f2f489c3 100644
--- a/web/apps/photos/src/pages/_app.tsx
+++ b/web/apps/photos/src/pages/_app.tsx
@@ -1,17 +1,17 @@
+import { AppLockSetupError } from "@/components/app-lock/LockScreenContents";
import { useDesktopAppLockRoute } from "@/components/utils/use-app-lock-route";
import { photosLogout } from "@/services/logout";
import "@fontsource-variable/inter";
import "@fontsource/outfit/700.css";
import ArrowForwardIcon from "@mui/icons-material/ArrowForward";
-import { Button, CssBaseline, Typography } from "@mui/material";
+import { CssBaseline, Typography } from "@mui/material";
import { styled, ThemeProvider } from "@mui/material/styles";
import {
isLocalStorageAndIndexedDBMismatch,
savedLocalUser,
} from "ente-accounts/services/accounts-db";
import { isDesktop, staticAppTitle } from "ente-base/app";
-import { CenteredRow, Stack100vhCenter } from "ente-base/components/containers";
-import { ActivityErrorIndicator } from "ente-base/components/ErrorIndicator";
+import { CenteredRow } from "ente-base/components/containers";
import { CustomHead } from "ente-base/components/Head";
import {
LoadingIndicator,
@@ -20,10 +20,7 @@ import {
import { AttributedMiniDialog } from "ente-base/components/MiniDialog";
import { Notification } from "ente-base/components/Notification";
import { ThemedLoadingBar } from "ente-base/components/ThemedLoadingBar";
-import {
- logoutDialogAttributes,
- useAttributedMiniDialog,
-} from "ente-base/components/utils/dialog";
+import { useAttributedMiniDialog } from "ente-base/components/utils/dialog";
import {
useIsRouteChangeInProgress,
useNotification,
@@ -32,11 +29,7 @@ import {
} from "ente-base/components/utils/hooks-app";
import { photosTheme } from "ente-base/components/utils/theme";
import { useLoadingBar } from "ente-base/components/utils/use-loading-bar";
-import {
- BaseContext,
- deriveBaseContext,
- useBaseContext,
-} from "ente-base/context";
+import { BaseContext, deriveBaseContext } from "ente-base/context";
import log from "ente-base/log";
import { logStartupBanner } from "ente-base/log-web";
import type { AppUpdate } from "ente-base/types/ipc";
@@ -258,27 +251,6 @@ const DesktopMainContent: React.FC<MainContentProps> = ({
);
};
-const AppLockSetupError: React.FC<{ onRetry: () => void }> = ({ onRetry }) => {
- const { logout, showMiniDialog } = useBaseContext();
-
- return (
- <Stack100vhCenter sx={{ gap: 2 }}>
- <ActivityErrorIndicator>
- {t("app_lock_unavailable")}
- </ActivityErrorIndicator>
- <Button color="accent" onClick={onRetry}>
- {t("retry")}
- </Button>
- <Button
- color="secondary"
- onClick={() => showMiniDialog(logoutDialogAttributes(logout))}
- >
- {t("logout")}
- </Button>
- </Stack100vhCenter>
- );
-};
-
const WindowTitlebar: React.FC<React.PropsWithChildren> = ({ children }) => (
<WindowTitlebarArea>
<Typography variant="small" sx={{ mt: "2px", fontWeight: "bold" }}>
diff --git a/web/apps/photos/src/pages/lock.tsx b/web/apps/photos/src/pages/lock.tsx
index 84e4fd4515..0cf6ab4c3f 100644
--- a/web/apps/photos/src/pages/lock.tsx
+++ b/web/apps/photos/src/pages/lock.tsx
@@ -1,23 +1,12 @@
-import { LockScreenContents } from "@/components/app-lock/LockScreenContents";
-import { Modal } from "@mui/material";
-import { t } from "i18next";
+import {
+ AppLockScreen,
+ LockScreenContents,
+} from "@/components/app-lock/LockScreenContents";
export const LockPage = () => (
- <Modal
- open
- aria-label={t("app_lock")}
- slotProps={{
- backdrop: {
- sx: (theme) => ({
- backgroundColor: "secondary.main",
- ...theme.applyStyles("dark", { backgroundColor: "#000" }),
- }),
- },
- }}
- sx={{ zIndex: "calc(var(--mui-zIndex-tooltip) + 1)" }}
- >
+ <AppLockScreen>
<LockScreenContents />
- </Modal>
+ </AppLockScreen>
);
export default LockPage;
diff --git a/web/packages/base/components/utils/dialog.tsx b/web/packages/base/components/utils/dialog.tsx
index 9fdb31322a..bf8041d99d 100644
--- a/web/packages/base/components/utils/dialog.tsx
+++ b/web/packages/base/components/utils/dialog.tsx
@@ -65,11 +65,3 @@ export const genericErrorDialogAttributes = () =>
export const genericRetriableErrorDialogAttributes = () =>
errorDialogAttributes(t("generic_error_retry"));
-
-export const logoutDialogAttributes = (
- logout: () => void,
-): MiniDialogAttributes => ({
- message: t("logout_message"),
- continue: { text: t("logout"), color: "critical", action: logout },
- buttonDirection: "row",
-});