Skip to content

armgit / ente

Public Imported from GitHub
0

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

feat(gallery):improve-move-to-shared-album-ux

Aswin Asokc9bcfb7a995e
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index feedc6e8eb..70e676bc8e 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -115,8 +115,10 @@ import {
updateCollectionCover,
} from "ente-new/photos/services/collection";
import {
+ canAddToCollection,
haveOnlySystemCollections,
PseudoCollectionID,
+ type CollectionSummary,
} from "ente-new/photos/services/collection-summary";
import exportService from "ente-new/photos/services/export";
import {
@@ -979,27 +981,26 @@ const Page: React.FC = () => {
};
const createOnSelectForCollectionOp =
- (op: CollectionOp) => (selectedCollection: Collection) => {
- void (async () => {
+ (op: CollectionOp) =>
+ (
+ selectedCollection: Collection,
+ selectedCollectionSummary?: CollectionSummary,
+ ) => {
+ const selectedFiles = getSelectedFiles(selected, filteredFiles);
+ const userFiles = selectedFiles.filter(
+ // If a selection is happening, there must be a user.
+ (f) => f.ownerID == user!.id,
+ );
+ const sourceCollectionID = selected.collectionID;
+
+ const performSelectedCollectionOp = async (
+ op: CollectionOp,
+ filesToProcess: EnteFile[],
+ notifySkippedFiles = false,
+ ) => {
showLoadingBar();
try {
setOpenCollectionSelector(false);
- const selectedFiles = getSelectedFiles(
- selected,
- filteredFiles,
- );
- const userFiles = selectedFiles.filter(
- // If a selection is happening, there must be a user.
- (f) => f.ownerID == user!.id,
- );
- /**
- * The add/copy path can process non-owned files when a
- * shared album requires copying them through the current
- * user's library.
- */
- const filesToProcess =
- op == "add" ? selectedFiles : userFiles;
- const sourceCollectionID = selected.collectionID;
if (filesToProcess.length > 0) {
await performCollectionOp(
op,
@@ -1008,19 +1009,54 @@ const Page: React.FC = () => {
sourceCollectionID,
);
}
- if (
- op != "add" &&
- userFiles.length != selectedFiles.length
- ) {
+ if (notifySkippedFiles) {
showMiniDialog(notifyOthersFilesDialogAttributes());
}
clearSelection();
await remotePull({ silent: true });
- } catch (e) {
- onGenericError(e);
} finally {
hideLoadingBar();
}
+ };
+
+ const shouldAddInsteadOfMove =
+ op == "move" &&
+ !!selectedCollectionSummary &&
+ selectedCollectionSummary.attributes.has("sharedIncoming") &&
+ canAddToCollection(selectedCollectionSummary);
+
+ if (shouldAddInsteadOfMove) {
+ setOpenCollectionSelector(false);
+ showMiniDialog({
+ title: t("cannot_move_to_shared_albums"),
+ message: t("cannot_move_to_shared_albums_message"),
+ continue: {
+ text: t("add"),
+ action: () =>
+ performSelectedCollectionOp("add", selectedFiles),
+ },
+ cancel: t("cancel"),
+ });
+ return;
+ }
+
+ void (async () => {
+ try {
+ /**
+ * The add/copy path can process non-owned files when a
+ * shared album requires copying them through the current
+ * user's library.
+ */
+ const filesToProcess =
+ op == "add" ? selectedFiles : userFiles;
+ await performSelectedCollectionOp(
+ op,
+ filesToProcess,
+ op != "add" && userFiles.length != selectedFiles.length,
+ );
+ } catch (e) {
+ onGenericError(e);
+ }
})();
};
diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.json
index 67d5cf2e3f..d14e23607e 100644
--- a/web/packages/base/locales/en-US/translation.json
+++ b/web/packages/base/locales/en-US/translation.json
@@ -422,6 +422,8 @@
"added_to_album": "Added to album",
"added_to_person": "Added to person",
"move_to_album": "Move to album",
+ "cannot_move_to_shared_albums": "Can't move to shared albums",
+ "cannot_move_to_shared_albums_message": "Items can only be added to shared albums, not moved. Would you like to add instead?",
"unhide_to_album": "Unhide to album",
"restore_to_album": "Restore to album",
"section_all": "All",
diff --git a/web/packages/new/photos/components/CollectionSelector.tsx b/web/packages/new/photos/components/CollectionSelector.tsx
index 77f0d9245e..6b08f5abc3 100644
--- a/web/packages/new/photos/components/CollectionSelector.tsx
+++ b/web/packages/new/photos/components/CollectionSelector.tsx
@@ -83,7 +83,10 @@ export interface CollectionSelectorAttributes {
* Callback invoked when the user selects one the existing collections
* listed in the dialog.
*/
- onSelectCollection: (collection: Collection) => void;
+ onSelectCollection: (
+ collection: Collection,
+ collectionSummary: CollectionSummary,
+ ) => void;
/**
* Callback invoked when the user cancels the collection selection dialog.
*/
@@ -177,8 +180,16 @@ export const CollectionSelector: React.FC<CollectionSelectorProps> = ({
cs.type == "uncategorized") &&
cs.type != "userFavorites"
);
+ } else if (attributes.action == "move") {
+ const canAddInsteadOfMove =
+ cs.attributes.has("sharedIncoming") &&
+ canAddToCollection(cs);
+ return (
+ (canMoveToCollection(cs) || canAddInsteadOfMove) &&
+ cs.type != "userFavorites"
+ );
} else {
- // "move" and "unhide"
+ // "unhide"
return (
canMoveToCollection(cs) && cs.type != "userFavorites"
);
@@ -234,7 +245,13 @@ export const CollectionSelector: React.FC<CollectionSelectorProps> = ({
attributes;
const handleCollectionSummaryClick = async (id: number) => {
- onSelectCollection(await collectionForCollectionSummaryID(id));
+ const collectionSummary = filteredCollections.find((cs) => cs.id == id);
+ if (!collectionSummary) return;
+
+ onSelectCollection(
+ await collectionForCollectionSummaryID(id),
+ collectionSummary,
+ );
onClose();
};
diff --git a/web/packages/new/photos/components/SelectedFileOptions.tsx b/web/packages/new/photos/components/SelectedFileOptions.tsx
index cf75881f4a..f809304311 100644
--- a/web/packages/new/photos/components/SelectedFileOptions.tsx
+++ b/web/packages/new/photos/components/SelectedFileOptions.tsx
@@ -136,7 +136,10 @@ interface SelectedFileOptionsProps {
*/
createOnSelectForCollectionOp: (
op: CollectionOp,
- ) => (selectedCollection: Collection) => void;
+ ) => (
+ selectedCollection: Collection,
+ selectedCollectionSummary?: CollectionSummary,
+ ) => void;
/**
* A function called to obtain a handler for the provided {@link op}.
*