diff --git a/invokeai/frontend/web/src/app/components/App.tsx b/invokeai/frontend/web/src/app/components/App.tsx index 760eddbee8..c61f892f49 100644 --- a/invokeai/frontend/web/src/app/components/App.tsx +++ b/invokeai/frontend/web/src/app/components/App.tsx @@ -18,10 +18,11 @@ import { languageSelector } from 'features/system/store/systemSelectors'; import InvokeTabs from 'features/ui/components/InvokeTabs'; import type { InvokeTabName } from 'features/ui/store/tabMap'; import { setActiveTab } from 'features/ui/store/uiSlice'; +import { useGetAndLoadLibraryWorkflow } from 'features/workflowLibrary/hooks/useGetAndLoadLibraryWorkflow'; import { AnimatePresence } from 'framer-motion'; import i18n from 'i18n'; import { size } from 'lodash-es'; -import { memo, useCallback, useEffect } from 'react'; +import { memo, useCallback, useEffect, useRef } from 'react'; import { ErrorBoundary } from 'react-error-boundary'; import { useGetOpenAPISchemaQuery } from 'services/api/endpoints/appInfo'; @@ -36,14 +37,16 @@ interface Props { imageName: string; action: 'sendToImg2Img' | 'sendToCanvas' | 'useAllParameters'; }; + selectedWorkflow?: string; destination?: InvokeTabName | undefined; } -const App = ({ config = DEFAULT_CONFIG, selectedImage, destination }: Props) => { +const App = ({ config = DEFAULT_CONFIG, selectedImage, selectedWorkflow, destination }: Props) => { const language = useAppSelector(languageSelector); const logger = useLogger('system'); const dispatch = useAppDispatch(); const clearStorage = useClearStorage(); + const hasLoadedRef = useRef(false); // singleton! useSocketIO(); @@ -70,6 +73,19 @@ const App = ({ config = DEFAULT_CONFIG, selectedImage, destination }: Props) => } }, [dispatch, config, logger]); + const { getAndLoadWorkflow } = useGetAndLoadLibraryWorkflow({ + onSuccess: () => { + setActiveTab('workflows'); + }, + }); + + useEffect(() => { + if (selectedWorkflow && !hasLoadedRef.current) { + getAndLoadWorkflow(selectedWorkflow); + hasLoadedRef.current = true; + } + }, [selectedWorkflow, getAndLoadWorkflow]); + useEffect(() => { if (destination) { dispatch(setActiveTab(destination)); diff --git a/invokeai/frontend/web/src/app/components/InvokeAIUI.tsx b/invokeai/frontend/web/src/app/components/InvokeAIUI.tsx index 0a80b7e92d..f1e23ebf16 100644 --- a/invokeai/frontend/web/src/app/components/InvokeAIUI.tsx +++ b/invokeai/frontend/web/src/app/components/InvokeAIUI.tsx @@ -44,6 +44,7 @@ interface Props extends PropsWithChildren { imageName: string; action: 'sendToImg2Img' | 'sendToCanvas' | 'useAllParameters'; }; + selectedWorkflow?: string; destination?: InvokeTabName; customStarUi?: CustomStarUi; socketOptions?: Partial; @@ -64,6 +65,7 @@ const InvokeAIUI = ({ projectUrl, queueId, selectedImage, + selectedWorkflow, destination, customStarUi, socketOptions, @@ -221,7 +223,7 @@ const InvokeAIUI = ({ }> - +