Skip to content

Commit 1f709eb

Browse files
Mary Hipphipsterusername
authored andcommitted
track whether hook fn has already been run
1 parent 747e863 commit 1f709eb

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

invokeai/frontend/web/src/app/hooks/useHandleStudioDestination.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useImageViewer } from 'features/gallery/components/ImageViewer/useImage
44
import { $isMenuOpen } from 'features/stylePresets/store/isMenuOpen';
55
import { setActiveTab } from 'features/ui/store/uiSlice';
66
import { useWorkflowLibraryModal } from 'features/workflowLibrary/store/isWorkflowLibraryModalOpen';
7-
import { useCallback } from 'react';
7+
import { useCallback, useState } from 'react';
88

99
export type StudioDestination =
1010
| 'generation'
@@ -16,22 +16,26 @@ export type StudioDestination =
1616

1717
export const useHandleStudioDestination = () => {
1818
const dispatch = useAppDispatch();
19-
const imageViewer = useImageViewer();
19+
const { open: imageViewerOpen, close: imageViewerClose } = useImageViewer();
20+
const [initialized, setInitialized] = useState(false);
2021

2122
const workflowLibraryModal = useWorkflowLibraryModal();
2223

2324
const handleStudioDestination = useCallback(
2425
(destination: StudioDestination) => {
26+
if (initialized) {
27+
return;
28+
}
2529
switch (destination) {
2630
case 'generation':
2731
dispatch(setActiveTab('canvas'));
2832
dispatch(settingsSendToCanvasChanged(false));
29-
imageViewer.open();
33+
imageViewerOpen();
3034
break;
3135
case 'canvas':
3236
dispatch(setActiveTab('canvas'));
3337
dispatch(settingsSendToCanvasChanged(true));
34-
imageViewer.close();
38+
imageViewerClose();
3539
break;
3640
case 'workflows':
3741
dispatch(setActiveTab('workflows'));
@@ -41,7 +45,7 @@ export const useHandleStudioDestination = () => {
4145
break;
4246
case 'viewAllWorkflows':
4347
dispatch(setActiveTab('workflows'));
44-
workflowLibraryModal.setFalse();
48+
workflowLibraryModal.setTrue();
4549
break;
4650
case 'viewAllStylePresets':
4751
dispatch(setActiveTab('canvas'));
@@ -51,8 +55,9 @@ export const useHandleStudioDestination = () => {
5155
dispatch(setActiveTab('canvas'));
5256
break;
5357
}
58+
setInitialized(true);
5459
},
55-
[dispatch, imageViewer, workflowLibraryModal]
60+
[dispatch, imageViewerOpen, imageViewerClose, workflowLibraryModal, initialized]
5661
);
5762

5863
return handleStudioDestination;

0 commit comments

Comments
 (0)