diff --git a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/imageDeleted.ts b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/imageDeleted.ts index bf7ca4020c..e8e7a78165 100644 --- a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/imageDeleted.ts +++ b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/imageDeleted.ts @@ -5,8 +5,6 @@ import { log } from 'app/logging/useLogger'; import { clamp } from 'lodash-es'; import { imageSelected } from 'features/gallery/store/gallerySlice'; import { - imageRemoved, - imagesAdapter, selectImagesEntities, selectImagesIds, } from 'features/gallery/store/imagesSlice'; @@ -58,8 +56,6 @@ export const addRequestedImageDeletionListener = () => { } } - dispatch(imageRemoved(image_name)); - dispatch( imageDeleted({ imageName: image_name, imageOrigin: image_origin }) ); @@ -74,9 +70,7 @@ export const addImageDeletedPendingListener = () => { startAppListening({ actionCreator: imageDeleted.pending, effect: (action, { dispatch, getState }) => { - const { imageName, imageOrigin } = action.meta.arg; - // Preemptively remove the image from the gallery - imagesAdapter.removeOne(getState().images, imageName); + // }, }); }; diff --git a/invokeai/frontend/web/src/features/controlNet/store/controlNetSlice.ts b/invokeai/frontend/web/src/features/controlNet/store/controlNetSlice.ts index 1389457aba..40714d3ecb 100644 --- a/invokeai/frontend/web/src/features/controlNet/store/controlNetSlice.ts +++ b/invokeai/frontend/web/src/features/controlNet/store/controlNetSlice.ts @@ -13,6 +13,8 @@ import { ControlNetModel, } from './constants'; import { controlNetImageProcessed } from './actions'; +import { imageDeleted } from 'services/thunks/image'; +import { forEach } from 'lodash-es'; export const initialControlNet: Omit = { isEnabled: true, @@ -194,6 +196,20 @@ export const controlNetSlice = createSlice({ state.isProcessingControlImage = true; } }); + + builder.addCase(imageDeleted.pending, (state, action) => { + // Preemptively remove the image from the gallery + const { imageName } = action.meta.arg; + forEach(state.controlNets, (c) => { + if (c.controlImage?.image_name === imageName) { + c.controlImage = null; + c.processedControlImage = null; + } + if (c.processedControlImage?.image_name === imageName) { + c.processedControlImage = null; + } + }); + }); }, }); diff --git a/invokeai/frontend/web/src/features/gallery/store/imagesSlice.ts b/invokeai/frontend/web/src/features/gallery/store/imagesSlice.ts index de2cdb48b2..539690dcde 100644 --- a/invokeai/frontend/web/src/features/gallery/store/imagesSlice.ts +++ b/invokeai/frontend/web/src/features/gallery/store/imagesSlice.ts @@ -7,8 +7,8 @@ import { import { RootState } from 'app/store/store'; import { ImageCategory, ImageDTO } from 'services/api'; import { dateComparator } from 'common/util/dateComparator'; -import { isString, keyBy } from 'lodash-es'; -import { receivedPageOfImages } from 'services/thunks/image'; +import { keyBy } from 'lodash-es'; +import { imageDeleted, receivedPageOfImages } from 'services/thunks/image'; export const imagesAdapter = createEntityAdapter({ selectId: (image) => image.image_name, @@ -49,14 +49,6 @@ const imagesSlice = createSlice({ imageUpserted: (state, action: PayloadAction) => { imagesAdapter.upsertOne(state, action.payload); }, - imageRemoved: (state, action: PayloadAction) => { - if (isString(action.payload)) { - imagesAdapter.removeOne(state, action.payload); - return; - } - - imagesAdapter.removeOne(state, action.payload.image_name); - }, imageCategoriesChanged: (state, action: PayloadAction) => { state.categories = action.payload; }, @@ -76,6 +68,11 @@ const imagesSlice = createSlice({ state.total = total; imagesAdapter.upsertMany(state, items); }); + builder.addCase(imageDeleted.pending, (state, action) => { + // Preemptively remove the image from the gallery + const { imageName } = action.meta.arg; + imagesAdapter.removeOne(state, imageName); + }); }, }); @@ -87,8 +84,7 @@ export const { selectTotal: selectImagesTotal, } = imagesAdapter.getSelectors((state) => state.images); -export const { imageUpserted, imageRemoved, imageCategoriesChanged } = - imagesSlice.actions; +export const { imageUpserted, imageCategoriesChanged } = imagesSlice.actions; export default imagesSlice.reducer;