π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add selection send-link quick action with mobile-parity quicklink naming and toast UX
Anand Baburajan6de4933e3ddb
diff --git a/web/apps/photos/src/components/QuickLinkCreatedNotification.tsx b/web/apps/photos/src/components/QuickLinkCreatedNotification.tsxnew file mode 100644index 0000000000..0d89c260ec--- /dev/null+++ b/web/apps/photos/src/components/QuickLinkCreatedNotification.tsx@@ -0,0 +1,95 @@+import CheckIcon from "@mui/icons-material/Check";+import CloseIcon from "@mui/icons-material/Close";+import ContentCopyOutlinedIcon from "@mui/icons-material/ContentCopyOutlined";+import { DialogTitle, Paper, Snackbar, Stack, Typography } from "@mui/material";+import { FilledIconButton } from "ente-base/components/mui";+import { t } from "i18next";+import React, { useEffect, useRef, useState } from "react";++interface QuickLinkCreatedNotificationProps {+ open: boolean;+ onClose: () => void;+ onCopy: () => void;+}++export const QuickLinkCreatedNotification: React.FC<+ QuickLinkCreatedNotificationProps+> = ({ open, onClose, onCopy }) => {+ const [copied, setCopied] = useState(false);+ const closeTimerRef = useRef<number | undefined>(undefined);++ useEffect(() => {+ if (open) {+ // Reset only when opening so the check icon does not flicker back+ // to copy during the close animation.+ setCopied(false);+ return;+ }+ if (closeTimerRef.current) {+ window.clearTimeout(closeTimerRef.current);+ closeTimerRef.current = undefined;+ }+ }, [open]);++ useEffect(+ () => () => {+ if (closeTimerRef.current) {+ window.clearTimeout(closeTimerRef.current);+ }+ },+ [],+ );++ const handleCopy = () => {+ onCopy();+ setCopied(true);+ if (closeTimerRef.current) {+ window.clearTimeout(closeTimerRef.current);+ }+ closeTimerRef.current = window.setTimeout(() => {+ onClose();+ closeTimerRef.current = undefined;+ }, 2500);+ };++ return (+ <Snackbar+ open={open}+ anchorOrigin={{ horizontal: "right", vertical: "bottom" }}+ >+ <Paper sx={{ width: "min(360px, 100svw)" }}>+ <DialogTitle>+ <Stack+ direction="row"+ sx={{+ justifyContent: "space-between",+ alignItems: "center",+ }}+ >+ <Typography variant="h3">+ {t("link_created")}+ </Typography>+ <Stack direction="row" sx={{ gap: 1 }}>+ <FilledIconButton+ aria-label={t("copy_link")}+ onClick={handleCopy}+ >+ {copied ? (+ <CheckIcon sx={{ color: "success.main" }} />+ ) : (+ <ContentCopyOutlinedIcon />+ )}+ </FilledIconButton>+ <FilledIconButton+ aria-label={t("close")}+ onClick={onClose}+ >+ <CloseIcon />+ </FilledIconButton>+ </Stack>+ </Stack>+ </DialogTitle>+ </Paper>+ </Snackbar>+ );+};diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex ecc78727a1..d145cd3bae 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -16,6 +16,7 @@ import { DownloadStatusNotifications } from "components/DownloadStatusNotificatiimport type { FileListHeaderOrFooter } from "components/FileList";import { FileListWithViewer } from "components/FileListWithViewer";import { FixCreationTime } from "components/FixCreationTime";+import { QuickLinkCreatedNotification } from "components/QuickLinkCreatedNotification";import { Sidebar } from "components/Sidebar";import { Upload } from "components/Upload";import { sessionExpiredDialogAttributes } from "ente-accounts/components/utils/dialog";@@ -93,12 +94,16 @@ import { notifyOthersFilesDialogAttributes } from "ente-new/photos/components/utimport { useIsOffline } from "ente-new/photos/components/utils/use-is-offline";import {usePeopleStateSnapshot,+ useSettingsSnapshot,useUserDetailsSnapshot,} from "ente-new/photos/components/utils/use-snapshot";import { shouldShowWhatsNew } from "ente-new/photos/services/changelog";import {+ addToCollection,addToFavoritesCollection,createAlbum,+ createPublicURL,+ createQuickLinkCollection,removeFromCollection,removeFromFavoritesCollection,} from "ente-new/photos/services/collection";@@ -155,6 +160,7 @@ import {performFileOp,type SelectedState,} from "utils/file";+import { quickLinkNameForFiles, resolveQuickLinkURL } from "utils/quick-link";/*** The default view for logged in users.@@ -240,6 +246,7 @@ const Page: React.FC = () => {const [collectionSelectorAttributes, setCollectionSelectorAttributes] =useState<CollectionSelectorAttributes | undefined>();+ const { customDomain } = useSettingsSnapshot();const userDetails = useUserDetailsSnapshot();const peopleState = usePeopleStateSnapshot();@@ -305,6 +312,10 @@ const Page: React.FC = () => {albumId?: number;albumName?: string;}>({ open: false, phase: "processing" });+ const [publicLinkToast, setPublicLinkToast] = useState<{+ open: boolean;+ url?: string;+ }>({ open: false });const onAuthenticateCallback = useRef<(() => void) | undefined>(undefined);const onAuthenticateCancelCallback = useRef<(() => void) | undefined>(@@ -942,6 +953,42 @@ const Page: React.FC = () => {void (async () => {showLoadingBar();try {+ if (op == "sendLink") {+ const selectedFiles = getSelectedFiles(+ selected,+ filteredFiles,+ );+ const ownedSelectedFiles = selectedFiles.filter(+ // There'll be a user if files are being selected.+ (file) => file.ownerID == user!.id,+ );+ if (!ownedSelectedFiles.length) return;+ if (ownedSelectedFiles.length != selectedFiles.length) {+ showMiniDialog(notifyOthersFilesDialogAttributes());+ }++ const quickLinkCollection = await createQuickLinkCollection(+ quickLinkNameForFiles(ownedSelectedFiles),+ );+ await addToCollection(+ quickLinkCollection,+ ownedSelectedFiles,+ );+ const publicURL = await createPublicURL(+ quickLinkCollection.id,+ );+ const resolvedURL = await resolveQuickLinkURL(+ publicURL.url,+ quickLinkCollection.key,+ customDomain,+ );+ setPublicLinkToast({ open: true, url: resolvedURL });++ clearSelection();+ await remotePull({ silent: true });+ return;+ }+// When hiding use all non-hidden files instead of the filtered// files since we want to move all files copies to the hidden// collection.@@ -1827,6 +1874,17 @@ const Page: React.FC = () => {}}onSubmit={handleAlbumNameSubmit}/>+ <QuickLinkCreatedNotification+ open={publicLinkToast.open}+ onCopy={() => {+ if (publicLinkToast.url) {+ void navigator.clipboard.writeText(publicLinkToast.url);+ }+ }}+ onClose={() =>+ setPublicLinkToast((prev) => ({ ...prev, open: false }))+ }+ /><AlbumAddedNotificationopen={addToAlbumProgress.open}onClose={() =>diff --git a/web/apps/photos/src/utils/quick-link.ts b/web/apps/photos/src/utils/quick-link.tsnew file mode 100644index 0000000000..6686199d72--- /dev/null+++ b/web/apps/photos/src/utils/quick-link.ts@@ -0,0 +1,71 @@+import { appendCollectionKeyToShareURL } from "ente-gallery/services/share";+import type { EnteFile } from "ente-media/file";+import { fileCreationTime } from "ente-media/file-metadata";++const shortMonths = [+ "",+ "Jan",+ "Feb",+ "Mar",+ "Apr",+ "May",+ "Jun",+ "Jul",+ "Aug",+ "Sep",+ "Oct",+ "Nov",+ "Dec",+];++/**+ * Mobile parity naming for quick-link collections.+ */+const getQuickLinkNameForDateRange = (+ firstCreationTime: number,+ secondCreationTime: number,+) => {+ const startTime = new Date(firstCreationTime / 1000);+ const endTime = new Date(secondCreationTime / 1000);++ if (startTime.getFullYear() != endTime.getFullYear()) {+ return `${shortMonths[startTime.getMonth() + 1]} ${startTime.getDate()}, ${startTime.getFullYear()} - ${shortMonths[endTime.getMonth() + 1]} ${endTime.getDate()}, ${endTime.getFullYear()}`;+ }+ if (startTime.getMonth() != endTime.getMonth()) {+ return `${shortMonths[startTime.getMonth() + 1]} ${startTime.getDate()} - ${shortMonths[endTime.getMonth() + 1]} ${endTime.getDate()}, ${endTime.getFullYear()}`;+ }+ if (startTime.getDate() != endTime.getDate()) {+ return `${shortMonths[startTime.getMonth() + 1]} ${startTime.getDate()} - ${shortMonths[endTime.getMonth() + 1]} ${endTime.getDate()}, ${endTime.getFullYear()}`;+ }+ return `${shortMonths[endTime.getMonth() + 1]} ${endTime.getDate()}, ${endTime.getFullYear()}`;+};++export const quickLinkNameForFiles = (files: EnteFile[]) => {+ if (!files.length) return "Quick link";++ const creationTimes = files.map((file) => fileCreationTime(file));+ return getQuickLinkNameForDateRange(+ Math.min(...creationTimes),+ Math.max(...creationTimes),+ );+};++const substituteCustomDomainIfNeeded = (+ url: string,+ customDomain: string | undefined,+) => {+ if (!customDomain) return url;+ const u = new URL(url);+ u.host = customDomain;+ return u.href;+};++export const resolveQuickLinkURL = async (+ publicURL: string,+ collectionKey: string,+ customDomain: string | undefined,+) =>+ substituteCustomDomainIfNeeded(+ await appendCollectionKeyToShareURL(publicURL, collectionKey),+ customDomain,+ );diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.jsonindex de0bc02074..f9995a12fb 100644--- a/web/packages/base/locales/en-US/translation.json+++ b/web/packages/base/locales/en-US/translation.json@@ -521,6 +521,7 @@"done": "Done","share_link_section_title": "Or share a link","remove_link": "Remove link",+ "link_created": "Link created","create_public_link": "Create public link","public_link_created": "Public link created","public_link_enabled": "Public link enabled",diff --git a/web/packages/new/photos/components/SelectedFileOptions.tsx b/web/packages/new/photos/components/SelectedFileOptions.tsxindex c402b72a4e..27ff419ece 100644--- a/web/packages/new/photos/components/SelectedFileOptions.tsx+++ b/web/packages/new/photos/components/SelectedFileOptions.tsx@@ -6,6 +6,7 @@ import {Download01Icon,Download05Icon,Location01Icon,+ Navigation03Icon,RemoveCircleIcon,Time04Icon,Unarchive03Icon,@@ -36,6 +37,7 @@ import { t } from "i18next";* Operations on selected files.*/export type FileOp =+ | "sendLink"| "download"| "fixTime"| "favorite"@@ -207,6 +209,7 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({const handleFixTime = createFileOpHandler("fixTime");const handleDownload = createFileOpHandler("download");+ const handleSendLink = createFileOpHandler("sendLink");const handleArchive = createFileOpHandler("archive");@@ -358,6 +361,9 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({{isInSearchMode ? (<>+ {selectedOwnFileCount > 0 && (+ <SendLinkButton onClick={handleSendLink} />+ )}{favoriteActionButton}<FixTimeButton onClick={handleFixTime} />{onEditLocation && selectedOwnFileCount > 0 && (@@ -378,6 +384,9 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({</>) : barMode == "people" ? (<>+ {selectedOwnFileCount > 0 && (+ <SendLinkButton onClick={handleSendLink} />+ )}{favoriteActionButton}<DownloadButton onClick={handleDownload} /><AddToCollectionButton@@ -401,6 +410,9 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({</>) : collectionSummary?.attributes.has("uncategorized") ? (<>+ {selectedOwnFileCount > 0 && (+ <SendLinkButton onClick={handleSendLink} />+ )}<DownloadButton onClick={handleDownload} />{!!onShowAssignPersonDialog && (<AddPersonButton@@ -414,6 +426,9 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({</>) : collectionSummary?.attributes.has("sharedIncoming") ? (<>+ {selectedOwnFileCount > 0 && (+ <SendLinkButton onClick={handleSendLink} />+ )}<DownloadButton onClick={handleDownload} />{!!onShowAssignPersonDialog && (<AddPersonButton@@ -426,6 +441,9 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({</>) : barMode == "hidden-albums" ? (<>+ {selectedOwnFileCount > 0 && (+ <SendLinkButton onClick={handleSendLink} />+ )}<DownloadButton onClick={handleDownload} />{!!onShowAssignPersonDialog && (<AddPersonButton@@ -437,6 +455,9 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({</>) : (<>+ {selectedOwnFileCount > 0 && (+ <SendLinkButton onClick={handleSendLink} />+ )}{collectionSummary?.id !=PseudoCollectionID.archiveItems &&favoriteActionButton}@@ -487,6 +508,14 @@ const DownloadButton: React.FC<ButtonishProps> = ({ onClick }) => (</Tooltip>);+const SendLinkButton: React.FC<ButtonishProps> = ({ onClick }) => (+ <Tooltip title="Send link">+ <IconButton {...{ onClick }} aria-label="Send link">+ <HugeiconsIcon icon={Navigation03Icon} />+ </IconButton>+ </Tooltip>+);+const FavoriteButton: React.FC<ButtonishProps> = ({ onClick }) => (<Tooltip title={t("favorite")}><IconButton {...{ onClick }}>diff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.tsindex 25b5d7c8d9..ed15cdf6f7 100644--- a/web/packages/new/photos/services/collection.ts+++ b/web/packages/new/photos/services/collection.ts@@ -68,6 +68,20 @@ const favoritesCollectionName = "Favorites";export const createAlbum = (albumName: string) =>createCollection(albumName, "album");+/**+ * Create a new quick link collection on remote, and return its local+ * representation.+ *+ * Remote only, does not modify local state.+ *+ * @param name The name to use for the new quick link collection.+ */+export const createQuickLinkCollection = (name: string) =>+ createCollection(name, "album", {+ subType: CollectionSubType.quicklink,+ visibility: ItemVisibility.visible,+ });+/*** Create a new hidden album on remote, and return its local representation.*