Skip to content

armgit / ente

Public Imported from GitHub
0

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

attr

Manav Rathi72028ec9d282
diff --git a/web/apps/photos/src/components/Collections/CollectionHeader.tsx b/web/apps/photos/src/components/Collections/CollectionHeader.tsx
index 19231e5b28..4e8c251d09 100644
--- a/web/apps/photos/src/components/Collections/CollectionHeader.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionHeader.tsx
@@ -358,8 +358,7 @@ const CollectionHeaderOptions: React.FC<CollectionHeaderProps> = ({
];
break;
- case "incomingShareViewer":
- case "incomingShareCollaborator":
+ case "sharedIncoming":
menuOptions = [
collectionSummary.attributes.has("archived") ? (
<OverflowMenuOption
@@ -635,11 +634,9 @@ const ShareQuickOption: React.FC<ShareQuickOptionProps> = ({
}) => (
<Tooltip
title={
- collectionSummaryType == "incomingShareViewer" ||
- collectionSummaryType == "incomingShareCollaborator"
+ collectionSummary.attributes.has("sharedIncoming")
? t("sharing_details")
- : collectionSummary.attributes.has("outgoingShare") ||
- collectionSummary.attributes.has("sharedOnlyViaLink")
+ : collectionSummary.attributes.has("shared")
? t("modify_sharing")
: collectionSummaryType == "favorites"
? t("share_favorites")
diff --git a/web/apps/photos/src/components/Collections/CollectionShare.tsx b/web/apps/photos/src/components/Collections/CollectionShare.tsx
index 4559cbd3a0..d973ff7874 100644
--- a/web/apps/photos/src/components/Collections/CollectionShare.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionShare.tsx
@@ -66,10 +66,7 @@ import {
type CreatePublicURLAttributes,
type UpdatePublicURLAttributes,
} from "ente-new/photos/services/collection";
-import type {
- CollectionSummary,
- CollectionSummaryType,
-} from "ente-new/photos/services/collection-summary";
+import type { CollectionSummary } from "ente-new/photos/services/collection-summary";
import { usePhotosAppContext } from "ente-new/photos/types/context";
import { CustomError, parseSharingErrorCodes } from "ente-shared/error";
import { wait } from "ente-utils/promise";
@@ -150,7 +147,7 @@ export const CollectionShare: React.FC<CollectionShareProps> = ({
return <></>;
}
- const { type } = collectionSummary;
+ const isSharedIncoming = collectionSummary.type == "sharedIncoming";
return (
<SidebarDrawer anchor="right" {...{ open, onClose }}>
@@ -159,17 +156,17 @@ export const CollectionShare: React.FC<CollectionShareProps> = ({
onClose={onClose}
onRootClose={onClose}
title={
- type == "incomingShareCollaborator" ||
- type == "incomingShareViewer"
+ isSharedIncoming
? t("sharing_details")
: t("share_album")
}
caption={collection.name}
/>
<Stack sx={{ py: "20px", px: "8px", gap: "24px" }}>
- {type == "incomingShareCollaborator" ||
- type == "incomingShareViewer" ? (
- <SharingDetails {...{ user, collection, type }} />
+ {isSharedIncoming ? (
+ <SharingDetails
+ {...{ user, collection, collectionSummary }}
+ />
) : (
<>
<EmailShare
@@ -199,15 +196,15 @@ export const CollectionShare: React.FC<CollectionShareProps> = ({
);
};
-type SharingDetailsProps = { type: CollectionSummaryType } & Pick<
+type SharingDetailsProps = Pick<
CollectionShareProps,
- "user" | "collection"
+ "user" | "collection" | "collectionSummary"
>;
const SharingDetails: React.FC<SharingDetailsProps> = ({
user,
collection,
- type,
+ collectionSummary,
}) => {
const isOwner = user.id == collection.owner?.id;
@@ -237,7 +234,7 @@ const SharingDetails: React.FC<SharingDetailsProps> = ({
/>
</RowButtonGroup>
</Stack>
- {type == "incomingShareCollaborator" &&
+ {collectionSummary.attributes.has("sharedIncomingCollaborator") &&
collaborators.length > 0 && (
<Stack>
<RowButtonGroupTitle icon={<ModeEditIcon />}>
diff --git a/web/apps/photos/src/components/pages/gallery/SelectedFileOptions.tsx b/web/apps/photos/src/components/pages/gallery/SelectedFileOptions.tsx
index 5a9ce14662..7baa0f80ac 100644
--- a/web/apps/photos/src/components/pages/gallery/SelectedFileOptions.tsx
+++ b/web/apps/photos/src/components/pages/gallery/SelectedFileOptions.tsx
@@ -94,7 +94,7 @@ const SelectedFileOptions = ({
const isUncategorizedCollection =
activeCollectionSummary?.type == "uncategorized";
- const isIncomingSharedCollection =
+ const isSharedIncomingCollection =
activeCollectionSummary?.attributes.has("sharedIncoming");
const addToCollection = () =>
@@ -286,7 +286,7 @@ const SelectedFileOptions = ({
</IconButton>
</Tooltip>
</>
- ) : isIncomingSharedCollection ? (
+ ) : isSharedIncomingCollection ? (
<Tooltip title={t("download")}>
<IconButton onClick={handleFileOp("download")}>
<DownloadIcon />
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 4bfd515381..0237dad2b5 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -1054,12 +1054,9 @@ const Page: React.FC = () => {
setSelected={setSelected}
activeCollectionID={activeCollectionID}
activePersonID={activePerson?.id}
- isInIncomingSharedCollection={
- normalCollectionSummaries.get(activeCollectionID)
- ?.type == "incomingShareCollaborator" ||
- normalCollectionSummaries.get(activeCollectionID)
- ?.type == "incomingShareViewer"
- }
+ isInIncomingSharedCollection={activeCollectionSummary?.attributes.has(
+ "sharedIncoming",
+ )}
isInHiddenSection={barMode == "hidden-albums"}
{...{
favoriteFileIDs,
diff --git a/web/packages/new/photos/components/CollectionSelector.tsx b/web/packages/new/photos/components/CollectionSelector.tsx
index 7ba14014c5..ee3a031734 100644
--- a/web/packages/new/photos/components/CollectionSelector.tsx
+++ b/web/packages/new/photos/components/CollectionSelector.tsx
@@ -122,11 +122,11 @@ export const CollectionSelector: React.FC<CollectionSelectorProps> = ({
}
const collections = [...collectionSummaries.values()]
- .filter(({ id, type }) => {
+ .filter(({ id, attributes: csAttributes, type }) => {
if (id === attributes.relatedCollectionID) {
return false;
} else if (attributes.action == "add") {
- return canAddToCollection(type);
+ return canAddToCollection(type, csAttributes);
} else if (attributes.action == "upload") {
return canMoveToCollection(type) || type == "uncategorized";
} else if (attributes.action == "restore") {
diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.ts
index e0c905b092..b11316254c 100644
--- a/web/packages/new/photos/components/gallery/reducer.ts
+++ b/web/packages/new/photos/components/gallery/reducer.ts
@@ -1424,11 +1424,7 @@ const createCollectionSummaries = (
let sortPriority: CollectionSummarySortPriority =
CollectionSummarySortPriority.other;
if (collection.owner.id != user.id) {
- type =
- collection.sharees.find((s) => s.id == user.id)?.role ==
- "COLLABORATOR"
- ? "incomingShareCollaborator"
- : "incomingShareViewer";
+ type = "sharedIncoming";
} else if (collectionType == "uncategorized") {
type = "uncategorized";
sortPriority = CollectionSummarySortPriority.system;
@@ -1437,9 +1433,9 @@ const createCollectionSummaries = (
//
// "favorites" can be both the user's own favorites, or favorites of
// other users shared with them. However, all of the latter will get
- // typed as "incomingShareViewer" or "incomingShareCollaborator" in
- // the first case above. So if a collection summary has type
- // "favorites", it is guaranteed to be the user's own favorites.
+ // typed as "sharedIncoming" in the first case above. So if a
+ // collection summary has type "favorites", it is guaranteed to be
+ // the user's own favorites.
//
// However, notice that the type of the _collection_ itself is not
// changed, so whenever we're checking the type of the collection
@@ -1453,10 +1449,6 @@ const createCollectionSummaries = (
// of the `attributes` computed below.
type = collectionType;
sortPriority = CollectionSummarySortPriority.favorites;
- } else if (isOutgoingShare(collection, user)) {
- type = "outgoingShare";
- } else if (isSharedOnlyViaLink(collection)) {
- type = "sharedOnlyViaLink";
} else if (isDefaultHiddenCollection(collection)) {
type = "defaultHidden";
} else {
@@ -1472,15 +1464,15 @@ const createCollectionSummaries = (
attributes.add(
collection.sharees.find((s) => s.id == user.id)?.role ==
"COLLABORATOR"
- ? "incomingShareCollaborator"
- : "incomingShareViewer",
+ ? "sharedIncomingCollaborator"
+ : "sharedIncomingViewer",
);
}
- if (isOutgoingShare(collection, user)) {
+ if (collection.owner.id == user.id && collection.sharees.length) {
attributes.add("shared");
- attributes.add("outgoingShare");
+ attributes.add("sharedOutgoing");
}
- if (isSharedOnlyViaLink(collection)) {
+ if (collection.publicURLs.length && !collection.sharees.length) {
attributes.add("shared");
attributes.add("sharedOnlyViaLink");
}
@@ -1579,14 +1571,6 @@ const findCoverFiles = (
return coverFiles;
};
-const isOutgoingShare = (collection: Collection, user: User) =>
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
- collection.owner.id === user.id && collection.sharees?.length > 0;
-
-const isSharedOnlyViaLink = (collection: Collection) =>
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
- collection.publicURLs?.length && !collection.sharees?.length;
-
/**
* Compute the {@link GalleryView} from its dependencies when we are switching
* to (or back to) the "albums" view, or the underlying collections might've
diff --git a/web/packages/new/photos/services/collection-summary.ts b/web/packages/new/photos/services/collection-summary.ts
index 38d7b89687..1bb344299d 100644
--- a/web/packages/new/photos/services/collection-summary.ts
+++ b/web/packages/new/photos/services/collection-summary.ts
@@ -8,10 +8,7 @@ export type CollectionSummaryType =
| "trash"
| "hiddenItems"
| "defaultHidden"
- | "outgoingShare"
- | "incomingShareViewer"
- | "incomingShareCollaborator"
- | "sharedOnlyViaLink";
+ | "sharedIncoming";
export type CollectionSummaryAttribute =
| CollectionType
@@ -21,10 +18,10 @@ export type CollectionSummaryAttribute =
| "hiddenItems"
| "defaultHidden"
| "shared"
- | "outgoingShare"
+ | "sharedOutgoing"
| "sharedIncoming"
- | "incomingShareViewer"
- | "incomingShareCollaborator"
+ | "sharedIncomingViewer"
+ | "sharedIncomingCollaborator"
| "sharedOnlyViaLink"
| "archived"
| "pinned";
@@ -224,14 +221,9 @@ const systemCSTypes = new Set<CollectionSummaryType>([
"defaultHidden",
]);
-const addToDisabledCSTypes = new Set<CollectionSummaryType>([
- ...systemCSTypes,
- "incomingShareViewer",
-]);
-
const moveToDisabledCSTypes = new Set<CollectionSummaryType>([
- ...addToDisabledCSTypes,
- "incomingShareCollaborator",
+ ...systemCSTypes,
+ "sharedIncoming",
]);
const hideFromCollectionBarCSTypes = new Set<CollectionSummaryType>([
@@ -251,8 +243,10 @@ export const areOnlySystemCollections = (
isSystemCollection(type),
);
-export const canAddToCollection = (type: CollectionSummaryType) =>
- !addToDisabledCSTypes.has(type);
+export const canAddToCollection = (
+ type: CollectionSummaryType,
+ attributes: Set<CollectionSummaryAttribute>,
+) => !systemCSTypes.has(type) && !attributes.has("sharedIncomingViewer");
export const canMoveToCollection = (type: CollectionSummaryType) =>
!moveToDisabledCSTypes.has(type);