Skip to content

Commit 1e7a5fd

Browse files
1 parent 050d724 commit 1e7a5fd

5 files changed

Lines changed: 39 additions & 26 deletions

File tree

frontend/src/app/socketio/emitters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import {
99
GalleryCategory,
1010
GalleryState,
11+
removeImage,
1112
} from '../../features/gallery/gallerySlice';
1213
import { OptionsState } from '../../features/options/optionsSlice';
1314
import {
@@ -163,6 +164,7 @@ const makeSocketIOEmitters = (
163164
},
164165
emitDeleteImage: (imageToDelete: InvokeAI.Image) => {
165166
const { url, uuid, category } = imageToDelete;
167+
dispatch(removeImage(imageToDelete));
166168
socketio.emit('deleteImage', url, uuid, category);
167169
},
168170
emitRequestImages: (category: GalleryCategory) => {

frontend/src/features/gallery/CurrentImageButtons.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@ import { SystemState } from '../system/systemSlice';
1717
import IAIButton from '../../common/components/IAIButton';
1818
import { runESRGAN, runFacetool } from '../../app/socketio/actions';
1919
import IAIIconButton from '../../common/components/IAIIconButton';
20-
import {
21-
MdDelete,
22-
MdFace,
23-
MdHd,
24-
MdImage,
25-
MdInfo,
26-
} from 'react-icons/md';
20+
import { MdDelete, MdFace, MdHd, MdImage, MdInfo } from 'react-icons/md';
2721
import InvokePopover from './InvokePopover';
2822
import UpscaleOptions from '../options/AdvancedOptions/Upscale/UpscaleOptions';
2923
import FaceRestoreOptions from '../options/AdvancedOptions/FaceRestore/FaceRestoreOptions';
@@ -360,7 +354,9 @@ const CurrentImageButtons = ({ image }: CurrentImageButtonsProps) => {
360354
icon={<MdDelete />}
361355
tooltip="Delete Image"
362356
aria-label="Delete Image"
363-
isDisabled={Boolean(intermediateImage)}
357+
isDisabled={
358+
Boolean(intermediateImage) || !isConnected || isProcessing
359+
}
364360
/>
365361
</DeleteImageModal>
366362
</div>

frontend/src/features/gallery/DeleteImageModal.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ import { setShouldConfirmOnDelete, SystemState } from '../system/systemSlice';
3030
import * as InvokeAI from '../../app/invokeai';
3131
import { useHotkeys } from 'react-hotkeys-hook';
3232

33+
const systemSelector = createSelector(
34+
(state: RootState) => state.system,
35+
(system: SystemState) => {
36+
const { shouldConfirmOnDelete, isConnected, isProcessing } = system;
37+
return { shouldConfirmOnDelete, isConnected, isProcessing };
38+
}
39+
);
3340
interface DeleteImageModalProps {
3441
/**
3542
* Component which, on click, should delete the image/open the modal.
@@ -41,11 +48,6 @@ interface DeleteImageModalProps {
4148
image: InvokeAI.Image;
4249
}
4350

44-
const systemSelector = createSelector(
45-
(state: RootState) => state.system,
46-
(system: SystemState) => system.shouldConfirmOnDelete
47-
);
48-
4951
/**
5052
* Needs a child, which will act as the button to delete an image.
5153
* If system.shouldConfirmOnDelete is true, a confirmation modal is displayed.
@@ -56,23 +58,19 @@ const DeleteImageModal = forwardRef(
5658
({ image, children }: DeleteImageModalProps, ref) => {
5759
const { isOpen, onOpen, onClose } = useDisclosure();
5860
const dispatch = useAppDispatch();
59-
const shouldConfirmOnDelete = useAppSelector(systemSelector);
61+
const { shouldConfirmOnDelete, isConnected, isProcessing } =
62+
useAppSelector(systemSelector);
6063
const cancelRef = useRef<HTMLButtonElement>(null);
61-
const toast = useToast();
6264

6365
const handleClickDelete = (e: SyntheticEvent) => {
6466
e.stopPropagation();
6567
shouldConfirmOnDelete ? onOpen() : handleDelete();
6668
};
6769

6870
const handleDelete = () => {
69-
dispatch(deleteImage(image));
70-
toast({
71-
title: 'Image Deleted',
72-
status: 'success',
73-
duration: 2500,
74-
isClosable: true,
75-
});
71+
if (isConnected && !isProcessing) {
72+
dispatch(deleteImage(image));
73+
}
7674
onClose();
7775
};
7876

frontend/src/features/gallery/HoverableImage.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ const memoEqualityCheck = (
3939
*/
4040
const HoverableImage = memo((props: HoverableImageProps) => {
4141
const dispatch = useAppDispatch();
42-
const { activeTabName, galleryImageObjectFit, galleryImageMinimumWidth } =
43-
useAppSelector(hoverableImageSelector);
42+
const {
43+
activeTabName,
44+
galleryImageObjectFit,
45+
galleryImageMinimumWidth,
46+
mayDeleteImage,
47+
} = useAppSelector(hoverableImageSelector);
4448
const { image, isSelected } = props;
4549
const { url, uuid, metadata } = image;
4650

@@ -177,6 +181,7 @@ const HoverableImage = memo((props: HoverableImageProps) => {
177181
size="xs"
178182
variant={'imageHoverIconButton'}
179183
fontSize={14}
184+
isDisabled={!mayDeleteImage}
180185
/>
181186
</DeleteImageModal>
182187
</Tooltip>

frontend/src/features/gallery/gallerySliceSelectors.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createSelector } from '@reduxjs/toolkit';
22
import { RootState } from '../../app/store';
33
import { activeTabNameSelector } from '../options/optionsSelectors';
44
import { OptionsState } from '../options/optionsSlice';
5+
import { SystemState } from '../system/systemSlice';
56
import { GalleryState } from './gallerySlice';
67

78
export const imageGallerySelector = createSelector(
@@ -46,9 +47,20 @@ export const imageGallerySelector = createSelector(
4647
);
4748

4849
export const hoverableImageSelector = createSelector(
49-
[(state: RootState) => state.options, (state: RootState) => state.gallery, activeTabNameSelector],
50-
(options: OptionsState, gallery: GalleryState, activeTabName) => {
50+
[
51+
(state: RootState) => state.options,
52+
(state: RootState) => state.gallery,
53+
(state: RootState) => state.system,
54+
activeTabNameSelector,
55+
],
56+
(
57+
options: OptionsState,
58+
gallery: GalleryState,
59+
system: SystemState,
60+
activeTabName
61+
) => {
5162
return {
63+
mayDeleteImage: system.isConnected && !system.isProcessing,
5264
galleryImageObjectFit: gallery.galleryImageObjectFit,
5365
galleryImageMinimumWidth: gallery.galleryImageMinimumWidth,
5466
activeTabName,

0 commit comments

Comments
 (0)