π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Switch map toggle to optimistic UI updates
anandbaburajanaa69bd258e26
diff --git a/web/apps/photos/src/components/Sidebar.tsx b/web/apps/photos/src/components/Sidebar.tsxindex 03ba6964a3..6e964db7f6 100644--- a/web/apps/photos/src/components/Sidebar.tsx+++ b/web/apps/photos/src/components/Sidebar.tsx@@ -72,10 +72,6 @@ import { DeleteAccount } from "ente-new/photos/components/DeleteAccount";import { DropdownInput } from "ente-new/photos/components/DropdownInput";import { MLSettings } from "ente-new/photos/components/sidebar/MLSettings";import { TwoFactorSettings } from "ente-new/photos/components/sidebar/TwoFactorSettings";-import {- confirmDisableMapsDialogAttributes,- confirmEnableMapsDialogAttributes,-} from "ente-new/photos/components/utils/dialog-attributes";import { downloadAppDialogAttributes } from "ente-new/photos/components/utils/download";import {useHLSGenerationStatusSnapshot,@@ -1159,23 +1155,15 @@ const MapSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({onClose,onRootClose,}) => {- const { showMiniDialog } = useBaseContext();-const { mapEnabled } = useSettingsSnapshot();+ const [errorMessage, setErrorMessage] = useState<string | undefined>();- const confirmToggle = useCallback(- () =>- showMiniDialog(- mapEnabled- ? confirmDisableMapsDialogAttributes(() =>- updateMapEnabled(false),- )- : confirmEnableMapsDialogAttributes(() =>- updateMapEnabled(true),- ),- ),- [showMiniDialog, mapEnabled],- );+ const handleToggle = useCallback(() => {+ setErrorMessage(undefined);+ void updateMapEnabled(!mapEnabled).catch(() => {+ setErrorMessage(t("generic_error"));+ });+ }, [mapEnabled]);const handleRootClose = () => {onClose();@@ -1193,9 +1181,24 @@ const MapSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({<RowSwitchlabel={t("enabled")}checked={mapEnabled}- onClick={confirmToggle}+ onClick={handleToggle}/></RowButtonGroup>+ <RowButtonGroupHint>+ {t("maps_privacy_notice")}+ </RowButtonGroupHint>+ {errorMessage && (+ <Typography+ variant="small"+ sx={{+ color: "critical.main",+ mt: 0.5,+ textAlign: "center",+ }}+ >+ {errorMessage}+ </Typography>+ )}</Stack></TitledNestedSidebarDrawer>);diff --git a/web/packages/new/photos/services/settings.ts b/web/packages/new/photos/services/settings.tsindex e09844ce7b..f08e82e297 100644--- a/web/packages/new/photos/services/settings.ts+++ b/web/packages/new/photos/services/settings.ts@@ -241,8 +241,18 @@ export const updateCustomDomain = async (customDomain: string) => {* Persist the user's map enabled preference both locally and on remote.*/export const updateMapEnabled = async (isEnabled: boolean) => {- await updateRemoteFlag("mapEnabled", isEnabled);- return pullSettings();+ const previousSnapshot = _state.settingsSnapshot;++ setSettingsSnapshot({ ...previousSnapshot, mapEnabled: isEnabled });++ try {+ await updateRemoteFlag("mapEnabled", isEnabled);+ await pullSettings();+ } catch (e) {+ log.error("Failed to update map setting", e);+ setSettingsSnapshot(previousSnapshot);+ throw e;+ }};const cfProxyDisabledKey = "cfProxyDisabled";