Skip to content

armgit / ente

Public Imported from GitHub
0

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

Use

Manav Rathic92bfc1f1cb8
diff --git a/web/apps/photos/src/components/Sidebar/AdvancedSettings.tsx b/web/apps/photos/src/components/Sidebar/AdvancedSettings.tsx
index 2b3e3e6076..24efe9a000 100644
--- a/web/apps/photos/src/components/Sidebar/AdvancedSettings.tsx
+++ b/web/apps/photos/src/components/Sidebar/AdvancedSettings.tsx
@@ -1,14 +1,14 @@
import { EnteDrawer } from "@/base/components/EnteDrawer";
import { MenuItemGroup, MenuSectionTitle } from "@/base/components/Menu";
import { Titlebar } from "@/base/components/Titlebar";
+import type { NestedDrawerVisibilityProps } from "@/base/components/utils/modal";
import { AppContext } from "@/new/photos/types/context";
import { EnteMenuItem } from "@ente/shared/components/Menu/EnteMenuItem";
import { Box, DialogProps, Stack } from "@mui/material";
import { t } from "i18next";
import React, { useContext } from "react";
-import type { SettingsDrawerProps } from "./types";
-export const AdvancedSettings: React.FC<SettingsDrawerProps> = ({
+export const AdvancedSettings: React.FC<NestedDrawerVisibilityProps> = ({
open,
onClose,
onRootClose,
diff --git a/web/apps/photos/src/components/Sidebar/MapSetting.tsx b/web/apps/photos/src/components/Sidebar/MapSetting.tsx
index e8106a1d58..74bcc0257c 100644
--- a/web/apps/photos/src/components/Sidebar/MapSetting.tsx
+++ b/web/apps/photos/src/components/Sidebar/MapSetting.tsx
@@ -16,9 +16,9 @@ import { t } from "i18next";
import React, { useContext, useEffect, useState } from "react";
import { Trans } from "react-i18next";
import { getMapEnabledStatus } from "services/userService";
-import type { SettingsDrawerProps } from "./types";
+import type { NestedDrawerVisibilityProps } from "@/base/components/utils/modal";
-export const MapSettings: React.FC<SettingsDrawerProps> = ({
+export const MapSettings: React.FC<NestedDrawerVisibilityProps> = ({
open,
onClose,
onRootClose,
diff --git a/web/apps/photos/src/components/Sidebar/Preferences.tsx b/web/apps/photos/src/components/Sidebar/Preferences.tsx
index 135e817227..cb0f017e7a 100644
--- a/web/apps/photos/src/components/Sidebar/Preferences.tsx
+++ b/web/apps/photos/src/components/Sidebar/Preferences.tsx
@@ -1,6 +1,7 @@
import { EnteDrawer } from "@/base/components/EnteDrawer";
import { MenuItemGroup, MenuSectionTitle } from "@/base/components/Menu";
import { Titlebar } from "@/base/components/Titlebar";
+import type { NestedDrawerVisibilityProps } from "@/base/components/utils/modal";
import {
getLocaleInUse,
setLocaleInUse,
@@ -18,9 +19,8 @@ import { t } from "i18next";
import React, { useState } from "react";
import { AdvancedSettings } from "./AdvancedSettings";
import { MapSettings } from "./MapSetting";
-import type { SettingsDrawerProps } from "./types";
-export const Preferences: React.FC<SettingsDrawerProps> = ({
+export const Preferences: React.FC<NestedDrawerVisibilityProps> = ({
open,
onClose,
onRootClose,
diff --git a/web/apps/photos/src/components/Sidebar/index.tsx b/web/apps/photos/src/components/Sidebar/index.tsx
index f81dd090a0..c44fe8b77a 100644
--- a/web/apps/photos/src/components/Sidebar/index.tsx
+++ b/web/apps/photos/src/components/Sidebar/index.tsx
@@ -427,7 +427,6 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {
const router = useRouter();
const appContext = useContext(AppContext);
const {
- setDialogMessage,
startLoading,
watchFolderView,
setWatchFolderView,
@@ -437,23 +436,13 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {
const { show: showRecoveryKey, props: recoveryKeyVisibilityProps } =
useModalVisibility();
- const [twoFactorModalView, setTwoFactorModalView] = useState(false);
- const [preferencesView, setPreferencesView] = useState(false);
-
- const openPreferencesOptions = () => setPreferencesView(true);
- const closePreferencesOptions = () => setPreferencesView(false);
-
- const openTwoFactorModal = () => setTwoFactorModalView(true);
- const closeTwoFactorModal = () => setTwoFactorModalView(false);
+ const { show: showTwoFactor, props: twoFactorVisibilityProps } =
+ useModalVisibility();
+ const { show: showPreferences, props: preferencesVisibilityProps } =
+ useModalVisibility();
- const openWatchFolder = () => {
- if (isElectron()) {
- setWatchFolderView(true);
- } else {
- setDialogMessage(getDownloadAppMessage());
- }
- };
- const closeWatchFolder = () => setWatchFolderView(false);
+ const showWatchFolder = () => setWatchFolderView(true);
+ const handleCloseWatchFolder = () => setWatchFolderView(false);
const redirectToChangePasswordPage = () => {
closeSidebar();
@@ -467,12 +456,7 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {
const redirectToAccountsPage = async () => {
closeSidebar();
-
- try {
- await openAccountsManagePasskeysPage();
- } catch (e) {
- log.error("failed to redirect to accounts page", e);
- }
+ await openAccountsManagePasskeysPage();
};
const redirectToDeduplicatePage = () => router.push(PAGES.DEDUPLICATE);
@@ -489,7 +473,7 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {
<>
{isElectron() && (
<EnteMenuItem
- onClick={openWatchFolder}
+ onClick={showWatchFolder}
variant="secondary"
label={t("WATCH_FOLDERS")}
/>
@@ -514,7 +498,7 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {
)}
<EnteMenuItem
variant="secondary"
- onClick={openTwoFactorModal}
+ onClick={showTwoFactor}
label={t("TWO_FACTOR")}
/>
@@ -529,40 +513,36 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {
onClick={redirectToChangePasswordPage}
label={t("CHANGE_PASSWORD")}
/>
-
<EnteMenuItem
variant="secondary"
onClick={redirectToChangeEmailPage}
label={t("CHANGE_EMAIL")}
/>
-
<EnteMenuItem
variant="secondary"
onClick={redirectToDeduplicatePage}
label={t("DEDUPLICATE_FILES")}
/>
-
<EnteMenuItem
variant="secondary"
- onClick={openPreferencesOptions}
+ onClick={showPreferences}
label={t("preferences")}
/>
+
<RecoveryKey {...recoveryKeyVisibilityProps} />
<TwoFactorModal
- show={twoFactorModalView}
- onHide={closeTwoFactorModal}
+ {...twoFactorVisibilityProps}
closeSidebar={closeSidebar}
setLoading={startLoading}
/>
{isElectron() && (
<WatchFolder
open={watchFolderView}
- onClose={closeWatchFolder}
+ onClose={handleCloseWatchFolder}
/>
)}
<Preferences
- open={preferencesView}
- onClose={closePreferencesOptions}
+ {...preferencesVisibilityProps}
onRootClose={closeSidebar}
/>
</>
diff --git a/web/apps/photos/src/components/Sidebar/types.ts b/web/apps/photos/src/components/Sidebar/types.ts
deleted file mode 100644
index e9eebadece..0000000000
--- a/web/apps/photos/src/components/Sidebar/types.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-export interface SettingsDrawerProps {
- /** If `true`, then this drawer page is shown. */
- open: boolean;
- /** Called when the user wants to go back from this drawer page. */
- onClose: () => void;
- /** Called when the user wants to close the entire stack of drawers. */
- onRootClose: () => void;
-}
diff --git a/web/apps/photos/src/components/TwoFactor/Modal/index.tsx b/web/apps/photos/src/components/TwoFactor/Modal/index.tsx
index 248167c2ea..528502bf09 100644
--- a/web/apps/photos/src/components/TwoFactor/Modal/index.tsx
+++ b/web/apps/photos/src/components/TwoFactor/Modal/index.tsx
@@ -3,20 +3,19 @@ import { t } from "i18next";
import { useEffect, useState } from "react";
import { getTwoFactorStatus } from "services/userService";
import { SetLoading } from "types/gallery";
-
import DialogTitleWithCloseButton from "@ente/shared/components/DialogBox/TitleWithCloseButton";
import { Dialog, DialogContent, styled } from "@mui/material";
import TwoFactorModalManageSection from "./Manage";
import TwoFactorModalSetupSection from "./Setup";
+import type { ModalVisibilityProps } from "@/base/components/utils/modal";
const TwoFactorDialog = styled(Dialog)(({ theme }) => ({
"& .MuiDialogContent-root": {
padding: theme.spacing(2, 4),
},
}));
-interface Props {
- show: boolean;
- onHide: () => void;
+
+type Props = ModalVisibilityProps & {
setLoading: SetLoading;
closeSidebar: () => void;
}
@@ -31,7 +30,7 @@ function TwoFactorModal(props: Props) {
}, []);
useEffect(() => {
- if (!props.show) {
+ if (!props.open) {
return;
}
const main = async () => {
@@ -43,16 +42,16 @@ function TwoFactorModal(props: Props) {
});
};
main();
- }, [props.show]);
+ }, [props.open]);
const closeDialog = () => {
- props.onHide();
+ props.onClose();
props.closeSidebar();
};
return (
- <TwoFactorDialog maxWidth="xs" open={props.show} onClose={props.onHide}>
- <DialogTitleWithCloseButton onClose={props.onHide}>
+ <TwoFactorDialog maxWidth="xs" open={props.open} onClose={props.onClose}>
+ <DialogTitleWithCloseButton onClose={props.onClose}>
{t("TWO_FACTOR_AUTHENTICATION")}
</DialogTitleWithCloseButton>
<DialogContent sx={{ px: 4 }}>
diff --git a/web/apps/photos/src/components/WatchFolder.tsx b/web/apps/photos/src/components/WatchFolder.tsx
index 6afdce67f9..4b32600322 100644
--- a/web/apps/photos/src/components/WatchFolder.tsx
+++ b/web/apps/photos/src/components/WatchFolder.tsx
@@ -1,4 +1,5 @@
import { EllipsizedTypography } from "@/base/components/Typography";
+import type { ModalVisibilityProps } from "@/base/components/utils/modal";
import { ensureElectron } from "@/base/electron";
import { basename, dirname } from "@/base/file";
import type { CollectionMapping, FolderWatch } from "@/base/types/ipc";
@@ -34,17 +35,15 @@ import { t } from "i18next";
import React, { useContext, useEffect, useState } from "react";
import watcher from "services/watch";
-interface WatchFolderProps {
- open: boolean;
- onClose: () => void;
-}
-
/**
* View the state of and manage folder watches.
*
* This is the screen that controls that "watch folder" feature in the app.
*/
-export const WatchFolder: React.FC<WatchFolderProps> = ({ open, onClose }) => {
+export const WatchFolder: React.FC<ModalVisibilityProps> = ({
+ open,
+ onClose,
+}) => {
// The folders we are watching
const [watches, setWatches] = useState<FolderWatch[] | undefined>();
// Temporarily stash the folder path while we show a choice dialog to the