From e7461d2c0bd551887da03bd322a673bdd764b78e Mon Sep 17 00:00:00 2001 From: Mary Hipp Date: Fri, 20 Sep 2024 15:17:00 -0400 Subject: [PATCH] track whether hook fn has already been run --- .../src/app/hooks/useHandleStudioDestination.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/invokeai/frontend/web/src/app/hooks/useHandleStudioDestination.ts b/invokeai/frontend/web/src/app/hooks/useHandleStudioDestination.ts index 76ddd70425..75b18290bc 100644 --- a/invokeai/frontend/web/src/app/hooks/useHandleStudioDestination.ts +++ b/invokeai/frontend/web/src/app/hooks/useHandleStudioDestination.ts @@ -4,7 +4,7 @@ import { useImageViewer } from 'features/gallery/components/ImageViewer/useImage import { $isMenuOpen } from 'features/stylePresets/store/isMenuOpen'; import { setActiveTab } from 'features/ui/store/uiSlice'; import { useWorkflowLibraryModal } from 'features/workflowLibrary/store/isWorkflowLibraryModalOpen'; -import { useCallback } from 'react'; +import { useCallback, useState } from 'react'; export type StudioDestination = | 'generation' @@ -16,22 +16,26 @@ export type StudioDestination = export const useHandleStudioDestination = () => { const dispatch = useAppDispatch(); - const imageViewer = useImageViewer(); + const { open: imageViewerOpen, close: imageViewerClose } = useImageViewer(); + const [initialized, setInitialized] = useState(false); const workflowLibraryModal = useWorkflowLibraryModal(); const handleStudioDestination = useCallback( (destination: StudioDestination) => { + if (initialized) { + return; + } switch (destination) { case 'generation': dispatch(setActiveTab('canvas')); dispatch(settingsSendToCanvasChanged(false)); - imageViewer.open(); + imageViewerOpen(); break; case 'canvas': dispatch(setActiveTab('canvas')); dispatch(settingsSendToCanvasChanged(true)); - imageViewer.close(); + imageViewerClose(); break; case 'workflows': dispatch(setActiveTab('workflows')); @@ -41,7 +45,7 @@ export const useHandleStudioDestination = () => { break; case 'viewAllWorkflows': dispatch(setActiveTab('workflows')); - workflowLibraryModal.setFalse(); + workflowLibraryModal.setTrue(); break; case 'viewAllStylePresets': dispatch(setActiveTab('canvas')); @@ -51,8 +55,9 @@ export const useHandleStudioDestination = () => { dispatch(setActiveTab('canvas')); break; } + setInitialized(true); }, - [dispatch, imageViewer, workflowLibraryModal] + [dispatch, imageViewerOpen, imageViewerClose, workflowLibraryModal, initialized] ); return handleStudioDestination;