Skip to content

add base prop for destination to direct users to different tabs on initial load #6706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion invokeai/frontend/web/src/app/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useStarterModelsToast } from 'features/modelManagerV2/hooks/useStarterM
import { configChanged } from 'features/system/store/configSlice';
import { languageSelector } from 'features/system/store/systemSelectors';
import InvokeTabs from 'features/ui/components/InvokeTabs';
import type { InvokeTabName } from 'features/ui/store/tabMap';
import { AnimatePresence } from 'framer-motion';
import i18n from 'i18n';
import { size } from 'lodash-es';
Expand All @@ -24,6 +25,7 @@ import { ErrorBoundary } from 'react-error-boundary';
import { useGetOpenAPISchemaQuery } from 'services/api/endpoints/appInfo';

import AppErrorBoundaryFallback from './AppErrorBoundaryFallback';
import Destination from './Destination';
import PreselectedImage from './PreselectedImage';

const DEFAULT_CONFIG = {};
Expand All @@ -34,9 +36,10 @@ interface Props {
imageName: string;
action: 'sendToImg2Img' | 'sendToCanvas' | 'useAllParameters';
};
destination?: InvokeTabName | undefined;
}

const App = ({ config = DEFAULT_CONFIG, selectedImage }: Props) => {
const App = ({ config = DEFAULT_CONFIG, selectedImage, destination }: Props) => {
const language = useAppSelector(languageSelector);
const logger = useLogger('system');
const dispatch = useAppDispatch();
Expand Down Expand Up @@ -96,6 +99,7 @@ const App = ({ config = DEFAULT_CONFIG, selectedImage }: Props) => {
<ChangeBoardModal />
<DynamicPromptsModal />
<PreselectedImage selectedImage={selectedImage} />
<Destination destination={destination} />
</ErrorBoundary>
);
};
Expand Down
14 changes: 14 additions & 0 deletions invokeai/frontend/web/src/app/components/Destination.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useDestination } from 'features/parameters/hooks/useDestination';
import type { InvokeTabName } from 'features/ui/store/tabMap';
import { memo } from 'react';

type Props = {
destination: InvokeTabName | undefined;
};

const Destination = (props: Props) => {
useDestination(props.destination);
return null;
};

export default memo(Destination);
4 changes: 3 additions & 1 deletion invokeai/frontend/web/src/app/components/InvokeAIUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface Props extends PropsWithChildren {
imageName: string;
action: 'sendToImg2Img' | 'sendToCanvas' | 'useAllParameters';
};
destination?: 'canvas' | 'workflows';
customStarUi?: CustomStarUi;
socketOptions?: Partial<ManagerOptions & SocketOptions>;
isDebugging?: boolean;
Expand All @@ -62,6 +63,7 @@ const InvokeAIUI = ({
projectUrl,
queueId,
selectedImage,
destination,
customStarUi,
socketOptions,
isDebugging = false,
Expand Down Expand Up @@ -218,7 +220,7 @@ const InvokeAIUI = ({
<React.Suspense fallback={<Loading />}>
<ThemeLocaleProvider>
<AppDndContext>
<App config={config} selectedImage={selectedImage} />
<App config={config} selectedImage={selectedImage} destination={destination} />
</AppDndContext>
</ThemeLocaleProvider>
</React.Suspense>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useAppDispatch } from 'app/store/storeHooks';
import type { InvokeTabName } from 'features/ui/store/tabMap';
import { setActiveTab } from 'features/ui/store/uiSlice';
import { useCallback, useEffect } from 'react';

export const useDestination = (destination: InvokeTabName | undefined) => {
const dispatch = useAppDispatch();

const handleSendToDestination = useCallback(() => {
if (destination) {
dispatch(setActiveTab(destination));
}
}, [dispatch, destination]);

useEffect(() => {
handleSendToDestination();
}, [destination, handleSendToDestination]);

return { handleSendToDestination };
};