π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Sort prio
Manav Rathi903c46bae0e5
diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.tsindex 1c08d1fb7d..7a1ce5e843 100644--- a/web/apps/photos/src/services/collectionService.ts+++ b/web/apps/photos/src/services/collectionService.ts@@ -8,10 +8,7 @@ import {savedUserFavoritesCollection,} from "ente-new/photos/services/collection";import type { CollectionSummary } from "ente-new/photos/services/collection-summary";-import {- CollectionSummaryOrder,- CollectionsSortBy,-} from "ente-new/photos/services/collection-summary";+import { CollectionsSortBy } from "ente-new/photos/services/collection-summary";import { savedCollectionFiles } from "ente-new/photos/services/photos-fdb";import HTTPService from "ente-shared/network/HTTPService";import { getToken } from "ente-shared/storage/localStorage/helpers";@@ -72,12 +69,7 @@ export const sortCollectionSummaries = (return (b.updationTime ?? 0) - (a.updationTime ?? 0);}})- .sort((a, b) => (b.order ?? 0) - (a.order ?? 0))- .sort(- (a, b) =>- CollectionSummaryOrder.get(a.type) -- CollectionSummaryOrder.get(b.type),- );+ .sort((a, b) => b.sortPriority - a.sortPriority);function compareCollectionsLatestFile(first: EnteFile | undefined,diff --git a/web/packages/new/photos/components/CollectionSelector.tsx b/web/packages/new/photos/components/CollectionSelector.tsxindex 3ed1aca2cf..7ba14014c5 100644--- a/web/packages/new/photos/components/CollectionSelector.tsx+++ b/web/packages/new/photos/components/CollectionSelector.tsx@@ -19,7 +19,6 @@ import {import {canAddToCollection,canMoveToCollection,- CollectionSummaryOrder,type CollectionSummaries,type CollectionSummary,} from "ente-new/photos/services/collection-summary";@@ -136,15 +135,8 @@ export const CollectionSelector: React.FC<CollectionSelectorProps> = ({return canMoveToCollection(type);}})- .sort((a, b) => {- return a.name.localeCompare(b.name);- })- .sort((a, b) => {- return (- CollectionSummaryOrder.get(a.type)! -- CollectionSummaryOrder.get(b.type)!- );- });+ .sort((a, b) => a.name.localeCompare(b.name))+ .sort((a, b) => b.sortPriority - a.sortPriority);if (collections.length === 0) {onClose();diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.tsindex 8ff91f4352..024097da2c 100644--- a/web/packages/new/photos/components/gallery/reducer.ts+++ b/web/packages/new/photos/components/gallery/reducer.ts@@ -30,6 +30,7 @@ import {isDefaultHiddenCollection,} from "../../services/collection";import {+ CollectionSummarySortPriority,PseudoCollectionID,type CollectionSummary,type CollectionSummaryType,@@ -1257,6 +1258,7 @@ const deriveNormalCollectionSummaries = (type: "uncategorized",attributes: new Set(["uncategorized"]),name: t("section_uncategorized"),+ sortPriority: CollectionSummarySortPriority.system,});}@@ -1278,6 +1280,7 @@ const deriveNormalCollectionSummaries = (type: "all",attributes: new Set(["all"]),name: t("section_all"),+ sortPriority: CollectionSummarySortPriority.system,});normalCollectionSummaries.set(PseudoCollectionID.trash, {@@ -1290,6 +1293,7 @@ const deriveNormalCollectionSummaries = (type: "trash",attributes: new Set(["trash"]),coverFile: undefined,+ sortPriority: CollectionSummarySortPriority.other,});normalCollectionSummaries.set(PseudoCollectionID.archiveItems, {@@ -1299,6 +1303,7 @@ const deriveNormalCollectionSummaries = (type: "archive",attributes: new Set(["archive"]),coverFile: undefined,+ sortPriority: CollectionSummarySortPriority.other,});return normalCollectionSummaries;@@ -1341,6 +1346,7 @@ const deriveHiddenCollectionSummaries = (name: t("hidden_items"),type: "hiddenItems",attributes: new Set(["hiddenItems"]),+ sortPriority: CollectionSummarySortPriority.system,});return hiddenCollectionSummaries;@@ -1372,12 +1378,17 @@ const createCollectionSummaries = (: "album";let type: CollectionSummaryType;+ let sortPriority: CollectionSummarySortPriority =+ CollectionSummarySortPriority.other;if (collection.owner.id != user.id) {type =collection.sharees.find((s) => s.id == user.id)?.role =="COLLABORATOR"? "incomingShareCollaborator": "incomingShareViewer";+ } else if (collectionType == "uncategorized") {+ type = "uncategorized";+ sortPriority = CollectionSummarySortPriority.system;} else if (collectionType == "favorites") {// [Note: User and shared favorites]//@@ -1398,6 +1409,7 @@ const createCollectionSummaries = (// user's "favorites", everything else is secondary and can be part// of the `attributes` computed below.type = collectionType;+ sortPriority = CollectionSummarySortPriority.favorites;} else if (isOutgoingShare(collection, user)) {type = "outgoingShare";} else if (isSharedOnlyViaLink(collection)) {@@ -1410,6 +1422,7 @@ const createCollectionSummaries = (collection.magicMetadata?.data.order == CollectionOrder.pinned) {type = "pinned";+ sortPriority = CollectionSummarySortPriority.pinned;} else {type = collectionType;}@@ -1485,7 +1498,7 @@ const createCollectionSummaries = (coverFile: coverFiles.get(collection.id),fileCount: collectionFiles?.length ?? 0,updationTime: collection.updationTime,- order: collection.magicMetadata?.data.order ?? 0,+ sortPriority,});}diff --git a/web/packages/new/photos/services/collection-summary.ts b/web/packages/new/photos/services/collection-summary.tsindex 22860b6ad6..d13e16e299 100644--- a/web/packages/new/photos/services/collection-summary.ts+++ b/web/packages/new/photos/services/collection-summary.ts@@ -146,6 +146,7 @@ export interface CollectionSummary {* file that it contains.*/updationTime: number | undefined;+ sortPriority: CollectionSummarySortPriority;order?: number;}@@ -173,28 +174,32 @@ export const collectionsSortBy = [export type CollectionsSortBy = (typeof collectionsSortBy)[number];/**- * An ordering of collection "categories".+ * An orderable set collection "priorities".*- * Within each category, the collections are sorted by the applicable- * {@link CollectionsSortBy}.+ * Collection summaries that need to appear prior to other collection summaries+ * get assigned a "priority", which is an otherwise arbitrary integer that only+ * serves as a sort priority (higher being prior).+ *+ * All collections in a higher category appear together, and before collections+ * in lower categories. Within each priority, the collections are sorted by the+ * applicable {@link CollectionsSortBy}.*/-export const CollectionSummaryOrder = new Map<CollectionSummaryType, number>([- ["all", 0],- ["hiddenItems", 0],- ["uncategorized", 1],- ["favorites", 2],- ["pinned", 3],- ["album", 4],- ["folder", 4],- ["incomingShareViewer", 4],- ["incomingShareCollaborator", 4],- ["outgoingShare", 4],- ["sharedOnlyViaLink", 4],- ["archived", 4],- ["archive", 5],- ["trash", 6],- ["defaultHidden", 7],-]);+export const CollectionSummarySortPriority = {+ /**+ * Currently: "All", "Uncategorized", "Hidden items".+ */+ system: 9,+ favorites: 8,+ pinned: 7,+ other: 0,+} as const;++/**+ * The TypeScript type that restricts the possible values to be one from amongst+ * the {@link CollectionSummarySortCategory} constants.+ */+export type CollectionSummarySortPriority =+ (typeof CollectionSummarySortPriority)[keyof typeof CollectionSummarySortPriority];const systemCSTypes = new Set<CollectionSummaryType>(["all",