Skip to content

Commit b67eb41

Browse files
fix(ui): select next image when deleting
1 parent 522eeda commit b67eb41

File tree

1 file changed

+10
-2
lines changed
  • invokeai/frontend/web/src/features/deleteImageModal/store

1 file changed

+10
-2
lines changed

invokeai/frontend/web/src/features/deleteImageModal/store/state.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { selectCanvasSlice } from 'features/controlLayers/store/selectors';
1212
import type { CanvasState, RefImagesState } from 'features/controlLayers/store/types';
1313
import type { ImageUsage } from 'features/deleteImageModal/store/types';
14+
import { selectListImageNamesQueryArgs } from 'features/gallery/store/gallerySelectors';
1415
import { imageSelected } from 'features/gallery/store/gallerySlice';
1516
import { fieldImageCollectionValueChanged, fieldImageValueChanged } from 'features/nodes/store/nodesSlice';
1617
import { selectNodesSlice } from 'features/nodes/store/selectors';
@@ -79,11 +80,18 @@ const handleDeletions = async (image_names: string[], store: AppStore) => {
7980
try {
8081
const { dispatch, getState } = store;
8182
const state = getState();
82-
await dispatch(imagesApi.endpoints.deleteImages.initiate({ image_names }, { track: false })).unwrap();
83+
const { data } = imagesApi.endpoints.getImageNames.select(selectListImageNamesQueryArgs(state))(state);
84+
const index = data?.image_names.findIndex((name) => name === image_names[0]);
85+
const { deleted_images } = await dispatch(
86+
imagesApi.endpoints.deleteImages.initiate({ image_names }, { track: false })
87+
).unwrap();
88+
89+
const newImageNames = data?.image_names.filter((name) => !deleted_images.includes(name)) || [];
90+
const newSelectedImage = newImageNames[index ?? 0] || null;
8391

8492
if (intersection(state.gallery.selection, image_names).length > 0) {
8593
// Some selected images were deleted, clear selection
86-
dispatch(imageSelected(null));
94+
dispatch(imageSelected(newSelectedImage));
8795
}
8896

8997
// We need to reset the features where the image is in use - none of these work if their image(s) don't exist

0 commit comments

Comments
 (0)