add base prop for destination to direct users to different tabs

This commit is contained in:
chainchompa 2024-07-31 17:20:51 -04:00
parent 4ce64b69cb
commit 31e270e32c
4 changed files with 42 additions and 2 deletions

View File

@ -16,6 +16,7 @@ import { useStarterModelsToast } from 'features/modelManagerV2/hooks/useStarterM
import { configChanged } from 'features/system/store/configSlice'; import { configChanged } from 'features/system/store/configSlice';
import { languageSelector } from 'features/system/store/systemSelectors'; import { languageSelector } from 'features/system/store/systemSelectors';
import InvokeTabs from 'features/ui/components/InvokeTabs'; import InvokeTabs from 'features/ui/components/InvokeTabs';
import type { InvokeTabName } from 'features/ui/store/tabMap';
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';
@ -24,6 +25,7 @@ import { ErrorBoundary } from 'react-error-boundary';
import { useGetOpenAPISchemaQuery } from 'services/api/endpoints/appInfo'; import { useGetOpenAPISchemaQuery } from 'services/api/endpoints/appInfo';
import AppErrorBoundaryFallback from './AppErrorBoundaryFallback'; import AppErrorBoundaryFallback from './AppErrorBoundaryFallback';
import Destination from './Destination';
import PreselectedImage from './PreselectedImage'; import PreselectedImage from './PreselectedImage';
const DEFAULT_CONFIG = {}; const DEFAULT_CONFIG = {};
@ -34,9 +36,10 @@ interface Props {
imageName: string; imageName: string;
action: 'sendToImg2Img' | 'sendToCanvas' | 'useAllParameters'; 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 language = useAppSelector(languageSelector);
const logger = useLogger('system'); const logger = useLogger('system');
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
@ -96,6 +99,7 @@ const App = ({ config = DEFAULT_CONFIG, selectedImage }: Props) => {
<ChangeBoardModal /> <ChangeBoardModal />
<DynamicPromptsModal /> <DynamicPromptsModal />
<PreselectedImage selectedImage={selectedImage} /> <PreselectedImage selectedImage={selectedImage} />
<Destination destination={destination} />
</ErrorBoundary> </ErrorBoundary>
); );
}; };

View File

@ -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);

View File

@ -43,6 +43,7 @@ interface Props extends PropsWithChildren {
imageName: string; imageName: string;
action: 'sendToImg2Img' | 'sendToCanvas' | 'useAllParameters'; action: 'sendToImg2Img' | 'sendToCanvas' | 'useAllParameters';
}; };
destination?: 'canvas' | 'workflows';
customStarUi?: CustomStarUi; customStarUi?: CustomStarUi;
socketOptions?: Partial<ManagerOptions & SocketOptions>; socketOptions?: Partial<ManagerOptions & SocketOptions>;
isDebugging?: boolean; isDebugging?: boolean;
@ -62,6 +63,7 @@ const InvokeAIUI = ({
projectUrl, projectUrl,
queueId, queueId,
selectedImage, selectedImage,
destination,
customStarUi, customStarUi,
socketOptions, socketOptions,
isDebugging = false, isDebugging = false,
@ -218,7 +220,7 @@ const InvokeAIUI = ({
<React.Suspense fallback={<Loading />}> <React.Suspense fallback={<Loading />}>
<ThemeLocaleProvider> <ThemeLocaleProvider>
<AppDndContext> <AppDndContext>
<App config={config} selectedImage={selectedImage} /> <App config={config} selectedImage={selectedImage} destination={destination} />
</AppDndContext> </AppDndContext>
</ThemeLocaleProvider> </ThemeLocaleProvider>
</React.Suspense> </React.Suspense>

View File

@ -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 };
};