Skip to content

armgit / ente

Public Imported from GitHub
0

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

Scaffold

Manav Rathi08fcc0228266
diff --git a/web/packages/new/photos/components/Gallery/index.tsx b/web/packages/new/photos/components/Gallery/index.tsx
index 202fbef019..abecac66ad 100644
--- a/web/packages/new/photos/components/Gallery/index.tsx
+++ b/web/packages/new/photos/components/Gallery/index.tsx
@@ -8,7 +8,7 @@
*/
import { pt } from "@/base/i18n";
-import type { Person } from "@/new/photos/services/ml/people";
+import { addPerson, type Person } from "@/new/photos/services/ml/people";
import type { SearchOption } from "@/new/photos/services/search/types";
import { wait } from "@/utils/promise";
import OverflowMenu from "@ente/shared/components/OverflowMenu/menu";
@@ -18,10 +18,11 @@ import EditIcon from "@mui/icons-material/Edit";
import MoreHoriz from "@mui/icons-material/MoreHoriz";
import { Typography } from "@mui/material";
import { t } from "i18next";
-import React from "react";
+import React, { useCallback, useState } from "react";
import type { NewAppContextPhotos } from "../../types/context";
import { SpaceBetweenFlex } from "../mui-custom";
-import { useWrapLoad, useWrapLoadError } from "../use-wrap";
+import { NameInputDialog } from "../NameInputDialog";
+import { useWrapLoadError } from "../use-wrap";
import { GalleryItemsHeaderAdapter, GalleryItemsSummary } from "./ListHeader";
/**
@@ -64,18 +65,30 @@ export const PersonListHeader: React.FC<PeopleListHeaderProps> = ({
// TODO-Cluster
const hasOptions = process.env.NEXT_PUBLIC_ENTE_WIP_CL;
- const wrapLoadError = useWrapLoadError(appContext);
+ const { startLoading, finishLoading } = appContext;
- const wrapLoad = useWrapLoad(appContext);
+ const [openAddNameInput, setOpenAddNameInput] = useState(false);
- const addPerson = wrapLoadError(async () => {
- console.log("add person");
+ const wrapLoadError = useWrapLoadError(appContext);
- await wait(2000);
- throw new Error("test");
- });
+ const addPersonWithName = useCallback(
+ async (name: string) => {
+ startLoading();
+ try {
+ console.log("adding", name);
+ await wait(2000);
+ throw new Error("test");
+ await addPerson(name, { id: "", faces: [] } /* TODO-Cluster*/);
+ } finally {
+ finishLoading();
+ }
+ },
+ [startLoading, finishLoading],
+ );
+
+ const handleAddPerson = () => setOpenAddNameInput(true);
- const rename = wrapLoad(async () => {
+ const rename = wrapLoadError(async () => {
console.log("add person");
await wait(2000);
throw new Error("test");
@@ -99,11 +112,22 @@ export const PersonListHeader: React.FC<PeopleListHeaderProps> = ({
{person.type == "cgroup" ? (
<CGroupPersonOptions onRename={rename} />
) : (
- <ClusterPersonOptions onAddPerson={addPerson} />
+ <ClusterPersonOptions
+ onAddPerson={handleAddPerson}
+ />
)}
</OverflowMenu>
)}
</SpaceBetweenFlex>
+ <NameInputDialog
+ open={openAddNameInput}
+ onClose={() => setOpenAddNameInput(false)}
+ title={pt("Add person")}
+ placeholder={"ENTER_NAME"}
+ initialValue={""}
+ submitButtonTitle={"Add"}
+ onSubmit={addPersonWithName}
+ />
</GalleryItemsHeaderAdapter>
);
};
diff --git a/web/packages/new/photos/components/use-wrap.tsx b/web/packages/new/photos/components/use-wrap.tsx
index 0667afaff6..5495ffef72 100644
--- a/web/packages/new/photos/components/use-wrap.tsx
+++ b/web/packages/new/photos/components/use-wrap.tsx
@@ -37,9 +37,10 @@ export const useWrapLoadError = (
/**
* A variant of {@link useWrapLoadError} that does not handle the error, only
- * does the loading indicator.
+ * does the loading indicator. It also returns the async function directly
+ * instead of voiding the await.
*/
-export const useWrapLoad = (
+export const useWrapLoadAsync = (
/** See: [Note: Migrating components that need the app context]. */
{ startLoading, finishLoading }: NewAppContextPhotos,
) =>
@@ -53,7 +54,7 @@ export const useWrapLoad = (
finishLoading();
}
};
- return (): void => void wrapped();
+ return wrapped;
},
[startLoading, finishLoading],
);