mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): clear controlnet image when image deleted
This commit is contained in:
parent
840c632c0a
commit
3ff732d583
@ -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);
|
||||
//
|
||||
},
|
||||
});
|
||||
};
|
||||
|
@ -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<ControlNetConfig, 'controlNetId'> = {
|
||||
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;
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -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<ImageDTO>({
|
||||
selectId: (image) => image.image_name,
|
||||
@ -49,14 +49,6 @@ const imagesSlice = createSlice({
|
||||
imageUpserted: (state, action: PayloadAction<ImageDTO>) => {
|
||||
imagesAdapter.upsertOne(state, action.payload);
|
||||
},
|
||||
imageRemoved: (state, action: PayloadAction<string | ImageDTO>) => {
|
||||
if (isString(action.payload)) {
|
||||
imagesAdapter.removeOne(state, action.payload);
|
||||
return;
|
||||
}
|
||||
|
||||
imagesAdapter.removeOne(state, action.payload.image_name);
|
||||
},
|
||||
imageCategoriesChanged: (state, action: PayloadAction<ImageCategory[]>) => {
|
||||
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<RootState>((state) => state.images);
|
||||
|
||||
export const { imageUpserted, imageRemoved, imageCategoriesChanged } =
|
||||
imagesSlice.actions;
|
||||
export const { imageUpserted, imageCategoriesChanged } = imagesSlice.actions;
|
||||
|
||||
export default imagesSlice.reducer;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user