Skip to content

armgit / ente

Public Imported from GitHub
0

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

Dedup

Manav Rathi869f3b613890
diff --git a/web/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx b/web/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx
index 587cbd8404..ec62ec87e0 100644
--- a/web/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx
+++ b/web/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx
@@ -1,4 +1,3 @@
-import type { MiniDialogAttributes } from "@/base/components/MiniDialog";
import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";
import { SidebarDrawer } from "@/base/components/mui/SidebarDrawer";
import { Titlebar } from "@/base/components/Titlebar";
@@ -20,6 +19,10 @@ import { type ButtonishProps } from "@/new/photos/components/mui";
import { ChipButton } from "@/new/photos/components/mui/ChipButton";
import { FilePeopleList } from "@/new/photos/components/PeopleList";
import { PhotoDateTimePicker } from "@/new/photos/components/PhotoDateTimePicker";
+import {
+ confirmDisableMapsDialogAttributes,
+ confirmEnableMapsDialogAttributes,
+} from "@/new/photos/components/utils/dialog";
import { fileInfoDrawerZIndex } from "@/new/photos/components/utils/z-index";
import { tagNumericValue, type RawExifTags } from "@/new/photos/services/exif";
import {
@@ -27,6 +30,11 @@ import {
isMLEnabled,
type AnnotatedFaceID,
} from "@/new/photos/services/ml";
+import {
+ settingsSnapshot,
+ settingsSubscribe,
+ updateMapEnabled,
+} from "@/new/photos/services/settings";
import { AppContext } from "@/new/photos/types/context";
import { formattedByteSize } from "@/new/photos/utils/units";
import CopyButton from "@ente/shared/components/CodeBlock/CopyButton";
@@ -55,8 +63,13 @@ import {
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 React, {
+ useContext,
+ useEffect,
+ useMemo,
+ useState,
+ useSyncExternalStore,
+} from "react";
import { changeFileName, updateExistingFilePubMetadata } from "utils/file";
import { PublicCollectionGalleryContext } from "utils/publicCollectionGallery";
import { FileNameEditDialog } from "./FileNameEditDialog";
@@ -100,8 +113,12 @@ export const FileInfo: React.FC<FileInfoProps> = ({
closePhotoViewer,
onSelectPerson,
}) => {
- const { mapEnabled, updateMapEnabled, showMiniDialog } =
- useContext(AppContext);
+ const { mapEnabled } = useSyncExternalStore(
+ settingsSubscribe,
+ settingsSnapshot,
+ );
+
+ const { showMiniDialog } = useContext(AppContext);
const galleryContext = useContext(GalleryContext);
const publicCollectionGalleryContext = useContext(
PublicCollectionGalleryContext,
@@ -369,35 +386,6 @@ const parseExifInfo = (
return info;
};
-const confirmEnableMapsDialogAttributes = (
- onConfirm: () => void,
-): MiniDialogAttributes => ({
- title: t("enable_maps_confirm"),
- message: (
- <Trans
- i18nKey={"enable_maps_confirm_message"}
- 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_confirm"),
- message: <Trans i18nKey={"disable_maps_confirm_message"} />,
- continue: { text: t("disable"), color: "critical", action: onConfirm },
-});
-
const FileInfoSidebar = styled((props: DialogProps) => (
<SidebarDrawer {...props} anchor="right" />
))({
diff --git a/web/apps/photos/src/components/Sidebar/MapSettings.tsx b/web/apps/photos/src/components/Sidebar/MapSettings.tsx
index ef26cf4a1b..44ddf6e7a2 100644
--- a/web/apps/photos/src/components/Sidebar/MapSettings.tsx
+++ b/web/apps/photos/src/components/Sidebar/MapSettings.tsx
@@ -1,38 +1,49 @@
-import { InlineErrorIndicator } from "@/base/components/ErrorIndicator";
import { MenuItemGroup } from "@/base/components/Menu";
-import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton";
-import { LoadingButton } from "@/base/components/mui/LoadingButton";
import {
NestedSidebarDrawer,
SidebarDrawerTitlebar,
type NestedSidebarDrawerVisibilityProps,
} from "@/base/components/mui/SidebarDrawer";
-import { useModalVisibility } from "@/base/components/utils/modal";
-import log from "@/base/log";
-import type { ButtonishProps } from "@/new/photos/components/mui";
+import {
+ confirmDisableMapsDialogAttributes,
+ confirmEnableMapsDialogAttributes,
+} from "@/new/photos/components/utils/dialog";
import {
settingsSnapshot,
settingsSubscribe,
updateMapEnabled,
} from "@/new/photos/services/settings";
+import { useAppContext } from "@/new/photos/types/context";
import { EnteMenuItem } from "@ente/shared/components/Menu/EnteMenuItem";
-import { Box, Link, Stack, Typography } from "@mui/material";
+import { Stack } from "@mui/material";
import { t } from "i18next";
-import React, { useState, useSyncExternalStore } from "react";
-import { Trans } from "react-i18next";
+import React, { useCallback, useSyncExternalStore } from "react";
export const MapSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({
open,
onClose,
onRootClose,
}) => {
+ const { showMiniDialog } = useAppContext();
+
const { mapEnabled } = useSyncExternalStore(
settingsSubscribe,
settingsSnapshot,
);
- const { show: showModifyMap, props: modifyMapVisibilityProps } =
- useModalVisibility();
+ const confirmToggle = useCallback(
+ () =>
+ showMiniDialog(
+ mapEnabled
+ ? confirmDisableMapsDialogAttributes(() =>
+ updateMapEnabled(false),
+ )
+ : confirmEnableMapsDialogAttributes(() =>
+ updateMapEnabled(true),
+ ),
+ ),
+ [showMiniDialog, mapEnabled],
+ );
const handleRootClose = () => {
onClose();
@@ -54,7 +65,7 @@ export const MapSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({
<Stack sx={{ px: "16px", py: "20px" }}>
<MenuItemGroup>
<EnteMenuItem
- onClick={showModifyMap}
+ onClick={confirmToggle}
variant="toggle"
checked={mapEnabled}
label={t("enabled")}
@@ -62,166 +73,6 @@ export const MapSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({
</MenuItemGroup>
</Stack>
</Stack>
- <ModifyMapSettings
- {...modifyMapVisibilityProps}
- onRootClose={handleRootClose}
- mapEnabled={mapEnabled}
- />
- </NestedSidebarDrawer>
- );
-};
-
-const ModifyMapSettings = ({ open, onClose, onRootClose, mapEnabled }) => {
- const [phase, setPhase] = useState<"loading" | "failed" | undefined>();
-
- const wrap = (op: () => Promise<void>) => {
- return () => {
- void (async () => {
- setPhase("loading");
- try {
- await op();
- handleClose();
- } catch (e) {
- log.error(e);
- setPhase("failed");
- }
- })();
- };
- };
-
- const enableMap = wrap(() => updateMapEnabled(true));
- const disableMap = wrap(() => updateMapEnabled(false));
-
- const handleClose = () => {
- setPhase(undefined);
- onClose();
- };
-
- const handleRootClose = () => {
- handleClose();
- onRootClose();
- };
-
- return (
- <NestedSidebarDrawer
- {...{ open }}
- onClose={handleClose}
- onRootClose={handleRootClose}
- >
- {mapEnabled ? (
- <ConfirmDisableMap
- onClose={handleClose}
- onRootClose={handleRootClose}
- onClick={disableMap}
- phase={phase}
- />
- ) : (
- <ConfirmEnableMap
- onClose={handleClose}
- onRootClose={handleRootClose}
- onClick={enableMap}
- phase={phase}
- />
- )}
</NestedSidebarDrawer>
);
};
-
-type ConfirmStepProps = Pick<
- NestedSidebarDrawerVisibilityProps,
- "onClose" | "onRootClose"
-> &
- ButtonishProps & {
- phase: "loading" | "failed" | undefined;
- };
-
-const ConfirmEnableMap: React.FC<ConfirmStepProps> = ({
- onClose,
- onRootClose,
- onClick,
- phase,
-}) => (
- <Stack sx={{ gap: "4px", py: "12px" }}>
- <SidebarDrawerTitlebar
- onClose={onClose}
- onRootClose={onRootClose}
- title={t("enable_maps_confirm")}
- />
- <Stack py={"20px"} px={"8px"} spacing={"32px"}>
- <Box px={"8px"}>
- <Typography component="div" color="text.muted">
- <Trans
- i18nKey={"enable_maps_confirm_message"}
- components={{
- a: (
- <Link
- target="_blank"
- rel="noopener"
- href="https://www.openstreetmap.org/"
- />
- ),
- }}
- />
- </Typography>
- </Box>
- <Stack px={"8px"} spacing={"8px"}>
- {phase == "failed" && <InlineErrorIndicator />}
- <LoadingButton
- loading={phase == "loading"}
- color={"accent"}
- fullWidth
- onClick={onClick}
- >
- {t("enable")}
- </LoadingButton>
- <FocusVisibleButton
- color={"secondary"}
- fullWidth
- onClick={onClose}
- >
- {t("cancel")}
- </FocusVisibleButton>
- </Stack>
- </Stack>
- </Stack>
-);
-
-const ConfirmDisableMap: React.FC<ConfirmStepProps> = ({
- onClose,
- onRootClose,
- onClick,
- phase,
-}) => (
- <Stack sx={{ gap: "4px", py: "12px" }}>
- <SidebarDrawerTitlebar
- onClose={onClose}
- onRootClose={onRootClose}
- title={t("disable_maps_confirm")}
- />
- <Stack py={"20px"} px={"8px"} spacing={"32px"}>
- <Box px={"8px"}>
- <Typography component="div" color="text.muted">
- <Trans i18nKey={"disable_maps_confirm_message"} />
- </Typography>
- </Box>
- <Stack px={"8px"} spacing={"8px"}>
- {phase == "failed" && <InlineErrorIndicator />}
- <LoadingButton
- loading={phase == "loading"}
- color={"critical"}
- fullWidth
- onClick={onClick}
- >
- {t("disable")}
- </LoadingButton>
- <FocusVisibleButton
- color={"secondary"}
- fullWidth
- onClick={onClose}
- >
- {t("cancel")}
- </FocusVisibleButton>
- </Stack>
- </Stack>
- </Stack>
-);
diff --git a/web/packages/new/photos/components/utils/dialog.tsx b/web/packages/new/photos/components/utils/dialog.tsx
new file mode 100644
index 0000000000..4a01bb6d97
--- /dev/null
+++ b/web/packages/new/photos/components/utils/dialog.tsx
@@ -0,0 +1,33 @@
+import type { MiniDialogAttributes } from "@/base/components/MiniDialog";
+import { Link } from "@mui/material";
+import { t } from "i18next";
+import { Trans } from "react-i18next";
+
+export const confirmEnableMapsDialogAttributes = (
+ onConfirm: () => void,
+): MiniDialogAttributes => ({
+ title: t("enable_maps_confirm"),
+ message: (
+ <Trans
+ i18nKey={"enable_maps_confirm_message"}
+ components={{
+ a: (
+ <Link
+ target="_blank"
+ rel="noopener"
+ href="https://www.openstreetmap.org/"
+ />
+ ),
+ }}
+ />
+ ),
+ continue: { text: t("enable"), action: onConfirm },
+});
+
+export const confirmDisableMapsDialogAttributes = (
+ onConfirm: () => void,
+): MiniDialogAttributes => ({
+ title: t("disable_maps_confirm"),
+ message: <Trans i18nKey={"disable_maps_confirm_message"} />,
+ continue: { text: t("disable"), color: "critical", action: onConfirm },
+});