π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add send-link actions and harden quick-link naming
Anand Baburajan3b828c9459a2
diff --git a/web/apps/photos/src/components/FileList.tsx b/web/apps/photos/src/components/FileList.tsxindex 859e99d1c1..116f4a6327 100644--- a/web/apps/photos/src/components/FileList.tsx+++ b/web/apps/photos/src/components/FileList.tsx@@ -267,7 +267,10 @@ export interface FileListProps {** @param action The action that was triggered.*/- onContextMenuAction?: (action: FileContextAction) => void;+ onContextMenuAction?: (+ action: FileContextAction,+ targetFile?: EnteFile,+ ) => void;/*** Whether to show the "Add Person" action in the context menu.*/@@ -773,9 +776,9 @@ export const FileList: React.FC<FileListProps> = ({const handleContextMenuActionWithTracking = useCallback((action: FileContextAction) => {contextMenuActionTakenRef.current = true;- onContextMenuAction?.(action);+ onContextMenuAction?.(action, contextMenu?.file);},- [onContextMenuAction],+ [onContextMenuAction, contextMenu],);const renderListItem = useCallback(diff --git a/web/apps/photos/src/components/FileListWithViewer.tsx b/web/apps/photos/src/components/FileListWithViewer.tsxindex 09e667514b..6676065f30 100644--- a/web/apps/photos/src/components/FileListWithViewer.tsx+++ b/web/apps/photos/src/components/FileListWithViewer.tsx@@ -127,6 +127,7 @@ export type FileListWithViewerProps = {| "onVisualFeedback"| "onToggleFavorite"| "onFileVisibilityUpdate"+ | "onSendLink"| "onSelectCollection"| "onSelectPerson"| "publicAlbumsCredentials"@@ -179,6 +180,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({onAddSaveGroup,onToggleFavorite,onFileVisibilityUpdate,+ onSendLink,onMarkTempDeleted,onSelectCollection,onSelectPerson,@@ -393,6 +395,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({onVisualFeedback,onToggleFavorite,onFileVisibilityUpdate,+ onSendLink,onSelectCollection,onSelectPerson,publicAlbumsCredentials,diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex f2262610b0..0a89208972 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -1292,6 +1292,40 @@ const Page: React.FC = () => {[],);+ const handleFileViewerSendLink = useCallback(+ async (file: EnteFile) => {+ if (file.ownerID != user?.id) return;++ showLoadingBar();+ try {+ const quickLinkCollection = await createQuickLinkCollection(+ quickLinkNameForFiles([file]),+ );+ await addToCollection(quickLinkCollection, [file]);+ const publicURL = await createPublicURL(quickLinkCollection.id);+ const resolvedURL = await resolveQuickLinkURL(+ publicURL.url,+ quickLinkCollection.key,+ customDomain,+ );+ setPublicLinkToast({ open: true, url: resolvedURL });+ await remotePull({ silent: true });+ } catch (e) {+ onGenericError(e);+ } finally {+ hideLoadingBar();+ }+ },+ [+ user?.id,+ showLoadingBar,+ hideLoadingBar,+ customDomain,+ remotePull,+ onGenericError,+ ],+ );+const handleMarkTempDeleted = useCallback((files: EnteFile[]) => dispatch({ type: "markTempDeleted", files }),[],@@ -1341,12 +1375,16 @@ const Page: React.FC = () => {* and selects an action from the context menu.*/const handleContextMenuAction = useCallback(- (action: FileContextAction) => {+ (action: FileContextAction, targetFile?: EnteFile) => {// The selection should already be set by FileList's handleContextMenu// We just need to invoke the appropriate action handlerswitch (action) {case "sendLink":- createFileOpHandler("sendLink")();+ if (targetFile) {+ void handleFileViewerSendLink(targetFile);+ } else {+ createFileOpHandler("sendLink")();+ }break;case "download":createFileOpHandler("download")();@@ -1500,6 +1538,7 @@ const Page: React.FC = () => {createFileOpHandler,createOnCreateForCollectionOp,createOnSelectForCollectionOp,+ handleFileViewerSendLink,handleOpenCollectionSelector,handleRemoveFilesFromCollection,showMiniDialog,@@ -1841,6 +1880,7 @@ const Page: React.FC = () => {onFileVisibilityUpdate={handleFileViewerFileVisibilityUpdate}+ onSendLink={handleFileViewerSendLink}onMarkTempDeleted={handleMarkTempDeleted}onSetOpenFileViewer={setIsFileViewerOpen}onRemotePull={remotePull}diff --git a/web/apps/photos/src/utils/quick-link.ts b/web/apps/photos/src/utils/quick-link.tsindex 6686199d72..c1c9bc86fa 100644--- a/web/apps/photos/src/utils/quick-link.ts+++ b/web/apps/photos/src/utils/quick-link.ts@@ -43,11 +43,15 @@ const getQuickLinkNameForDateRange = (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),- );+ let minCreationTime = Number.POSITIVE_INFINITY;+ let maxCreationTime = Number.NEGATIVE_INFINITY;+ for (const file of files) {+ const creationTime = fileCreationTime(file);+ if (creationTime < minCreationTime) minCreationTime = creationTime;+ if (creationTime > maxCreationTime) maxCreationTime = creationTime;+ }++ return getQuickLinkNameForDateRange(minCreationTime, maxCreationTime);};const substituteCustomDomainIfNeeded = (diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsxindex 66f842a305..876a4c550b 100644--- a/web/packages/gallery/components/viewer/FileViewer.tsx+++ b/web/packages/gallery/components/viewer/FileViewer.tsx@@ -1,3 +1,5 @@+import { Navigation03Icon } from "@hugeicons/core-free-icons";+import { HugeiconsIcon } from "@hugeicons/react";import AddIcon from "@mui/icons-material/Add";import ArchiveOutlinedIcon from "@mui/icons-material/ArchiveOutlined";import ContentCopyIcon from "@mui/icons-material/ContentCopy";@@ -306,6 +308,12 @@ export type FileViewerProps = ModalVisibilityProps & {* If this is not provided then the download action will not be shown.*/onDownload?: (file: EnteFile) => void;+ /**+ * Called when the given {@link file} should be shared via quick link.+ *+ * If this is not provided then the send link action will not be shown.+ */+ onSendLink?: (file: EnteFile) => void;/*** Called when the given {@link file} should be deleted.*@@ -401,6 +409,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({onToggleFavorite,onFileVisibilityUpdate,onDownload,+ onSendLink,onDelete,onSelectCollection,onSelectPerson,@@ -1343,6 +1352,15 @@ export const FileViewer: React.FC<FileViewerProps> = ({onDownload!(activeAnnotatedFile!.file);};+ // Callback invoked when the send link action is triggered by activating the+ // send link menu item in the more menu.+ //+ // Not memoized since it uses the frequently changing `activeAnnotatedFile`.+ const handleSendLinkMenuAction = () => {+ handleMoreMenuCloseIfNeeded();+ onSendLink!(activeAnnotatedFile!.file);+ };+const handleMore = useCallback((buttonElement: HTMLElement) => setMoreMenuAnchorEl(buttonElement),[],@@ -2614,6 +2632,12 @@ export const FileViewer: React.FC<FileViewerProps> = ({<FileDownloadOutlinedIcon /></MoreMenuItem>)}+ {activeAnnotatedFile.annotation.isOwnFile && onSendLink && (+ <MoreMenuItem onClick={handleSendLinkMenuAction}>+ <MoreMenuItemTitle>Send link</MoreMenuItemTitle>+ <HugeiconsIcon icon={Navigation03Icon} size={20} />+ </MoreMenuItem>+ )}{activeAnnotatedFile.annotation.showDelete && (<MoreMenuItem onClick={handleConfirmDelete}><MoreMenuItemTitle>{t("delete")}</MoreMenuItemTitle>diff --git a/web/packages/gallery/package.json b/web/packages/gallery/package.jsonindex 496542b414..a3346ddd5e 100644--- a/web/packages/gallery/package.json+++ b/web/packages/gallery/package.json@@ -4,6 +4,8 @@"private": true,"dependencies": {"@ffmpeg/ffmpeg": "^0.12.15",+ "@hugeicons/core-free-icons": "^1.1.0",+ "@hugeicons/react": "^1.1.4","bs58": "^6.0.0","ente-base": "*","ente-utils": "*",