Skip to content

armgit / ente

Public Imported from GitHub
0

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

[web][photos] Show public link details in Links

AswinAsok25aedb247ce9
diff --git a/web/apps/photos/src/components/Collections/CollectionShare.tsx b/web/apps/photos/src/components/Collections/CollectionShare.tsx
index 25dad4c0a9..f93b805708 100644
--- a/web/apps/photos/src/components/Collections/CollectionShare.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionShare.tsx
@@ -3,6 +3,7 @@
import Avatar from "@/components/Avatar";
import type { RemotePullOpts } from "@/components/gallery";
import { PublicLinkCreated } from "@/components/share/PublicLinkCreated";
+import { usePublicLinkURL } from "@/components/utils/use-public-link-url";
import { avatarTextColor } from "@/services/avatar";
import AddIcon from "@mui/icons-material/Add";
import AdminPanelSettingsIcon from "@mui/icons-material/AdminPanelSettings";
@@ -54,7 +55,6 @@ import { isHTTPErrorWithStatus, isMuseumHTTPError } from "ente-base/http";
import { formattedDateTime } from "ente-base/i18n-date";
import log from "ente-base/log";
import { useResolvedContactDisplay } from "ente-contacts";
-import { appendCollectionKeyToShareURL } from "ente-gallery/services/share";
import type {
Collection,
CollectionNewParticipantRole,
@@ -1422,35 +1422,22 @@ const PublicShare: React.FC<PublicShareProps> = ({
props: publicLinkCreatedVisibilityProps,
} = useModalVisibility();
- const [publicURL, setPublicURL] = useState<PublicURL | undefined>(
- undefined,
- );
- const [resolvedURL, setResolvedURL] = useState<string | undefined>(
- undefined,
+ const [shareState, setShareState] = useState({
+ collection,
+ publicURL: collection.publicURLs[0],
+ });
+ const publicURL =
+ shareState.collection === collection
+ ? shareState.publicURL
+ : collection.publicURLs[0];
+ const setPublicURL = (publicURL: PublicURL | undefined) =>
+ setShareState({ collection, publicURL });
+ const { resolvedURL, isLoading, error } = usePublicLinkURL(
+ collection,
+ publicURL,
+ canManage ? customDomain : undefined,
);
- useEffect(() => {
- setPublicURL(collection.publicURLs[0]);
- }, [collection]);
-
- useEffect(() => {
- if (publicURL?.url) {
- void appendCollectionKeyToShareURL(
- publicURL.url,
- collection.key,
- ).then((url) =>
- setResolvedURL(
- substituteCustomDomainIfNeeded(
- url,
- canManage ? customDomain : undefined,
- ),
- ),
- );
- } else {
- setResolvedURL(undefined);
- }
- }, [collection.key, publicURL, customDomain, canManage]);
-
const handleCopyLink = () => {
if (resolvedURL) void navigator.clipboard.writeText(resolvedURL);
};
@@ -1474,6 +1461,14 @@ const PublicShare: React.FC<PublicShareProps> = ({
) : (
<ReadOnlyPublicShare resolvedURL={resolvedURL} />
)
+ ) : publicURL ? (
+ <Typography role="status" color="text.muted">
+ {error
+ ? t("generic_error")
+ : isLoading
+ ? t("loading")
+ : null}
+ </Typography>
) : canManage ? (
<EnablePublicShareOptions
{...{ collection, onRemotePull, setPublicURL }}
@@ -1488,16 +1483,6 @@ const PublicShare: React.FC<PublicShareProps> = ({
);
};
-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/gallery/PublicLinkDetails.tsx b/web/apps/photos/src/components/gallery/PublicLinkDetails.tsx
new file mode 100644
index 0000000000..a892254858
--- /dev/null
+++ b/web/apps/photos/src/components/gallery/PublicLinkDetails.tsx
@@ -0,0 +1,176 @@
+import { usePublicLinkURL } from "@/components/utils/use-public-link-url";
+import { Copy01Icon } from "@hugeicons/core-free-icons";
+import { HugeiconsIcon } from "@hugeicons/react";
+import DoneIcon from "@mui/icons-material/Done";
+import {
+ Box,
+ IconButton,
+ Stack,
+ Tooltip,
+ Typography,
+ styled,
+} from "@mui/material";
+import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";
+import { useClipboardCopy } from "ente-base/components/utils/hooks";
+import type { Collection } from "ente-media/collection";
+import type { EnteFile } from "ente-media/file";
+import { ItemCard } from "ente-new/photos/components/Tiles";
+import { useSettingsSnapshot } from "ente-new/photos/components/utils/use-snapshot";
+import { openURL } from "ente-new/photos/utils/web";
+import { t } from "i18next";
+
+interface PublicLinkDetailsProps {
+ collection: Collection;
+ coverFile?: EnteFile;
+}
+
+export const PublicLinkDetails = ({
+ collection,
+ coverFile,
+}: PublicLinkDetailsProps) => {
+ const { customDomain } = useSettingsSnapshot();
+ // Links navigation only contains the user's own quick links.
+ const { resolvedURL, isLoading, error } = usePublicLinkURL(
+ collection,
+ collection.publicURLs[0],
+ customDomain,
+ );
+
+ return (
+ <Box
+ sx={{
+ flex: 1,
+ minHeight: 0,
+ overflow: "auto",
+ p: { xs: "24px", md: "36px" },
+ }}
+ >
+ <Stack sx={{ width: "100%", maxWidth: 364, gap: "14px" }}>
+ <Box role="img" aria-label={collection.name}>
+ <ItemCard
+ key={`${collection.id}-${coverFile?.id ?? "empty"}`}
+ TileComponent={Cover}
+ coverFile={coverFile}
+ />
+ </Box>
+ <Stack
+ direction="row"
+ sx={(theme) => ({
+ alignItems: "center",
+ gap: "8px",
+ height: 52,
+ px: "16px",
+ borderRadius: "16px",
+ bgcolor: "fill.faint",
+ ...theme.applyStyles("light", { bgcolor: "#F4F4F4" }),
+ })}
+ >
+ <Typography
+ component="span"
+ title={resolvedURL}
+ aria-live="polite"
+ sx={{
+ flex: 1,
+ minWidth: 0,
+ fontSize: 14,
+ fontWeight: 500,
+ lineHeight: "20px",
+ letterSpacing: 0,
+ overflow: "hidden",
+ textOverflow: "ellipsis",
+ whiteSpace: "nowrap",
+ }}
+ >
+ {resolvedURL?.replace(/^https?:\/\//, "") ??
+ (error
+ ? t("generic_error")
+ : isLoading
+ ? t("loading")
+ : null)}
+ </Typography>
+ <CopyLinkButton
+ key={resolvedURL ?? "pending"}
+ url={resolvedURL}
+ />
+ </Stack>
+ <Typography
+ sx={{
+ color: "text.muted",
+ fontSize: "11.5px",
+ fontWeight: 400,
+ lineHeight: 1.45,
+ letterSpacing: 0,
+ }}
+ >
+ {t("public_link_description")}
+ </Typography>
+ <FocusVisibleButton
+ color="secondary"
+ fullWidth
+ disabled={!resolvedURL}
+ onClick={() => {
+ if (resolvedURL) openURL(resolvedURL);
+ }}
+ sx={(theme) => ({
+ height: 52,
+ px: "24px",
+ py: "14px",
+ borderRadius: "20px",
+ fontSize: 14,
+ fontWeight: 500,
+ lineHeight: "20px",
+ letterSpacing: 0,
+ ...theme.applyStyles("light", {
+ bgcolor: "#EAEAEA",
+ "&:hover": { bgcolor: "secondary.hover" },
+ }),
+ })}
+ >
+ {t("open_album")}
+ </FocusVisibleButton>
+ </Stack>
+ </Box>
+ );
+};
+
+const CopyLinkButton = ({ url }: { url: string | undefined }) => {
+ const [copied, copy] = useClipboardCopy(url ?? "");
+ const label = t(copied ? "copied" : "copy_link");
+ return (
+ <Tooltip title={label}>
+ <span>
+ <IconButton
+ aria-label={label}
+ disabled={!url}
+ onClick={copy}
+ sx={{
+ width: 36,
+ height: 36,
+ p: 0,
+ mr: "-6px",
+ borderRadius: "8px",
+ }}
+ >
+ {copied ? (
+ <DoneIcon sx={{ fontSize: 24, color: "accent.main" }} />
+ ) : (
+ <HugeiconsIcon
+ icon={Copy01Icon}
+ size={24}
+ strokeWidth={1.5}
+ />
+ )}
+ </IconButton>
+ </span>
+ </Tooltip>
+ );
+};
+
+const Cover = styled("div")({
+ position: "relative",
+ width: "100%",
+ aspectRatio: "1",
+ borderRadius: 24,
+ overflow: "hidden",
+ "& > img": { width: "100%", height: "100%", objectFit: "cover" },
+});
diff --git a/web/apps/photos/src/components/utils/use-public-link-url.ts b/web/apps/photos/src/components/utils/use-public-link-url.ts
new file mode 100644
index 0000000000..950ebaecf5
--- /dev/null
+++ b/web/apps/photos/src/components/utils/use-public-link-url.ts
@@ -0,0 +1,50 @@
+import { appendCollectionKeyToShareURL } from "ente-gallery/services/share";
+import type { Collection, PublicURL } from "ente-media/collection";
+import { useEffect, useMemo, useState } from "react";
+
+/** Resolve a share URL without exposing a previous selection's URL while loading. */
+export const usePublicLinkURL = (
+ collection: Pick<Collection, "id" | "key">,
+ publicURL: PublicURL | undefined,
+ customDomain?: string,
+) => {
+ const url = publicURL?.url;
+ const { id, key } = collection;
+ const input = useMemo(
+ () => ({ id, key, url, customDomain }),
+ [id, key, url, customDomain],
+ );
+ const [result, setResult] = useState<
+ | { input: typeof input; resolvedURL?: string; error?: unknown }
+ | undefined
+ >();
+
+ useEffect(() => {
+ if (!input.url) return;
+ let cancelled = false;
+
+ void appendCollectionKeyToShareURL(input.url, input.key)
+ .then((url) => {
+ if (input.customDomain) {
+ const customURL = new URL(url);
+ customURL.host = input.customDomain;
+ url = customURL.href;
+ }
+ if (!cancelled) setResult({ input, resolvedURL: url });
+ })
+ .catch((error: unknown) => {
+ if (!cancelled) setResult({ input, error });
+ });
+
+ return () => {
+ cancelled = true;
+ };
+ }, [input]);
+
+ const currentResult = result?.input === input ? result : undefined;
+ return {
+ resolvedURL: currentResult?.resolvedURL,
+ isLoading: Boolean(url) && !currentResult,
+ error: currentResult?.error,
+ };
+};
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index c2a8dfb850..919b7a5845 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -39,6 +39,7 @@ import { DuplicatesView } from "@/components/gallery/DuplicatesView";
import { LargeFilesView } from "@/components/gallery/LargeFilesView";
import { PeopleOverview } from "@/components/gallery/PeopleOverview";
import { PhotosNavigationShell } from "@/components/gallery/PhotosNavigationShell";
+import { PublicLinkDetails } from "@/components/gallery/PublicLinkDetails";
import {
albumShortcutCollectionID,
findCollectionCreatingIfNeeded,
@@ -79,7 +80,7 @@ import { ensureLocalUser } from "ente-accounts/services/user";
import { isDesktop } from "ente-base/app";
import type { MiniDialogAttributes } from "ente-base/components/MiniDialog";
import { SingleInputDialog } from "ente-base/components/SingleInputDialog";
-import { CenteredFill, CenteredRow } from "ente-base/components/containers";
+import { CenteredRow } from "ente-base/components/containers";
import { TranslucentLoadingOverlay } from "ente-base/components/loaders";
import { errorDialogAttributes } from "ente-base/components/utils/dialog";
import { useModalVisibility } from "ente-base/components/utils/modal";
@@ -488,6 +489,7 @@ const Page: React.FC = () => {
),
[quickLinks, normalCollectionSummaries],
);
+ const selectedLink = quickLinks.find(({ id }) => id === selectedLinkID);
const activePerson =
state.view?.type == "people" ? state.view.activePerson : undefined;
const activePersonID = activePerson?.id;
@@ -2241,11 +2243,15 @@ const Page: React.FC = () => {
) : cleanupView === "large-files" ? (
<LargeFilesView onRemoteFilesPull={remoteFilesPull} />
) : !isInSearchMode && barMode == "links" ? (
- <CenteredFill>
- <Typography variant="h3">
- {t("nothing_here")}
- </Typography>
- </CenteredFill>
+ selectedLink ? (
+ <PublicLinkDetails
+ key={selectedLink.id}
+ collection={selectedLink}
+ coverFile={
+ linkSummaries.get(selectedLink.id)?.coverFile
+ }
+ />
+ ) : null
) : !isInSearchMode &&
!isFirstLoad &&
!state.collectionFiles.length &&
diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.json
index cd72414bf2..609ad7506b 100644
--- a/web/packages/base/locales/en-US/translation.json
+++ b/web/packages/base/locales/en-US/translation.json
@@ -748,6 +748,8 @@
"share_link_section_title": "Or share a link",
"remove_link": "Remove link",
"link_created": "Link created",
+ "public_link_description": "Anyone with this link can open the album without an Ente account.",
+ "open_album": "Open album",
"create_public_link": "Create public link",
"public_link_created": "Public link created",
"public_link_enabled": "Public link enabled",