Skip to content

armgit / ente

Public Imported from GitHub
0

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

attr fin

Manav Rathi5141b04695cc
diff --git a/web/apps/photos/src/components/Collections/CollectionHeader.tsx b/web/apps/photos/src/components/Collections/CollectionHeader.tsx
index 81b710a0b1..31a174b009 100644
--- a/web/apps/photos/src/components/Collections/CollectionHeader.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionHeader.tsx
@@ -624,12 +624,12 @@ const ShareQuickOption: React.FC<ShareQuickOptionProps> = ({
}) => (
<Tooltip
title={
- attributes.has("sharedIncoming")
- ? t("sharing_details")
- : attributes.has("shared")
- ? t("modify_sharing")
- : attributes.has("userFavorites")
- ? t("share_favorites")
+ attributes.has("userFavorites")
+ ? t("share_favorites")
+ : attributes.has("sharedIncoming")
+ ? t("sharing_details")
+ : attributes.has("shared")
+ ? t("modify_sharing")
: t("share_album")
}
>
diff --git a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
index 6b3d7ff905..5ee2715ef9 100644
--- a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
+++ b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
@@ -12,11 +12,9 @@ import {
} from "ente-new/photos/components/gallery/BarImpl";
import { PeopleHeader } from "ente-new/photos/components/gallery/PeopleHeader";
import {
- areOnlySystemCollections,
collectionsSortBy,
- isSystemCollection,
+ haveOnlySystemCollections,
PseudoCollectionID,
- shouldShowOnCollectionBar,
type CollectionsSortBy,
type CollectionSummaries,
} from "ente-new/photos/services/collection-summary";
@@ -114,7 +112,7 @@ export const GalleryBarAndListHeader: React.FC<
const shouldBeHidden = useMemo(
() =>
shouldHide ||
- (areOnlySystemCollections(toShowCollectionSummaries) &&
+ (haveOnlySystemCollections(toShowCollectionSummaries) &&
activeCollectionID === PseudoCollectionID.all),
[shouldHide, toShowCollectionSummaries, activeCollectionID],
);
@@ -203,15 +201,15 @@ export const GalleryBarAndListHeader: React.FC<
onSelectCollectionID={setActiveCollectionID}
onChangeCollectionsSortBy={setCollectionsSortBy}
onShowAllAlbums={showAllAlbums}
- collectionSummaries={sortedCollectionSummaries.filter((x) =>
- shouldShowOnCollectionBar(x.type),
+ collectionSummaries={sortedCollectionSummaries.filter(
+ (cs) => !cs.attributes.has("hideFromCollectionBar"),
)}
/>
<AllAlbums
{...allAlbumsVisibilityProps}
collectionSummaries={sortedCollectionSummaries.filter(
- (x) => !isSystemCollection(x.type),
+ (cs) => !cs.attributes.has("system"),
)}
onSelectCollectionID={setActiveCollectionID}
onChangeCollectionsSortBy={setCollectionsSortBy}
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 0237dad2b5..898932b45f 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -69,7 +69,7 @@ import { usePeopleStateSnapshot } from "ente-new/photos/components/utils/use-sna
import { shouldShowWhatsNew } from "ente-new/photos/services/changelog";
import { createAlbum } from "ente-new/photos/services/collection";
import {
- areOnlySystemCollections,
+ haveOnlySystemCollections,
PseudoCollectionID,
} from "ente-new/photos/services/collection-summary";
import exportService from "ente-new/photos/services/export";
@@ -1006,7 +1006,7 @@ const Page: React.FC = () => {
onRemoteFilesPull={remoteFilesPull}
onUploadFile={(file) => dispatch({ type: "uploadFile", file })}
onShowPlanSelector={showPlanSelector}
- isFirstUpload={areOnlySystemCollections(
+ isFirstUpload={haveOnlySystemCollections(
normalCollectionSummaries,
)}
showSessionExpiredMessage={showSessionExpiredDialog}
diff --git a/web/packages/new/photos/components/CollectionSelector.tsx b/web/packages/new/photos/components/CollectionSelector.tsx
index ee3a031734..78e913b0b6 100644
--- a/web/packages/new/photos/components/CollectionSelector.tsx
+++ b/web/packages/new/photos/components/CollectionSelector.tsx
@@ -122,17 +122,21 @@ export const CollectionSelector: React.FC<CollectionSelectorProps> = ({
}
const collections = [...collectionSummaries.values()]
- .filter(({ id, attributes: csAttributes, type }) => {
- if (id === attributes.relatedCollectionID) {
+ .filter((cs) => {
+ if (cs.id === attributes.relatedCollectionID) {
return false;
} else if (attributes.action == "add") {
- return canAddToCollection(type, csAttributes);
+ return canAddToCollection(cs);
} else if (attributes.action == "upload") {
- return canMoveToCollection(type) || type == "uncategorized";
+ return (
+ canMoveToCollection(cs) || cs.type == "uncategorized"
+ );
} else if (attributes.action == "restore") {
- return canMoveToCollection(type) || type == "uncategorized";
+ return (
+ canMoveToCollection(cs) || cs.type == "uncategorized"
+ );
} else {
- return canMoveToCollection(type);
+ return canMoveToCollection(cs);
}
})
.sort((a, b) => a.name.localeCompare(b.name))
diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.ts
index 429c584c5c..741ffc39d2 100644
--- a/web/packages/new/photos/components/gallery/reducer.ts
+++ b/web/packages/new/photos/components/gallery/reducer.ts
@@ -1299,7 +1299,11 @@ const deriveNormalCollectionSummaries = (
...pseudoCollectionOptionsForFiles([]),
id,
type: "uncategorized",
- attributes: new Set(["uncategorized"]),
+ attributes: new Set([
+ "uncategorized",
+ "system",
+ "hideFromCollectionBar",
+ ]),
name: t("section_uncategorized"),
sortPriority: CollectionSummarySortPriority.system,
});
@@ -1321,7 +1325,7 @@ const deriveNormalCollectionSummaries = (
...pseudoCollectionOptionsForFiles(allSectionFiles),
id: PseudoCollectionID.all,
type: "all",
- attributes: new Set(["all"]),
+ attributes: new Set(["all", "system"]),
name: t("section_all"),
sortPriority: CollectionSummarySortPriority.system,
});
@@ -1334,7 +1338,7 @@ const deriveNormalCollectionSummaries = (
id: PseudoCollectionID.trash,
name: t("section_trash"),
type: "trash",
- attributes: new Set(["trash"]),
+ attributes: new Set(["trash", "system", "hideFromCollectionBar"]),
coverFile: undefined,
sortPriority: CollectionSummarySortPriority.other,
});
@@ -1344,7 +1348,11 @@ const deriveNormalCollectionSummaries = (
id: PseudoCollectionID.archiveItems,
name: t("section_archive"),
type: "archiveItems",
- attributes: new Set(),
+ attributes: new Set([
+ "archiveItems",
+ "system",
+ "hideFromCollectionBar",
+ ]),
coverFile: undefined,
sortPriority: CollectionSummarySortPriority.other,
});
@@ -1388,7 +1396,7 @@ const deriveHiddenCollectionSummaries = (
id: PseudoCollectionID.hiddenItems,
name: t("hidden_items"),
type: "hiddenItems",
- attributes: new Set(["hiddenItems"]),
+ attributes: new Set(["hiddenItems", "system"]),
sortPriority: CollectionSummarySortPriority.system,
});
@@ -1420,15 +1428,30 @@ const createCollectionSummaries = (
? collection.type
: "album";
+ const attributes = new Set<CollectionSummaryAttribute>();
+
let type: CollectionSummaryType;
+ let name = collection.name;
let sortPriority: CollectionSummarySortPriority =
CollectionSummarySortPriority.other;
+
if (collection.owner.id != user.id) {
// This case needs to be the first; the rest assume that they're
// dealing with collections owned by the user.
type = "sharedIncoming";
+ attributes.add("shared");
+ attributes.add("sharedIncoming");
+ attributes.add(
+ collection.sharees.find((s) => s.id == user.id)?.role ==
+ "COLLABORATOR"
+ ? "sharedIncomingCollaborator"
+ : "sharedIncomingViewer",
+ );
} else if (collectionType == "uncategorized") {
type = "uncategorized";
+ name = t("section_uncategorized");
+ attributes.add("system");
+ attributes.add("hideFromCollectionBar");
sortPriority = CollectionSummarySortPriority.system;
} else if (collectionType == "favorites") {
// [Note: User and shared favorites]
@@ -1453,26 +1476,19 @@ const createCollectionSummaries = (
// user's "favorites", everything else is secondary and can be part
// of the `attributes` computed below.
type = "userFavorites";
+ name = t("favorites");
sortPriority = CollectionSummarySortPriority.favorites;
} else if (isDefaultHiddenCollection(collection)) {
type = "defaultHidden";
+ attributes.add("system");
+ attributes.add("hideFromCollectionBar");
} else {
type = collectionType;
}
- // This block of code duplicates the above. Such duplication is needed
- // until type is completely replaced by attributes.
- const attributes = new Set<CollectionSummaryAttribute>();
- if (collection.owner.id != user.id) {
- attributes.add("shared");
- attributes.add("sharedIncoming");
- attributes.add(
- collection.sharees.find((s) => s.id == user.id)?.role ==
- "COLLABORATOR"
- ? "sharedIncomingCollaborator"
- : "sharedIncomingViewer",
- );
- }
+ attributes.add(type);
+ attributes.add(collectionType);
+
if (collection.owner.id == user.id && collection.sharees.length) {
attributes.add("shared");
attributes.add("sharedOutgoing");
@@ -1484,21 +1500,12 @@ const createCollectionSummaries = (
if (isArchivedCollection(collection)) {
attributes.add("archived");
}
- if (isDefaultHiddenCollection(collection)) {
- attributes.add("defaultHidden");
- }
if (collection.magicMetadata?.data.order == CollectionOrder.pinned) {
attributes.add("pinned");
sortPriority = CollectionSummarySortPriority.pinned;
}
- attributes.add(collectionType);
- let name: string;
- if (type == "uncategorized") {
- name = t("section_uncategorized");
- } else if (type == "userFavorites") {
- name = t("favorites");
- } else if (collectionType == "favorites") {
+ if (type == "sharedIncoming" && collectionType == "favorites") {
// See: [Note: User and shared favorites] above.
//
// Use the first letter of the email of the user who shared this
@@ -1511,8 +1518,6 @@ const createCollectionSummaries = (
} else {
name = t("shared_favorites");
}
- } else {
- name = collection.name;
}
const collectionFiles = filesByCollection.get(collection.id);
diff --git a/web/packages/new/photos/services/collection-summary.ts b/web/packages/new/photos/services/collection-summary.ts
index 07a6d1e7d5..a735dc8114 100644
--- a/web/packages/new/photos/services/collection-summary.ts
+++ b/web/packages/new/photos/services/collection-summary.ts
@@ -18,6 +18,8 @@ export type CollectionSummaryAttribute =
| "sharedIncomingViewer"
| "sharedIncomingCollaborator"
| "sharedOnlyViaLink"
+ | "system"
+ | "hideFromCollectionBar"
| "archived"
| "pinned";
@@ -207,44 +209,15 @@ export const CollectionSummarySortPriority = {
export type CollectionSummarySortPriority =
(typeof CollectionSummarySortPriority)[keyof typeof CollectionSummarySortPriority];
-const systemCSTypes = new Set<CollectionSummaryType>([
- "all",
- "archiveItems",
- "trash",
- "uncategorized",
- "hiddenItems",
- "defaultHidden",
-]);
-
-const moveToDisabledCSTypes = new Set<CollectionSummaryType>([
- ...systemCSTypes,
- "sharedIncoming",
-]);
-
-const hideFromCollectionBarCSTypes = new Set<CollectionSummaryType>([
- "trash",
- "archiveItems",
- "uncategorized",
- "defaultHidden",
-]);
-
-export const isSystemCollection = (type: CollectionSummaryType) =>
- systemCSTypes.has(type);
-
-export const areOnlySystemCollections = (
+export const haveOnlySystemCollections = (
collectionSummaries: CollectionSummaries,
) =>
- [...collectionSummaries.values()].every(({ type }) =>
- isSystemCollection(type),
+ [...collectionSummaries.values()].every((cs) =>
+ cs.attributes.has("system"),
);
-export const canAddToCollection = (
- type: CollectionSummaryType,
- attributes: Set<CollectionSummaryAttribute>,
-) => !systemCSTypes.has(type) && !attributes.has("sharedIncomingViewer");
-
-export const canMoveToCollection = (type: CollectionSummaryType) =>
- !moveToDisabledCSTypes.has(type);
+export const canAddToCollection = ({ attributes }: CollectionSummary) =>
+ !attributes.has("system") && !attributes.has("sharedIncomingViewer");
-export const shouldShowOnCollectionBar = (type: CollectionSummaryType) =>
- !hideFromCollectionBarCSTypes.has(type);
+export const canMoveToCollection = ({ attributes }: CollectionSummary) =>
+ !attributes.has("system") && !attributes.has("sharedIncoming");