π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix(AllAlbums):fix-logic-findings
Aswin Asok9e1b8249e28c
diff --git a/desktop/changes/filter-quick-links.md b/desktop/changes/filter-quick-links.mdnew file mode 100644index 0000000000..fd218be487--- /dev/null+++ b/desktop/changes/filter-quick-links.md@@ -0,0 +1 @@+- parity: Added a filter for quick links in All Albums.diff --git a/desktop/changes/filter-received-albums.md b/desktop/changes/filter-received-albums.mdnew file mode 100644index 0000000000..775ec3183c--- /dev/null+++ b/desktop/changes/filter-received-albums.md@@ -0,0 +1 @@+- parity: Added a filter for received albums in All Albums.diff --git a/desktop/changes/filter-shared-albums.md b/desktop/changes/filter-shared-albums.mdnew file mode 100644index 0000000000..f3391258d0--- /dev/null+++ b/desktop/changes/filter-shared-albums.md@@ -0,0 +1 @@+- parity: Added a filter for shared albums in All Albums.diff --git a/desktop/changes/revamped-all-albums-ui.md b/desktop/changes/revamped-all-albums-ui.mdnew file mode 100644index 0000000000..2715150aa5--- /dev/null+++ b/desktop/changes/revamped-all-albums-ui.md@@ -0,0 +1 @@+- ui: Revamped the All Albums UI.diff --git a/web/apps/photos/src/components/Collections/AllAlbums.tsx b/web/apps/photos/src/components/Collections/AllAlbums.tsxindex 9619f71e8a..14e18f96f8 100644--- a/web/apps/photos/src/components/Collections/AllAlbums.tsx+++ b/web/apps/photos/src/components/Collections/AllAlbums.tsx@@ -42,6 +42,7 @@ import {type SxProps,type Theme,} from "@mui/material";+import { ensureLocalUser } from "ente-accounts/services/user";import { FilledIconButton } from "ente-base/components/mui";import { SingleInputDialog } from "ente-base/components/SingleInputDialog";import { useModalVisibility } from "ente-base/components/utils/modal";@@ -52,6 +53,8 @@ import {createAlbum,createHiddenAlbum,deleteCollection,+ isArchivedCollection,+ isDefaultHiddenCollection,} from "ente-new/photos/services/collection";import {isBulkDeletableEmptyAlbum,@@ -109,6 +112,29 @@ const albumFilters: {},];+const matchesAlbumFilter = (+ cs: CollectionSummary,+ albumFilter: AlbumFilter,+) => {+ switch (albumFilter) {+ case "all":+ return true;+ case "shared":+ return (+ !cs.attributes.has("sharedIncoming") &&+ !cs.attributes.has("quickLink") &&+ (cs.attributes.has("sharedOutgoing") ||+ cs.attributes.has("sharedViaLink"))+ );+ case "received":+ return cs.attributes.has("sharedIncoming");+ case "links":+ return cs.attributes.has("quickLink");+ case "empty-albums":+ return isBulkDeletableEmptyAlbum(cs);+ }+};+interface AllAlbums {open: boolean;onClose: () => void;@@ -196,18 +222,15 @@ export const AllAlbums: React.FC<AllAlbums> = ({// A filter with nothing worth showing is not worth a pill.const visibleAlbumFilters = useMemo(() =>- albumFilters.filter(({ value }) => {- switch (value) {- case "links":- return collectionSummaries.some((cs) =>- cs.attributes.has("quickLink"),- );- case "empty-albums":- return hasEnoughEmptyAlbums;- default:- return true;- }- }),+ albumFilters.filter(+ ({ value }) =>+ value == "all" ||+ (value == "empty-albums"+ ? hasEnoughEmptyAlbums+ : collectionSummaries.some((cs) =>+ matchesAlbumFilter(cs, value),+ )),+ ),[collectionSummaries, hasEnoughEmptyAlbums],);@@ -229,35 +252,59 @@ export const AllAlbums: React.FC<AllAlbums> = ({const deleteEmptyAlbums = async (candidateIDs: number[]) => {let failedCount = 0;+ let confirmedCandidateIDs: number[];try {await onRemotePull();- const collections = await savedCollections();- const existingCollectionIDs = new Set(- collections.map((collection) => collection.id),- );- const collectionFiles = await savedCollectionFiles();+ const [collections, collectionFiles] = await Promise.all([+ savedCollections(),+ savedCollectionFiles(),+ ]);+ const candidateIDSet = new Set(candidateIDs);const nonEmptyCollectionIDs = new Set(collectionFiles.map((file) => file.collectionID),);- const confirmedCandidateIDs = candidateIDs.filter(- (id) =>- existingCollectionIDs.has(id) &&- !nonEmptyCollectionIDs.has(id),- );+ const userID = ensureLocalUser().id;+ confirmedCandidateIDs = collections+ .filter(+ (collection) =>+ candidateIDSet.has(collection.id) &&+ !nonEmptyCollectionIDs.has(collection.id) &&+ (collection.type == "album" ||+ collection.type == "folder") &&+ collection.owner.id == userID &&+ !collection.sharees.length &&+ !collection.publicURLs.length &&+ !isArchivedCollection(collection) &&+ !isDefaultHiddenCollection(collection),+ )+ .map((collection) => collection.id);+ } catch {+ showNotification({+ color: "critical",+ title: t("delete_empty_albums_failed", {+ count: candidateIDs.length,+ }),+ });+ return;+ }- for (const id of confirmedCandidateIDs) {- try {- await deleteCollection(id, { keepFiles: true });- } catch {- failedCount++;- }+ if (!confirmedCandidateIDs.length) return;++ for (const id of confirmedCandidateIDs) {+ try {+ await deleteCollection(id, { keepFiles: true });+ } catch {+ failedCount++;}+ }+ let refreshFailed = false;+ try {await onRemotePull();} catch {- failedCount = candidateIDs.length;+ refreshFailed = true;}if (failedCount > 0) {@@ -265,6 +312,11 @@ export const AllAlbums: React.FC<AllAlbums> = ({color: "critical",title: t("delete_empty_albums_failed", { count: failedCount }),});+ } else if (refreshFailed) {+ showNotification({+ color: "critical",+ title: t("delete_empty_albums_refresh_failed"),+ });}};@@ -287,23 +339,9 @@ export const AllAlbums: React.FC<AllAlbums> = ({const albumFilteredCollectionSummaries =isInHiddenSection || albumFilter == "all"? collectionSummaries- : collectionSummaries.filter((cs) => {- switch (albumFilter) {- case "shared":- return (- !cs.attributes.has("sharedIncoming") &&- !cs.attributes.has("quickLink") &&- (cs.attributes.has("sharedOutgoing") ||- cs.attributes.has("sharedViaLink"))- );- case "received":- return cs.attributes.has("sharedIncoming");- case "links":- return cs.attributes.has("quickLink");- case "empty-albums":- return isBulkDeletableEmptyAlbum(cs);- }- });+ : collectionSummaries.filter((cs) =>+ matchesAlbumFilter(cs, albumFilter),+ );if (!searchTerm.trim()) {return albumFilteredCollectionSummaries;@@ -370,7 +408,7 @@ export const AllAlbums: React.FC<AllAlbums> = ({</IconButton></Stack></Stack>- {!isInHiddenSection && (+ {!isInHiddenSection && visibleAlbumFilters.length > 1 && (<ToggleButtonGroupexclusivevalue={albumFilter}diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.jsonindex 7eac826b1e..c8e085b75a 100644--- a/web/packages/base/locales/en-US/translation.json+++ b/web/packages/base/locales/en-US/translation.json@@ -451,6 +451,7 @@"delete_empty_albums_message": "This will delete {{count, number}} empty albums shown in this list.","delete_empty_albums_failed_one": "Could not delete 1 album","delete_empty_albums_failed": "Could not delete {{count, number}} albums",+ "delete_empty_albums_refresh_failed": "The albums were deleted, but the album list could not be refreshed.","delete_photos": "Delete photos","keep_photos": "Keep photos","share_album": "Share album",