Skip to content

Commit d0619c0

Browse files
feat(ui): add edit button to current image buttons
1 parent 6f4850f commit d0619c0

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

invokeai/frontend/web/src/features/gallery/components/ImageViewer/CurrentImageButtons.tsx

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
1-
import { Divider, IconButton, Menu, MenuButton, MenuList } from '@invoke-ai/ui-library';
1+
import { Button, Divider, IconButton, Menu, MenuButton, MenuList } from '@invoke-ai/ui-library';
22
import { useStore } from '@nanostores/react';
3-
import { useAppSelector } from 'app/store/storeHooks';
3+
import { useAppSelector, useAppStore } from 'app/store/storeHooks';
44
import { selectIsStaging } from 'features/controlLayers/store/canvasStagingAreaSlice';
55
import { DeleteImageButton } from 'features/deleteImageModal/components/DeleteImageButton';
66
import SingleSelectionMenuItems from 'features/gallery/components/ImageContextMenu/SingleSelectionMenuItems';
77
import { useImageActions } from 'features/gallery/hooks/useImageActions';
88
import { selectLastSelectedImage } from 'features/gallery/store/gallerySelectors';
9+
import { newCanvasFromImage } from 'features/imageActions/actions';
910
import { $hasTemplates } from 'features/nodes/store/nodesSlice';
1011
import { PostProcessingPopover } from 'features/parameters/components/PostProcessing/PostProcessingPopover';
1112
import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus';
13+
import { toast } from 'features/toast/toast';
14+
import { useAutoLayoutContext } from 'features/ui/layouts/auto-layout-context';
15+
import { WORKSPACE_PANEL_ID } from 'features/ui/layouts/shared';
1216
import { selectShouldShowProgressInViewer } from 'features/ui/store/uiSelectors';
13-
import { memo } from 'react';
17+
import { setActiveTab } from 'features/ui/store/uiSlice';
18+
import { memo, useCallback } from 'react';
1419
import { useTranslation } from 'react-i18next';
1520
import {
1621
PiArrowsCounterClockwiseBold,
1722
PiAsteriskBold,
1823
PiDotsThreeOutlineFill,
1924
PiFlowArrowBold,
25+
PiPencilBold,
2026
PiPlantBold,
2127
PiQuotesBold,
2228
PiRulerBold,
@@ -38,6 +44,29 @@ export const CurrentImageButtons = memo(() => {
3844
const imageActions = useImageActions(imageDTO);
3945
const isStaging = useAppSelector(selectIsStaging);
4046
const isUpscalingEnabled = useFeatureStatus('upscaling');
47+
const { getState, dispatch } = useAppStore();
48+
const autoLayoutContext = useAutoLayoutContext();
49+
50+
const handleEdit = useCallback(async () => {
51+
if (!imageDTO) {
52+
return;
53+
}
54+
55+
await newCanvasFromImage({
56+
imageDTO,
57+
type: 'raster_layer',
58+
withInpaintMask: true,
59+
getState,
60+
dispatch,
61+
});
62+
dispatch(setActiveTab('canvas'));
63+
autoLayoutContext?.focusPanel(WORKSPACE_PANEL_ID);
64+
toast({
65+
id: 'SENT_TO_CANVAS',
66+
title: t('toast.sentToCanvas'),
67+
status: 'success',
68+
});
69+
}, [imageDTO, getState, dispatch, t, autoLayoutContext]);
4170

4271
return (
4372
<>
@@ -56,6 +85,20 @@ export const CurrentImageButtons = memo(() => {
5685

5786
<Divider orientation="vertical" h={8} mx={2} />
5887

88+
<Button
89+
leftIcon={<PiPencilBold />}
90+
onClick={handleEdit}
91+
isDisabled={isDisabledOverride || !imageDTO}
92+
variant="link"
93+
size="sm"
94+
alignSelf="stretch"
95+
px={2}
96+
>
97+
{t('common.edit')}
98+
</Button>
99+
100+
<Divider orientation="vertical" h={8} mx={2} />
101+
59102
<IconButton
60103
icon={<PiFlowArrowBold />}
61104
tooltip={`${t('nodes.loadWorkflow')} (W)`}

0 commit comments

Comments
 (0)