From 4ea91499fc4149a066815f9a77c2b20758ab3c4d Mon Sep 17 00:00:00 2001 From: Mary Hipp Date: Wed, 20 Nov 2024 15:02:13 -0500 Subject: [PATCH] use nanostore for schema parsed instead --- .../frontend/web/src/app/components/App.tsx | 4 ++-- .../web/src/app/hooks/useStudioInitAction.ts | 21 ++++++++----------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/invokeai/frontend/web/src/app/components/App.tsx b/invokeai/frontend/web/src/app/components/App.tsx index dcfb23388fc..2902c344adb 100644 --- a/invokeai/frontend/web/src/app/components/App.tsx +++ b/invokeai/frontend/web/src/app/components/App.tsx @@ -59,7 +59,7 @@ const App = ({ config = DEFAULT_CONFIG, studioInitAction }: Props) => { useSocketIO(); useGlobalModifiersInit(); useGlobalHotkeys(); - const { data: openApiData } = useGetOpenAPISchemaQuery(); + useGetOpenAPISchemaQuery(); useSyncLoggingConfig(); const handleReset = useCallback(() => { @@ -83,7 +83,7 @@ const App = ({ config = DEFAULT_CONFIG, studioInitAction }: Props) => { dispatch(appStarted()); }, [dispatch]); - useStudioInitAction(studioInitAction, !!openApiData); + useStudioInitAction(studioInitAction); useStarterModelsToast(); useSyncQueueStatus(); useFocusRegionWatcher(); diff --git a/invokeai/frontend/web/src/app/hooks/useStudioInitAction.ts b/invokeai/frontend/web/src/app/hooks/useStudioInitAction.ts index 77f11d54a01..64bfbb5bd7d 100644 --- a/invokeai/frontend/web/src/app/hooks/useStudioInitAction.ts +++ b/invokeai/frontend/web/src/app/hooks/useStudioInitAction.ts @@ -1,3 +1,4 @@ +import { useStore } from '@nanostores/react'; import { useAppStore } from 'app/store/storeHooks'; import { useAssertSingleton } from 'common/hooks/useAssertSingleton'; import { withResultAsync } from 'common/util/result'; @@ -9,6 +10,7 @@ import { imageDTOToImageObject } from 'features/controlLayers/store/util'; import { $imageViewer } from 'features/gallery/components/ImageViewer/useImageViewer'; import { sentImageToCanvas } from 'features/gallery/store/actions'; import { parseAndRecallAllMetadata } from 'features/metadata/util/handlers'; +import { $hasTemplates } from 'features/nodes/store/nodesSlice'; import { $isWorkflowListMenuIsOpen } from 'features/nodes/store/workflowListMenu'; import { $isStylePresetsMenuOpen, activeStylePresetIdChanged } from 'features/stylePresets/store/stylePresetSlice'; import { toast } from 'features/toast/toast'; @@ -46,11 +48,12 @@ export type StudioInitAction = * - Use `getImageDTO` helper instead of `useGetImageDTO` * - Usee the `$imageViewer` atom instead of `useImageViewer` */ -export const useStudioInitAction = (action?: StudioInitAction, schemaLoaded?: boolean) => { +export const useStudioInitAction = (action?: StudioInitAction) => { useAssertSingleton('useStudioInitAction'); const { t } = useTranslation(); // Use a ref to ensure that we only perform the action once const didInit = useRef(false); + const didParseOpenAPISchema = useStore($hasTemplates); const store = useAppStore(); const { getAndLoadWorkflow } = useGetAndLoadLibraryWorkflow(); @@ -174,36 +177,30 @@ export const useStudioInitAction = (action?: StudioInitAction, schemaLoaded?: bo ); useEffect(() => { - if (didInit.current || !action) { + if (didInit.current || !action || !didParseOpenAPISchema) { return; } + didInit.current = true; + switch (action.type) { case 'loadWorkflow': - if (schemaLoaded) { - handleLoadWorkflow(action.data.workflowId); - didInit.current = true; - } + handleLoadWorkflow(action.data.workflowId); break; - case 'selectStylePreset': handleSelectStylePreset(action.data.stylePresetId); - didInit.current = true; break; case 'sendToCanvas': handleSendToCanvas(action.data.imageName); - didInit.current = true; break; case 'useAllParameters': handleUseAllMetadata(action.data.imageName); - didInit.current = true; break; case 'goToDestination': handleGoToDestination(action.data.destination); - didInit.current = true; break; default: @@ -216,6 +213,6 @@ export const useStudioInitAction = (action?: StudioInitAction, schemaLoaded?: bo handleSelectStylePreset, handleGoToDestination, handleLoadWorkflow, - schemaLoaded, + didParseOpenAPISchema, ]); };