From 5cbe9fafb2ae82a27f6cd9d9e5371e074f8af761 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sun, 14 Jul 2024 21:08:33 +1000 Subject: [PATCH] fix(ui): clear selection when deleting last image in board --- .../listeners/imageDeletionListeners.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/imageDeletionListeners.ts b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/imageDeletionListeners.ts index 056346cb68..489adb7476 100644 --- a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/imageDeletionListeners.ts +++ b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/imageDeletionListeners.ts @@ -136,7 +136,12 @@ export const addImageDeletionListeners = (startAppListening: AppStartListening) if (data) { const deletedImageIndex = data.items.findIndex((i) => i.image_name === imageDTO.image_name); const nextImage = data.items[deletedImageIndex + 1] ?? data.items[0] ?? null; - dispatch(imageSelected(nextImage)); + if (nextImage?.image_name === imageDTO.image_name) { + // If the next image is the same as the deleted one, it means it was the last image, reset selection + dispatch(imageSelected(null)); + } else { + dispatch(imageSelected(nextImage)); + } } } @@ -176,6 +181,8 @@ export const addImageDeletionListeners = (startAppListening: AppStartListening) const queryArgs = selectListImagesQueryArgs(state); const { data } = imagesApi.endpoints.listImages.select(queryArgs)(state); if (data) { + // When we delete multiple images, we clear the selection. Then, the the next time we load images, we will + // select the first one. This is handled below in the listener for `imagesApi.endpoints.listImages.matchFulfilled`. dispatch(imageSelected(null)); } }