Skip to content

Commit 31e270e

Browse files
committed
add base prop for destination to direct users to different tabs
1 parent 4ce64b6 commit 31e270e

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

invokeai/frontend/web/src/app/components/App.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { useStarterModelsToast } from 'features/modelManagerV2/hooks/useStarterM
1616
import { configChanged } from 'features/system/store/configSlice';
1717
import { languageSelector } from 'features/system/store/systemSelectors';
1818
import InvokeTabs from 'features/ui/components/InvokeTabs';
19+
import type { InvokeTabName } from 'features/ui/store/tabMap';
1920
import { AnimatePresence } from 'framer-motion';
2021
import i18n from 'i18n';
2122
import { size } from 'lodash-es';
@@ -24,6 +25,7 @@ import { ErrorBoundary } from 'react-error-boundary';
2425
import { useGetOpenAPISchemaQuery } from 'services/api/endpoints/appInfo';
2526

2627
import AppErrorBoundaryFallback from './AppErrorBoundaryFallback';
28+
import Destination from './Destination';
2729
import PreselectedImage from './PreselectedImage';
2830

2931
const DEFAULT_CONFIG = {};
@@ -34,9 +36,10 @@ interface Props {
3436
imageName: string;
3537
action: 'sendToImg2Img' | 'sendToCanvas' | 'useAllParameters';
3638
};
39+
destination?: InvokeTabName | undefined;
3740
}
3841

39-
const App = ({ config = DEFAULT_CONFIG, selectedImage }: Props) => {
42+
const App = ({ config = DEFAULT_CONFIG, selectedImage, destination }: Props) => {
4043
const language = useAppSelector(languageSelector);
4144
const logger = useLogger('system');
4245
const dispatch = useAppDispatch();
@@ -96,6 +99,7 @@ const App = ({ config = DEFAULT_CONFIG, selectedImage }: Props) => {
9699
<ChangeBoardModal />
97100
<DynamicPromptsModal />
98101
<PreselectedImage selectedImage={selectedImage} />
102+
<Destination destination={destination} />
99103
</ErrorBoundary>
100104
);
101105
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { useDestination } from 'features/parameters/hooks/useDestination';
2+
import type { InvokeTabName } from 'features/ui/store/tabMap';
3+
import { memo } from 'react';
4+
5+
type Props = {
6+
destination: InvokeTabName | undefined;
7+
};
8+
9+
const Destination = (props: Props) => {
10+
useDestination(props.destination);
11+
return null;
12+
};
13+
14+
export default memo(Destination);

invokeai/frontend/web/src/app/components/InvokeAIUI.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ interface Props extends PropsWithChildren {
4343
imageName: string;
4444
action: 'sendToImg2Img' | 'sendToCanvas' | 'useAllParameters';
4545
};
46+
destination?: 'canvas' | 'workflows';
4647
customStarUi?: CustomStarUi;
4748
socketOptions?: Partial<ManagerOptions & SocketOptions>;
4849
isDebugging?: boolean;
@@ -62,6 +63,7 @@ const InvokeAIUI = ({
6263
projectUrl,
6364
queueId,
6465
selectedImage,
66+
destination,
6567
customStarUi,
6668
socketOptions,
6769
isDebugging = false,
@@ -218,7 +220,7 @@ const InvokeAIUI = ({
218220
<React.Suspense fallback={<Loading />}>
219221
<ThemeLocaleProvider>
220222
<AppDndContext>
221-
<App config={config} selectedImage={selectedImage} />
223+
<App config={config} selectedImage={selectedImage} destination={destination} />
222224
</AppDndContext>
223225
</ThemeLocaleProvider>
224226
</React.Suspense>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { useAppDispatch } from 'app/store/storeHooks';
2+
import type { InvokeTabName } from 'features/ui/store/tabMap';
3+
import { setActiveTab } from 'features/ui/store/uiSlice';
4+
import { useCallback, useEffect } from 'react';
5+
6+
export const useDestination = (destination: InvokeTabName | undefined) => {
7+
const dispatch = useAppDispatch();
8+
9+
const handleSendToDestination = useCallback(() => {
10+
if (destination) {
11+
dispatch(setActiveTab(destination));
12+
}
13+
}, [dispatch, destination]);
14+
15+
useEffect(() => {
16+
handleSendToDestination();
17+
}, [destination, handleSendToDestination]);
18+
19+
return { handleSendToDestination };
20+
};

0 commit comments

Comments
 (0)