mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
remove ref, make options optional for useGetLoadWorkflow
This commit is contained in:
parent
88648dca1a
commit
268be97ba0
@ -23,7 +23,7 @@ import { useGetAndLoadLibraryWorkflow } from 'features/workflowLibrary/hooks/use
|
|||||||
import { AnimatePresence } from 'framer-motion';
|
import { AnimatePresence } from 'framer-motion';
|
||||||
import i18n from 'i18n';
|
import i18n from 'i18n';
|
||||||
import { size } from 'lodash-es';
|
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 { ErrorBoundary } from 'react-error-boundary';
|
||||||
import { useGetOpenAPISchemaQuery } from 'services/api/endpoints/appInfo';
|
import { useGetOpenAPISchemaQuery } from 'services/api/endpoints/appInfo';
|
||||||
|
|
||||||
@ -47,7 +47,6 @@ const App = ({ config = DEFAULT_CONFIG, selectedImage, selectedWorkflowId, desti
|
|||||||
const logger = useLogger('system');
|
const logger = useLogger('system');
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const clearStorage = useClearStorage();
|
const clearStorage = useClearStorage();
|
||||||
const hasLoadedRef = useRef<boolean>(false);
|
|
||||||
|
|
||||||
// singleton!
|
// singleton!
|
||||||
useSocketIO();
|
useSocketIO();
|
||||||
@ -74,16 +73,11 @@ const App = ({ config = DEFAULT_CONFIG, selectedImage, selectedWorkflowId, desti
|
|||||||
}
|
}
|
||||||
}, [dispatch, config, logger]);
|
}, [dispatch, config, logger]);
|
||||||
|
|
||||||
const { getAndLoadWorkflow } = useGetAndLoadLibraryWorkflow({
|
const { getAndLoadWorkflow } = useGetAndLoadLibraryWorkflow();
|
||||||
onSuccess: () => {
|
|
||||||
setActiveTab('workflows');
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedWorkflowId && !hasLoadedRef.current) {
|
if (selectedWorkflowId) {
|
||||||
getAndLoadWorkflow(selectedWorkflowId);
|
getAndLoadWorkflow(selectedWorkflowId);
|
||||||
hasLoadedRef.current = true;
|
|
||||||
}
|
}
|
||||||
}, [selectedWorkflowId, getAndLoadWorkflow]);
|
}, [selectedWorkflowId, getAndLoadWorkflow]);
|
||||||
|
|
||||||
|
@ -15,9 +15,9 @@ type UseGetAndLoadLibraryWorkflowReturn = {
|
|||||||
getAndLoadWorkflowResult: ReturnType<typeof useLazyGetWorkflowQuery>[1];
|
getAndLoadWorkflowResult: ReturnType<typeof useLazyGetWorkflowQuery>[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 dispatch = useAppDispatch();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
const { t } = useTranslation();
|
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
|
// 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 }));
|
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
|
// No toast - the listener for this action does that after the workflow is loaded
|
||||||
onSuccess && onSuccess();
|
arg?.onSuccess && arg.onSuccess();
|
||||||
} catch {
|
} catch {
|
||||||
toast({
|
toast({
|
||||||
id: `AUTH_ERROR_TOAST_${workflowsApi.endpoints.getWorkflow.name}`,
|
id: `AUTH_ERROR_TOAST_${workflowsApi.endpoints.getWorkflow.name}`,
|
||||||
title: t('toast.problemRetrievingWorkflow'),
|
title: t('toast.problemRetrievingWorkflow'),
|
||||||
status: 'error',
|
status: 'error',
|
||||||
});
|
});
|
||||||
onError && onError();
|
arg?.onError && arg.onError();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[_getAndLoadWorkflow, dispatch, onSuccess, t, onError, toast]
|
[_getAndLoadWorkflow, dispatch, arg, t, toast]
|
||||||
);
|
);
|
||||||
|
|
||||||
return { getAndLoadWorkflow, getAndLoadWorkflowResult };
|
return { getAndLoadWorkflow, getAndLoadWorkflowResult };
|
||||||
|
Loading…
Reference in New Issue
Block a user