From 7b100e8dae56fad8a7da709e08d47cea0d98be05 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Fri, 30 May 2025 16:06:23 +0530 Subject: [PATCH] Use --- web/apps/photos/src/pages/gallery.tsx | 55 ++++++++++++++++----------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx index 586787bc46..7395b1ffa7 100644 --- a/web/apps/photos/src/pages/gallery.tsx +++ b/web/apps/photos/src/pages/gallery.tsx @@ -22,6 +22,7 @@ import { stashRedirect } from "ente-accounts/services/redirect"; import { isSessionInvalid } from "ente-accounts/services/session"; import type { MiniDialogAttributes } from "ente-base/components/MiniDialog"; import { NavbarBase } from "ente-base/components/Navbar"; +import { SingleInputDialog } from "ente-base/components/SingleInputDialog"; import { CenteredRow } from "ente-base/components/containers"; import { TranslucentLoadingOverlay } from "ente-base/components/loaders"; import type { ButtonishProps } from "ente-base/components/mui"; @@ -235,6 +236,9 @@ const Page: React.FC = () => { filesDownloadProgressAttributesList, setFilesDownloadProgressAttributesList, ] = useState([]); + const [postCreateAlbumOp, setPostCreateAlbumOp] = useState< + CollectionOp | undefined + >(undefined); const [openCollectionSelector, setOpenCollectionSelector] = useState(false); const [collectionSelectorAttributes, setCollectionSelectorAttributes] = @@ -254,6 +258,8 @@ const Page: React.FC = () => { show: showAuthenticateUser, props: authenticateUserVisibilityProps, } = useModalVisibility(); + const { show: showAlbumNameInput, props: albumNameInputVisibilityProps } = + useModalVisibility(); const onAuthenticateCallback = useRef<(() => void) | undefined>(undefined); @@ -736,26 +742,22 @@ const Page: React.FC = () => { } }; - const showCreateCollectionModal = (op: CollectionOp) => { - const callback = async (collectionName: string) => { - try { - showLoadingBar(); - const collection = await createAlbum(collectionName); - await collectionOpsHelper(op)(collection); - } catch (e) { - onGenericError(e); - } finally { - hideLoadingBar(); - } - }; - return () => - setCollectionNamerAttributes({ - title: t("new_album"), - buttonText: t("create"), - autoFilledName: "", - callback, - }); - }; + const handleCreateAlbumForOp = useCallback( + (op: CollectionOp) => { + setPostCreateAlbumOp(op); + return showAlbumNameInput; + }, + [showAlbumNameInput], + ); + + const handleAlbumNameSubmit = useCallback( + async (name: string) => { + const collection = await createAlbum(name); + await collectionOpsHelper(postCreateAlbumOp!)(collection); + setPostCreateAlbumOp(undefined); + }, + [postCreateAlbumOp, collectionOpsHelper], + ); const handleSelectSearchOption = ( searchOption: SearchOption | undefined, @@ -965,9 +967,7 @@ const Page: React.FC = () => { { {...authenticateUserVisibilityProps} onAuthenticate={onAuthenticateCallback.current!} /> + );