From 268be97ba020d4a43b9afe5a9ef32500970cbc92 Mon Sep 17 00:00:00 2001 From: chainchompa Date: Thu, 15 Aug 2024 09:18:41 -0400 Subject: [PATCH] remove ref, make options optional for useGetLoadWorkflow --- invokeai/frontend/web/src/app/components/App.tsx | 12 +++--------- .../hooks/useGetAndLoadLibraryWorkflow.ts | 10 +++++----- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/invokeai/frontend/web/src/app/components/App.tsx b/invokeai/frontend/web/src/app/components/App.tsx index 3b4448a12d..41f3d97051 100644 --- a/invokeai/frontend/web/src/app/components/App.tsx +++ b/invokeai/frontend/web/src/app/components/App.tsx @@ -23,7 +23,7 @@ import { useGetAndLoadLibraryWorkflow } from 'features/workflowLibrary/hooks/use import { AnimatePresence } from 'framer-motion'; import i18n from 'i18n'; import { size } from 'lodash-es'; -import { memo, useCallback, useEffect, useRef } from 'react'; +import { memo, useCallback, useEffect } from 'react'; import { ErrorBoundary } from 'react-error-boundary'; import { useGetOpenAPISchemaQuery } from 'services/api/endpoints/appInfo'; @@ -47,7 +47,6 @@ const App = ({ config = DEFAULT_CONFIG, selectedImage, selectedWorkflowId, desti const logger = useLogger('system'); const dispatch = useAppDispatch(); const clearStorage = useClearStorage(); - const hasLoadedRef = useRef(false); // singleton! useSocketIO(); @@ -74,16 +73,11 @@ const App = ({ config = DEFAULT_CONFIG, selectedImage, selectedWorkflowId, desti } }, [dispatch, config, logger]); - const { getAndLoadWorkflow } = useGetAndLoadLibraryWorkflow({ - onSuccess: () => { - setActiveTab('workflows'); - }, - }); + const { getAndLoadWorkflow } = useGetAndLoadLibraryWorkflow(); useEffect(() => { - if (selectedWorkflowId && !hasLoadedRef.current) { + if (selectedWorkflowId) { getAndLoadWorkflow(selectedWorkflowId); - hasLoadedRef.current = true; } }, [selectedWorkflowId, getAndLoadWorkflow]); diff --git a/invokeai/frontend/web/src/features/workflowLibrary/hooks/useGetAndLoadLibraryWorkflow.ts b/invokeai/frontend/web/src/features/workflowLibrary/hooks/useGetAndLoadLibraryWorkflow.ts index 89933999bd..9f86d11860 100644 --- a/invokeai/frontend/web/src/features/workflowLibrary/hooks/useGetAndLoadLibraryWorkflow.ts +++ b/invokeai/frontend/web/src/features/workflowLibrary/hooks/useGetAndLoadLibraryWorkflow.ts @@ -15,9 +15,9 @@ type UseGetAndLoadLibraryWorkflowReturn = { getAndLoadWorkflowResult: ReturnType[1]; }; -type UseGetAndLoadLibraryWorkflow = (arg: UseGetAndLoadLibraryWorkflowOptions) => UseGetAndLoadLibraryWorkflowReturn; +type UseGetAndLoadLibraryWorkflow = (arg?: UseGetAndLoadLibraryWorkflowOptions) => UseGetAndLoadLibraryWorkflowReturn; -export const useGetAndLoadLibraryWorkflow: UseGetAndLoadLibraryWorkflow = ({ onSuccess, onError }) => { +export const useGetAndLoadLibraryWorkflow: UseGetAndLoadLibraryWorkflow = (arg) => { const dispatch = useAppDispatch(); const toast = useToast(); const { t } = useTranslation(); @@ -29,17 +29,17 @@ export const useGetAndLoadLibraryWorkflow: UseGetAndLoadLibraryWorkflow = ({ onS // This action expects a stringified workflow, instead of updating the routes and services we will just stringify it here dispatch(workflowLoadRequested({ data: { workflow: JSON.stringify(workflow), graph: null }, asCopy: false })); // No toast - the listener for this action does that after the workflow is loaded - onSuccess && onSuccess(); + arg?.onSuccess && arg.onSuccess(); } catch { toast({ id: `AUTH_ERROR_TOAST_${workflowsApi.endpoints.getWorkflow.name}`, title: t('toast.problemRetrievingWorkflow'), status: 'error', }); - onError && onError(); + arg?.onError && arg.onError(); } }, - [_getAndLoadWorkflow, dispatch, onSuccess, t, onError, toast] + [_getAndLoadWorkflow, dispatch, arg, t, toast] ); return { getAndLoadWorkflow, getAndLoadWorkflowResult };