Skip to content

Commit

Permalink
use nanostore for schema parsed instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Mary Hipp authored and maryhipp committed Nov 21, 2024
1 parent e9dd2c3 commit ded8391
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions invokeai/frontend/web/src/app/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const App = ({ config = DEFAULT_CONFIG, studioInitAction }: Props) => {
useSocketIO();
useGlobalModifiersInit();
useGlobalHotkeys();
const { data: openApiData } = useGetOpenAPISchemaQuery();
useGetOpenAPISchemaQuery();
useSyncLoggingConfig();

const handleReset = useCallback(() => {
Expand All @@ -83,7 +83,7 @@ const App = ({ config = DEFAULT_CONFIG, studioInitAction }: Props) => {
dispatch(appStarted());
}, [dispatch]);

useStudioInitAction(studioInitAction, !!openApiData);
useStudioInitAction(studioInitAction);
useStarterModelsToast();
useSyncQueueStatus();
useFocusRegionWatcher();
Expand Down
21 changes: 9 additions & 12 deletions invokeai/frontend/web/src/app/hooks/useStudioInitAction.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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:
Expand All @@ -216,6 +213,6 @@ export const useStudioInitAction = (action?: StudioInitAction, schemaLoaded?: bo
handleSelectStylePreset,
handleGoToDestination,
handleLoadWorkflow,
schemaLoaded,
didParseOpenAPISchema,
]);
};

0 comments on commit ded8391

Please sign in to comment.