Skip to content

armgit / ente

Public Imported from GitHub
0

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

Fix some

Manav Rathi5c6b0b8679c8
diff --git a/web/apps/photos/src/components/Upload/Uploader.tsx b/web/apps/photos/src/components/Upload/Uploader.tsx
index 9bdbbd60eb..68c1620051 100644
--- a/web/apps/photos/src/components/Upload/Uploader.tsx
+++ b/web/apps/photos/src/components/Upload/Uploader.tsx
@@ -3,7 +3,6 @@ import log from "@/base/log";
import type { CollectionMapping, Electron, ZipItem } from "@/base/types/ipc";
import type { Collection } from "@/media/collection";
import { CollectionMappingChoiceDialog } from "@/new/photos/components/CollectionMappingChoiceDialog";
-import { CollectionSelectorIntent } from "@/new/photos/components/CollectionSelectionDialog";
import { exportMetadataDirectoryName } from "@/new/photos/services/export";
import type {
FileAndPath,
@@ -461,10 +460,10 @@ export default function Uploader({
}
props.setCollectionSelectorAttributes({
+ action: "upload",
callback: uploadFilesToExistingCollection,
onCancel: handleCollectionSelectorCancel,
showNextModal,
- intent: CollectionSelectorIntent.upload,
});
})();
}, [webFiles, desktopFiles, desktopFilePaths, desktopZipItems]);
diff --git a/web/apps/photos/src/components/pages/gallery/SelectedFileOptions.tsx b/web/apps/photos/src/components/pages/gallery/SelectedFileOptions.tsx
index 3e919266c7..cdabbed760 100644
--- a/web/apps/photos/src/components/pages/gallery/SelectedFileOptions.tsx
+++ b/web/apps/photos/src/components/pages/gallery/SelectedFileOptions.tsx
@@ -1,6 +1,5 @@
import { SelectionBar } from "@/base/components/Navbar";
import type { Collection } from "@/media/collection";
-import { CollectionSelectorIntent } from "@/new/photos/components/CollectionSelectionDialog";
import type { GalleryBarMode } from "@/new/photos/components/Gallery/BarImpl";
import { FluidContainer } from "@ente/shared/components/Container";
import ClockIcon from "@mui/icons-material/AccessTime";
@@ -73,9 +72,9 @@ const SelectedFileOptions = ({
const addToCollection = () =>
setCollectionSelectorAttributes({
+ action: "add",
callback: handleCollectionOps(COLLECTION_OPS_TYPE.ADD),
showNextModal: showCreateCollectionModal(COLLECTION_OPS_TYPE.ADD),
- intent: CollectionSelectorIntent.add,
fromCollection:
!isInSearchMode && !peopleMode ? activeCollectionID : undefined,
});
@@ -99,11 +98,11 @@ const SelectedFileOptions = ({
const restoreHandler = () =>
setCollectionSelectorAttributes({
+ action: "restore",
callback: handleCollectionOps(COLLECTION_OPS_TYPE.RESTORE),
showNextModal: showCreateCollectionModal(
COLLECTION_OPS_TYPE.RESTORE,
),
- intent: CollectionSelectorIntent.restore,
});
const removeFromCollectionHandler = () => {
@@ -142,9 +141,9 @@ const SelectedFileOptions = ({
const moveToCollection = () => {
setCollectionSelectorAttributes({
+ action: "move",
callback: handleCollectionOps(COLLECTION_OPS_TYPE.MOVE),
showNextModal: showCreateCollectionModal(COLLECTION_OPS_TYPE.MOVE),
- intent: CollectionSelectorIntent.move,
fromCollection:
!isInSearchMode && !peopleMode ? activeCollectionID : undefined,
});
@@ -152,11 +151,11 @@ const SelectedFileOptions = ({
const unhideToCollection = () => {
setCollectionSelectorAttributes({
+ action: "unhide",
callback: handleCollectionOps(COLLECTION_OPS_TYPE.UNHIDE),
showNextModal: showCreateCollectionModal(
COLLECTION_OPS_TYPE.UNHIDE,
),
- intent: CollectionSelectorIntent.unhide,
});
};
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 90ae18afb4..7f6bf6dcdd 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -1175,8 +1175,8 @@ export default function Gallery() {
<CollectionSelectionDialog
open={collectionSelectorView}
onClose={closeCollectionSelector}
- collectionSummaries={collectionSummaries}
attributes={collectionSelectorAttributes}
+ collectionSummaries={collectionSummaries}
collectionForCollectionID={(id) =>
findCollectionCreatingUncategorizedIfNeeded(
collections,
diff --git a/web/packages/new/photos/components/CollectionSelectionDialog.tsx b/web/packages/new/photos/components/CollectionSelectionDialog.tsx
index 8ef8f58057..255c0e393a 100644
--- a/web/packages/new/photos/components/CollectionSelectionDialog.tsx
+++ b/web/packages/new/photos/components/CollectionSelectionDialog.tsx
@@ -1,3 +1,5 @@
+// TODO
+/* eslint-disable @typescript-eslint/no-non-null-assertion */
import type { Collection } from "@/media/collection";
import {
AllCollectionTile,
@@ -22,25 +24,25 @@ import {
useMediaQuery,
} from "@mui/material";
import { t } from "i18next";
-import { useEffect, useState } from "react";
+import React, { useEffect, useState } from "react";
import type { DialogVisibilityProps } from "./mui/Dialog";
-export enum CollectionSelectorIntent {
- upload,
- add,
- move,
- restore,
- unhide,
-}
+export type CollectionSelectionAction =
+ | "upload"
+ | "add"
+ | "move"
+ | "restore"
+ | "unhide";
export interface CollectionSelectorAttributes {
- callback: (collection: Collection) => void;
- showNextModal: () => void;
/**
- * The {@link intent} modifies the title of the dialog, and also filters
- * the list of collections the user can select from appropriately.
+ * The {@link action} modifies the title of the dialog, and also removes
+ * some system collections that don't might not make sense for that
+ * particular action.
*/
- intent: CollectionSelectorIntent;
+ action: CollectionSelectionAction;
+ callback: (collection: Collection) => void;
+ showNextModal: () => void;
fromCollection?: number;
onCancel?: () => void;
}
@@ -50,7 +52,7 @@ type CollectionSelectionDialogProps = DialogVisibilityProps & {
* The same {@link CollectionSelectionDialog} can be used for different
* purposes by customizing the {@link attributes} prop before opening it.
*/
- attributes: CollectionSelectorAttributes;
+ attributes: CollectionSelectorAttributes | undefined;
/**
* The collections to list.
*/
@@ -89,60 +91,49 @@ export const CollectionSelectionDialog: React.FC<
if (!attributes || !open) {
return;
}
- const main = async () => {
- const collectionsToShow = [...collectionSummaries.values()]
- ?.filter(({ id, type }) => {
- if (id === attributes.fromCollection) {
- return false;
- } else if (
- attributes.intent === CollectionSelectorIntent.add
- ) {
- return canAddToCollection(type);
- } else if (
- attributes.intent === CollectionSelectorIntent.upload
- ) {
- return (
- canMoveToCollection(type) || type == "uncategorized"
- );
- } else if (
- attributes.intent === CollectionSelectorIntent.restore
- ) {
- return (
- canMoveToCollection(type) || type == "uncategorized"
- );
- } else {
- return canMoveToCollection(type);
- }
- })
- .sort((a, b) => {
- return a.name.localeCompare(b.name);
- })
- .sort((a, b) => {
- return (
- CollectionSummaryOrder.get(a.type) -
- CollectionSummaryOrder.get(b.type)
- );
- });
- if (collectionsToShow.length === 0) {
- onClose();
- attributes.showNextModal();
- }
- setCollectionsToShow(collectionsToShow);
- };
- main();
+
+ const collectionsToShow = [...collectionSummaries.values()]
+ .filter(({ id, type }) => {
+ if (id === attributes.fromCollection) {
+ return false;
+ } else if (attributes.action == "add") {
+ return canAddToCollection(type);
+ } else if (attributes.action == "upload") {
+ return canMoveToCollection(type) || type == "uncategorized";
+ } else if (attributes.action == "restore") {
+ return canMoveToCollection(type) || type == "uncategorized";
+ } else {
+ return canMoveToCollection(type);
+ }
+ })
+ .sort((a, b) => {
+ return a.name.localeCompare(b.name);
+ })
+ .sort((a, b) => {
+ return (
+ CollectionSummaryOrder.get(a.type)! -
+ CollectionSummaryOrder.get(b.type)!
+ );
+ });
+ if (collectionsToShow.length === 0) {
+ onClose();
+ attributes.showNextModal();
+ }
+ setCollectionsToShow(collectionsToShow);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [collectionSummaries, attributes, open]);
- if (!collectionsToShow?.length) {
+ if (!collectionsToShow.length) {
return <></>;
}
const handleCollectionClick = async (collectionID: number) => {
- attributes.callback(await collectionForCollectionID(collectionID));
+ attributes?.callback(await collectionForCollectionID(collectionID));
onClose();
};
const onUserTriggeredClose = () => {
- attributes.onCancel?.();
+ attributes?.onCancel?.();
onClose();
};
@@ -154,18 +145,7 @@ export const CollectionSelectionDialog: React.FC<
fullWidth
>
<DialogTitleWithCloseButton onClose={onUserTriggeredClose}>
- {attributes.intent === CollectionSelectorIntent.upload
- ? t("upload_to_album")
- : attributes.intent === CollectionSelectorIntent.add
- ? t("add_to_album")
- : attributes.intent === CollectionSelectorIntent.move
- ? t("move_to_album")
- : attributes.intent === CollectionSelectorIntent.restore
- ? t("restore_to_album")
- : attributes.intent ===
- CollectionSelectorIntent.unhide
- ? t("unhide_to_album")
- : t("select_album")}
+ {dialogTitleForAction(attributes?.action)}
</DialogTitleWithCloseButton>
<DialogContent sx={{ "&&&": { padding: 0 } }}>
<FlexWrapper flexWrap="wrap" gap={"4px"} padding={"16px"}>
@@ -198,6 +178,25 @@ const Dialog_ = styled(Dialog)(({ theme }) => ({
},
}));
+const dialogTitleForAction = (
+ action: CollectionSelectionAction | undefined,
+) => {
+ switch (action) {
+ case "upload":
+ return t("upload_to_album");
+ case "add":
+ return t("add_to_album");
+ case "move":
+ return t("move_to_album");
+ case "restore":
+ return t("restore_to_album");
+ case "unhide":
+ return t("unhide_to_album");
+ case undefined:
+ return t("select_album");
+ }
+};
+
interface CollectionSelectorCardProps {
collectionSummary: CollectionSummary;
onCollectionClick: (collectionID: number) => void;