From 3d12812671a887c17a71bada0ad479dd2458a79e Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Fri, 8 Aug 2025 19:19:23 +0530 Subject: [PATCH] Use --- .../Collections/CollectionShare.tsx | 21 ++++++++++++-- web/apps/photos/src/components/Sidebar.tsx | 28 ++----------------- web/packages/new/photos/services/settings.ts | 17 ++++++++++- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/web/apps/photos/src/components/Collections/CollectionShare.tsx b/web/apps/photos/src/components/Collections/CollectionShare.tsx index e22740e1eb..b23778551f 100644 --- a/web/apps/photos/src/components/Collections/CollectionShare.tsx +++ b/web/apps/photos/src/components/Collections/CollectionShare.tsx @@ -58,6 +58,7 @@ import type { import { type CollectionUser } from "ente-media/collection"; import type { RemotePullOpts } from "ente-new/photos/components/gallery"; import { PublicLinkCreated } from "ente-new/photos/components/share/PublicLinkCreated"; +import { useSettingsSnapshot } from "ente-new/photos/components/utils/use-snapshot"; import { avatarTextColor } from "ente-new/photos/services/avatar"; import { createPublicURL, @@ -1105,6 +1106,8 @@ const PublicShare: React.FC = ({ setBlockingLoad, onRemotePull, }) => { + const { customDomain } = useSettingsSnapshot(); + const { show: showPublicLinkCreated, props: publicLinkCreatedVisibilityProps, @@ -1126,11 +1129,15 @@ const PublicShare: React.FC = ({ void appendCollectionKeyToShareURL( publicURL.url, collection.key, - ).then((url) => setResolvedURL(url)); + ).then((url) => + setResolvedURL( + substituteCustomDomainIfNeeded(url, customDomain), + ), + ); } else { setResolvedURL(undefined); } - }, [collection.key, publicURL]); + }, [collection.key, publicURL, customDomain]); const handleCopyLink = () => { if (resolvedURL) void navigator.clipboard.writeText(resolvedURL); @@ -1164,6 +1171,16 @@ const PublicShare: React.FC = ({ ); }; +const substituteCustomDomainIfNeeded = ( + url: string, + customDomain: string | undefined, +) => { + if (!customDomain) return url; + const u = new URL(url); + u.host = customDomain; + return u.href; +}; + type EnablePublicShareOptionsProps = { setPublicURL: (value: PublicURL) => void; onLinkCreated: () => void; diff --git a/web/apps/photos/src/components/Sidebar.tsx b/web/apps/photos/src/components/Sidebar.tsx index 11562c26c0..537299588c 100644 --- a/web/apps/photos/src/components/Sidebar.tsx +++ b/web/apps/photos/src/components/Sidebar.tsx @@ -90,6 +90,7 @@ import { isDevBuildAndUser, pullSettings, updateCFProxyDisabledPreference, + updateCustomDomain, updateMapEnabled, } from "ente-new/photos/services/settings"; import { @@ -987,38 +988,13 @@ const DomainSettings: React.FC = ({ onClose, onRootClose, }) => { - // const { showMiniDialog } = useBaseContext(); - const { customDomain, customDomainCNAME } = useSettingsSnapshot(); - // const handleSubmit = useCallback(async (newName: string) => { - // const newFileName = [newName, extension].filter((x) => !!x).join("."); - // if (newFileName != fileName) { - // await onRename(newFileName); - // } - // onClose(); - // }; - const handleSubmit = useCallback(() => { - // customDomain - // showMiniDialog( - // mapEnabled - // ? confirmDisableMapsDialogAttributes(() => - // updateMapEnabled(false), - // ) - // : confirmEnableMapsDialogAttributes(() => - // updateMapEnabled(true), - // ), - // ), - // [showMiniDialog, mapEnabled], - }, []); - const handleRootClose = () => { onClose(); onRootClose(); }; - // const customDomain = ""; - return ( = ({ submitButtonTitle={ customDomain ? pt("Update") : pt("Set") } - onSubmit={handleSubmit} + onSubmit={updateCustomDomain} /> diff --git a/web/packages/new/photos/services/settings.ts b/web/packages/new/photos/services/settings.ts index fc988edbdb..e09844ce7b 100644 --- a/web/packages/new/photos/services/settings.ts +++ b/web/packages/new/photos/services/settings.ts @@ -8,7 +8,11 @@ import log from "ente-base/log"; import { updateShouldDisableCFUploadProxy } from "ente-gallery/services/upload"; import { nullToUndefined } from "ente-utils/transform"; import { z } from "zod/v4"; -import { fetchFeatureFlags, updateRemoteFlag } from "./remote-store"; +import { + fetchFeatureFlags, + updateRemoteFlag, + updateRemoteValue, +} from "./remote-store"; /** * In-memory flags that tracks various settings. @@ -222,6 +226,17 @@ export const isDevBuildAndUser = () => isDevBuild && isDevUserViaEmail(); const isDevUserViaEmail = () => !!savedPartialLocalUser()?.email?.endsWith("@ente.io"); +/** + * Persist the user's custom domain preference both locally and on remote. + * + * Setting the value to a blank string is equivalent to deleting the custom + * domain value altogether. + */ +export const updateCustomDomain = async (customDomain: string) => { + await updateRemoteValue("customDomain", customDomain); + return pullSettings(); +}; + /** * Persist the user's map enabled preference both locally and on remote. */