Skip to content

armgit / ente

Public Imported from GitHub
0

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

refactor(photos):inline-app-lock-toggle-and-options

Aswin Asok1f001478f9c4
diff --git a/web/apps/photos/src/components/sidebar/accounts/Account.tsx b/web/apps/photos/src/components/sidebar/accounts/Account.tsx
index 0d2543c04f..823cbb819c 100644
--- a/web/apps/photos/src/components/sidebar/accounts/Account.tsx
+++ b/web/apps/photos/src/components/sidebar/accounts/Account.tsx
@@ -327,11 +327,6 @@ export const Account: React.FC<AccountProps> = ({
/>
<RowCard
title={t("two_factor")}
- subtitle={
- twoFactorEnabled === undefined
- ? undefined
- : t(twoFactorEnabled ? "on" : "off")
- }
endIcon={
<EnteSwitch
checked={twoFactorEnabled === true}
diff --git a/web/apps/photos/src/components/sidebar/preferences/AppLockSettings.tsx b/web/apps/photos/src/components/sidebar/preferences/AppLockSettings.tsx
index c187af73ee..7708654259 100644
--- a/web/apps/photos/src/components/sidebar/preferences/AppLockSettings.tsx
+++ b/web/apps/photos/src/components/sidebar/preferences/AppLockSettings.tsx
@@ -1,6 +1,7 @@
import CheckIcon from "@mui/icons-material/Check";
import ChevronRightIcon from "@mui/icons-material/ChevronRight";
import { Stack, TextField, Typography } from "@mui/material";
+import { EnteSwitch } from "ente-base/components/EnteSwitch";
import { TitledMiniDialog } from "ente-base/components/MiniDialog";
import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";
import { ShowHidePasswordInputAdornment } from "ente-base/components/mui/PasswordInputAdornment";
@@ -13,9 +14,9 @@ import {
RowButtonDivider,
RowButtonEndActivityIndicator,
RowButtonGroup,
- RowSwitch,
} from "ente-base/components/RowButton";
import { errorDialogAttributes } from "ente-base/components/utils/dialog";
+import { RowCard } from "ente-base/components/v2/RowCard";
import { useBaseContext } from "ente-base/context";
import log from "ente-base/log";
import { useAppLockSnapshot } from "ente-new/photos/components/utils/use-snapshot";
@@ -33,11 +34,14 @@ import React, { useCallback, useEffect, useRef, useState } from "react";
type DeviceLockEnableOutcome = "success" | "cancelled" | "failed";
-export const AppLockSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({
- open,
- onClose,
- onRootClose,
-}) => {
+export const AppLockSettings: React.FC<
+ Pick<NestedSidebarDrawerVisibilityProps, "onRootClose"> & {
+ onAuthenticateUser: () => Promise<boolean>;
+ }
+> = ({ onAuthenticateUser, onRootClose }) => {
+ const [open, setOpen] = useState(false);
+ const [isAuthenticating, setIsAuthenticating] = useState(false);
+ const onClose = () => setOpen(false);
const state = useAppLockSnapshot();
const isMacOS =
typeof navigator != "undefined" &&
@@ -174,8 +178,50 @@ export const AppLockSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({
setPasswordDialogOpen(false);
}, []);
+ const authenticateAndRun = async (action: () => void) => {
+ if (isAuthenticating) return;
+ setIsAuthenticating(true);
+ try {
+ if (await onAuthenticateUser()) action();
+ } catch (error) {
+ log.error("Failed to authenticate app lock settings", error);
+ } finally {
+ setIsAuthenticating(false);
+ }
+ };
+
return (
<>
+ <RowCard
+ title={t("app_lock")}
+ subtitle={
+ !state.supported ? t("app_lock_not_supported") : undefined
+ }
+ endIcon={
+ <EnteSwitch
+ checked={state.enabled}
+ disabled={
+ !state.supported ||
+ isAuthenticating ||
+ isSettingDeviceLock
+ }
+ onChange={() =>
+ void authenticateAndRun(handleToggleEnabled)
+ }
+ slotProps={{ input: { "aria-label": t("app_lock") } }}
+ />
+ }
+ />
+ {state.enabled && (
+ <Stack sx={{ pl: 2 }}>
+ <RowCard
+ title="App lock options"
+ onClick={() =>
+ void authenticateAndRun(() => setOpen(true))
+ }
+ />
+ </Stack>
+ )}
<TitledNestedSidebarDrawer
maxWidth="440px"
{...{ open, onClose }}
@@ -183,14 +229,6 @@ export const AppLockSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({
title={t("app_lock")}
>
<Stack sx={{ px: "16px", py: "20px", gap: "24px" }}>
- <RowButtonGroup>
- <RowSwitch
- label={t("enabled")}
- checked={state.enabled}
- onClick={handleToggleEnabled}
- />
- </RowButtonGroup>
-
{state.enabled && (
<>
<Stack>
diff --git a/web/apps/photos/src/components/sidebar/preferences/Preferences.tsx b/web/apps/photos/src/components/sidebar/preferences/Preferences.tsx
index 53c7f74a96..7297e264b1 100644
--- a/web/apps/photos/src/components/sidebar/preferences/Preferences.tsx
+++ b/web/apps/photos/src/components/sidebar/preferences/Preferences.tsx
@@ -30,7 +30,6 @@ import {
toggleHLSGeneration,
} from "ente-gallery/services/video";
import {
- useAppLockSnapshot,
useHLSGenerationStatusSnapshot,
useSettingsSnapshot,
} from "ente-new/photos/components/utils/use-snapshot";
@@ -64,43 +63,6 @@ export type PreferencesAction = Extract<
| "preferences.streamableVideos"
>;
-const DesktopAppLockSettings: React.FC<
- { onAuthenticateUser: () => Promise<boolean> } & Pick<
- NestedSidebarDrawerVisibilityProps,
- "onRootClose"
- >
-> = ({ onAuthenticateUser, onRootClose }) => {
- const appLock = useAppLockSnapshot();
- const { show, props } = useModalVisibility();
-
- const handleOpen = useCallback(async () => {
- try {
- if (!(await onAuthenticateUser())) return;
- show();
- } catch (error) {
- log.error("Failed to open app lock settings", error);
- }
- }, [onAuthenticateUser, show]);
-
- return (
- <>
- <RowButtonGroup>
- <RowButton
- label={t("app_lock")}
- caption={
- !appLock.supported
- ? t("app_lock_not_supported")
- : undefined
- }
- disabled={!appLock.supported}
- onClick={handleOpen}
- />
- </RowButtonGroup>
- <AppLockSettings {...props} onRootClose={onRootClose} />
- </>
- );
-};
-
type PreferencesProps = NestedSidebarDrawerVisibilityProps & {
onAuthenticateUser: () => Promise<boolean>;
} & {
@@ -230,7 +192,7 @@ export const Preferences: React.FC<PreferencesProps> = ({
onClick={showAdvancedSettings}
/>
{isDesktop && (
- <DesktopAppLockSettings
+ <AppLockSettings
onAuthenticateUser={onAuthenticateUser}
onRootClose={onRootClose}
/>