Skip to content
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

fix(ui): track whether studio destination hook fn has already fired #6904

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useImageViewer } from 'features/gallery/components/ImageViewer/useImage
import { $isMenuOpen } from 'features/stylePresets/store/isMenuOpen';
import { setActiveTab } from 'features/ui/store/uiSlice';
import { useWorkflowLibraryModal } from 'features/workflowLibrary/store/isWorkflowLibraryModalOpen';
import { useCallback } from 'react';
import { useCallback, useState } from 'react';

export type StudioDestination =
| 'generation'
Expand All @@ -16,22 +16,26 @@ export type StudioDestination =

export const useHandleStudioDestination = () => {
const dispatch = useAppDispatch();
const imageViewer = useImageViewer();
const { open: imageViewerOpen, close: imageViewerClose } = useImageViewer();
const [initialized, setInitialized] = useState(false);

const workflowLibraryModal = useWorkflowLibraryModal();

const handleStudioDestination = useCallback(
(destination: StudioDestination) => {
if (initialized) {
return;
}
switch (destination) {
case 'generation':
dispatch(setActiveTab('canvas'));
dispatch(settingsSendToCanvasChanged(false));
imageViewer.open();
imageViewerOpen();
break;
case 'canvas':
dispatch(setActiveTab('canvas'));
dispatch(settingsSendToCanvasChanged(true));
imageViewer.close();
imageViewerClose();
break;
case 'workflows':
dispatch(setActiveTab('workflows'));
Expand All @@ -41,7 +45,7 @@ export const useHandleStudioDestination = () => {
break;
case 'viewAllWorkflows':
dispatch(setActiveTab('workflows'));
workflowLibraryModal.setFalse();
workflowLibraryModal.setTrue();
break;
case 'viewAllStylePresets':
dispatch(setActiveTab('canvas'));
Expand All @@ -51,8 +55,9 @@ export const useHandleStudioDestination = () => {
dispatch(setActiveTab('canvas'));
break;
}
setInitialized(true);
},
[dispatch, imageViewer, workflowLibraryModal]
[dispatch, imageViewerOpen, imageViewerClose, workflowLibraryModal, initialized]
);

return handleStudioDestination;
Expand Down
Loading