π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat(photos):add-to-albums
Aswin Asok7c6ee30101cf
diff --git a/web/apps/photos/src/components/FileListWithViewer.tsx b/web/apps/photos/src/components/FileListWithViewer.tsxindex 3c9fbeb497..0133661a17 100644--- a/web/apps/photos/src/components/FileListWithViewer.tsx+++ b/web/apps/photos/src/components/FileListWithViewer.tsx@@ -52,6 +52,11 @@ export type FileListWithViewerProps = {* progress of user-initiated download, and to cancel it if needed.*/onAddSaveGroup: AddSaveGroup;++ onAddFileToCollection?: (+ file: EnteFile,+ context: { sourceCollectionSummaryID?: number },+ ) => void;} & Pick<FileListProps,| "mode"@@ -121,6 +126,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({onMarkTempDeleted,onSelectCollection,onSelectPerson,+ onAddFileToCollection,}) => {const [openFileViewer, setOpenFileViewer] = useState(false);const [currentIndex, setCurrentIndex] = useState(0);@@ -229,6 +235,8 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({onDownload={handleDownload}onDelete={handleDelete}onSaveEditedImageCopy={handleSaveEditedImageCopy}+ onAddFileToCollection={onAddFileToCollection}+ activeCollectionID={activeCollectionID}/></Container>);diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 2ebb6e4c62..7ce87a1ced 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -166,6 +166,17 @@ const Page: React.FC = () => {);const [isFileViewerOpen, setIsFileViewerOpen] = useState(false);+ /**+ * Tracks a pending file addition operation.+ *+ * Used to temporarily store the file and optional source collection ID+ * when adding a single file to a collection, allowing the operation+ * to be completed after any necessary user interactions (like selecting+ * a target collection).+ */+ const pendingSingleFileAdd = useRef<+ { file: EnteFile; sourceCollectionID?: number } | undefined+ >(undefined);/*** A queue to serialize calls to {@link remoteFilesPull}.*/@@ -711,6 +722,16 @@ const Page: React.FC = () => {const handleAlbumNameSubmit = useCallback(async (name: string) => {const collection = await createAlbum(name);++ if (pendingSingleFileAdd.current) {+ await performCollectionOp(+ "add",+ collection,+ [pendingSingleFileAdd.current.file],+ pendingSingleFileAdd.current.sourceCollectionID,+ );+ }+setPostCreateAlbumOp((postCreateAlbumOp) => {// The function returned by createHandleCollectionOp does its// own progress and error reporting, defer to that.@@ -972,6 +993,65 @@ const Page: React.FC = () => {[],);+ /**+ * Handles adding a single file to a collection by opening a collection selector dialog.+ *+ * @param file - The EnteFile to be added to a collection+ * @param sourceCollectionSummaryID - Optional ID of the source collection where the file currently resides+ *+ * @remarks+ * This function stores the pending file operation, displays a collection selector modal,+ * and handles three scenarios:+ * - User selects an existing collection: adds the file and triggers a remote pull+ * - User creates a new collection: sets up post-create operation and shows album name input+ * - User cancels: clears the pending operation+ *+ * The function shows/hides a loading bar during the add operation and handles errors generically.+ */+ const handleAddSingleFileToCollection = useCallback(+ (file: EnteFile, sourceCollectionSummaryID?: number) => {+ pendingSingleFileAdd.current = {+ file,+ sourceCollectionID: sourceCollectionSummaryID,+ };++ const handleSelect = async (collection: Collection) => {+ try {+ showLoadingBar();+ await performCollectionOp(+ "add",+ collection,+ [file],+ sourceCollectionSummaryID,+ );+ await remotePull({ silent: true });+ } catch (e) {+ onGenericError(e);+ } finally {+ pendingSingleFileAdd.current = undefined;+ hideLoadingBar();+ }+ };++ const handleCreate = () => {+ setPostCreateAlbumOp("add");+ showAlbumNameInput();+ };++ handleOpenCollectionSelector({+ action: "add",+ sourceCollectionSummaryID,+ onSelectCollection: (collection) =>+ void handleSelect(collection),+ onCreateCollection: handleCreate,+ onCancel: () => {+ pendingSingleFileAdd.current = undefined;+ },+ });+ },+ [handleOpenCollectionSelector, remotePull, onGenericError],+ );+const showAppDownloadFooter =state.collectionFiles.length < 30 && !isInSearchMode;@@ -1199,6 +1279,12 @@ const Page: React.FC = () => {onVisualFeedback={handleVisualFeedback}onSelectCollection={handleSelectCollection}onSelectPerson={handleSelectPerson}+ onAddFileToCollection={(file) =>+ handleAddSingleFileToCollection(+ file,+ activeCollectionID,+ )+ }/>)}<Export {...exportVisibilityProps} {...{ collectionNameByID }} />diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsxindex 10fbf06e77..af9e55af7f 100644--- a/web/packages/gallery/components/viewer/FileViewer.tsx+++ b/web/packages/gallery/components/viewer/FileViewer.tsx@@ -1,3 +1,4 @@+import AddIcon from "@mui/icons-material/Add";import ArchiveOutlinedIcon from "@mui/icons-material/ArchiveOutlined";import ContentCopyIcon from "@mui/icons-material/ContentCopy";import DeleteIcon from "@mui/icons-material/Delete";@@ -280,6 +281,15 @@ export type FileViewerProps = ModalVisibilityProps & {* documentation about the parameters.*/onSaveEditedImageCopy?: ImageEditorOverlayProps["onSaveEditedCopy"];++ onAddFileToCollection?: (+ file: EnteFile,+ context: { sourceCollectionSummaryID?: number },+ ) => void;+ /**+ * The ID of the currently active collection, if any (e.g., when viewing an album).+ */+ activeCollectionID?: number;} & Pick<FileInfoProps,"collectionNameByID" | "onSelectCollection" | "onSelectPerson"@@ -314,6 +324,8 @@ export const FileViewer: React.FC<FileViewerProps> = ({onSelectCollection,onSelectPerson,onSaveEditedImageCopy,+ onAddFileToCollection,+ activeCollectionID,}) => {const { onGenericError } = useBaseContext();@@ -935,6 +947,24 @@ export const FileViewer: React.FC<FileViewerProps> = ({)}</MoreMenuItem>)}+ {onAddFileToCollection && (+ <MoreMenuItem+ onClick={() => {+ handleMoreMenuCloseIfNeeded();+ const sourceSummaryID = fileNormalCollectionIDs+ ?.get(activeAnnotatedFile.file.id)+ ?.find((id) => id === activeCollectionID);+ onAddFileToCollection(activeAnnotatedFile.file, {+ sourceCollectionSummaryID: sourceSummaryID,+ });+ }}+ >+ <MoreMenuItemTitle>+ {t("add_to_album")}+ </MoreMenuItemTitle>+ <AddIcon />+ </MoreMenuItem>+ )}{canCopyImage() && (<MoreMenuItem onClick={handleCopyImage}><MoreMenuItemTitle>@@ -944,6 +974,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({<ContentCopyIcon sx={{ "&&": { fontSize: "18px" } }} /></MoreMenuItem>)}+{activeAnnotatedFile.annotation.showEditImage && (<MoreMenuItem onClick={handleEditImage}><MoreMenuItemTitle>{t("edit_image")}</MoreMenuItemTitle>