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:
@ -5,8 +5,6 @@ import { log } from 'app/logging/useLogger';
|
|||||||
import { clamp } from 'lodash-es';
|
import { clamp } from 'lodash-es';
|
||||||
import { imageSelected } from 'features/gallery/store/gallerySlice';
|
import { imageSelected } from 'features/gallery/store/gallerySlice';
|
||||||
import {
|
import {
|
||||||
imageRemoved,
|
|
||||||
imagesAdapter,
|
|
||||||
selectImagesEntities,
|
selectImagesEntities,
|
||||||
selectImagesIds,
|
selectImagesIds,
|
||||||
} from 'features/gallery/store/imagesSlice';
|
} from 'features/gallery/store/imagesSlice';
|
||||||
@ -58,8 +56,6 @@ export const addRequestedImageDeletionListener = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(imageRemoved(image_name));
|
|
||||||
|
|
||||||
dispatch(
|
dispatch(
|
||||||
imageDeleted({ imageName: image_name, imageOrigin: image_origin })
|
imageDeleted({ imageName: image_name, imageOrigin: image_origin })
|
||||||
);
|
);
|
||||||
@ -74,9 +70,7 @@ export const addImageDeletedPendingListener = () => {
|
|||||||
startAppListening({
|
startAppListening({
|
||||||
actionCreator: imageDeleted.pending,
|
actionCreator: imageDeleted.pending,
|
||||||
effect: (action, { dispatch, getState }) => {
|
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,
|
ControlNetModel,
|
||||||
} from './constants';
|
} from './constants';
|
||||||
import { controlNetImageProcessed } from './actions';
|
import { controlNetImageProcessed } from './actions';
|
||||||
|
import { imageDeleted } from 'services/thunks/image';
|
||||||
|
import { forEach } from 'lodash-es';
|
||||||
|
|
||||||
export const initialControlNet: Omit<ControlNetConfig, 'controlNetId'> = {
|
export const initialControlNet: Omit<ControlNetConfig, 'controlNetId'> = {
|
||||||
isEnabled: true,
|
isEnabled: true,
|
||||||
@ -194,6 +196,20 @@ export const controlNetSlice = createSlice({
|
|||||||
state.isProcessingControlImage = true;
|
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 { RootState } from 'app/store/store';
|
||||||
import { ImageCategory, ImageDTO } from 'services/api';
|
import { ImageCategory, ImageDTO } from 'services/api';
|
||||||
import { dateComparator } from 'common/util/dateComparator';
|
import { dateComparator } from 'common/util/dateComparator';
|
||||||
import { isString, keyBy } from 'lodash-es';
|
import { keyBy } from 'lodash-es';
|
||||||
import { receivedPageOfImages } from 'services/thunks/image';
|
import { imageDeleted, receivedPageOfImages } from 'services/thunks/image';
|
||||||
|
|
||||||
export const imagesAdapter = createEntityAdapter<ImageDTO>({
|
export const imagesAdapter = createEntityAdapter<ImageDTO>({
|
||||||
selectId: (image) => image.image_name,
|
selectId: (image) => image.image_name,
|
||||||
@ -49,14 +49,6 @@ const imagesSlice = createSlice({
|
|||||||
imageUpserted: (state, action: PayloadAction<ImageDTO>) => {
|
imageUpserted: (state, action: PayloadAction<ImageDTO>) => {
|
||||||
imagesAdapter.upsertOne(state, action.payload);
|
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[]>) => {
|
imageCategoriesChanged: (state, action: PayloadAction<ImageCategory[]>) => {
|
||||||
state.categories = action.payload;
|
state.categories = action.payload;
|
||||||
},
|
},
|
||||||
@ -76,6 +68,11 @@ const imagesSlice = createSlice({
|
|||||||
state.total = total;
|
state.total = total;
|
||||||
imagesAdapter.upsertMany(state, items);
|
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,
|
selectTotal: selectImagesTotal,
|
||||||
} = imagesAdapter.getSelectors<RootState>((state) => state.images);
|
} = imagesAdapter.getSelectors<RootState>((state) => state.images);
|
||||||
|
|
||||||
export const { imageUpserted, imageRemoved, imageCategoriesChanged } =
|
export const { imageUpserted, imageCategoriesChanged } = imagesSlice.actions;
|
||||||
imagesSlice.actions;
|
|
||||||
|
|
||||||
export default imagesSlice.reducer;
|
export default imagesSlice.reducer;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user