fix(ui): fix bug with image deletion not removing image from gallery

This commit is contained in:
psychedelicious 2023-06-21 20:40:12 +10:00
parent e2ee8102c2
commit 4545f3209f
4 changed files with 32 additions and 13 deletions

View File

@ -77,6 +77,7 @@ import {
addImageAddedToBoardFulfilledListener,
addImageAddedToBoardRejectedListener,
} from './listeners/imageAddedToBoard';
import { addBoardIdSelectedListener } from './listeners/boardIdSelected';
export const listenerMiddleware = createListenerMiddleware();
@ -191,3 +192,4 @@ addUpdateImageUrlsOnConnectListener();
// Boards
addImageAddedToBoardFulfilledListener();
addImageAddedToBoardRejectedListener();
addBoardIdSelectedListener();

View File

@ -0,0 +1,28 @@
import { log } from 'app/logging/useLogger';
import { startAppListening } from '..';
import { boardIdSelected } from 'features/gallery/store/boardSlice';
import { selectImagesAll } from 'features/gallery/store/imagesSlice';
import { receivedPageOfImages } from 'services/thunks/image';
const moduleLog = log.child({ namespace: 'boards' });
export const addBoardIdSelectedListener = () => {
startAppListening({
actionCreator: boardIdSelected,
effect: (action, { getState, dispatch }) => {
const boardId = action.payload;
const state = getState();
const { categories } = state.images;
const images = selectImagesAll(state).filter((i) => {
const isInCategory = categories.includes(i.image_category);
const isInSelectedBoard = boardId ? i.board_id === boardId : true;
return isInCategory && isInSelectedBoard;
});
if (images.length === 0) {
dispatch(receivedPageOfImages({ categories, boardId }));
}
},
});
};

View File

@ -14,7 +14,7 @@ import { clearInitialImage } from 'features/parameters/store/generationSlice';
import { nodeEditorReset } from 'features/nodes/store/nodesSlice';
import { api } from 'services/apiSlice';
const moduleLog = log.child({ namespace: 'addRequestedImageDeletionListener' });
const moduleLog = log.child({ namespace: 'image' });
/**
* Called when the user requests an image deletion
@ -30,7 +30,7 @@ export const addRequestedImageDeletionListener = () => {
const state = getState();
const selectedImage = state.gallery.selectedImage;
if (selectedImage && selectedImage === image_name) {
if (selectedImage === image_name) {
const ids = selectImagesIds(state);
const deletedImageIndex = ids.findIndex(

View File

@ -211,17 +211,6 @@ const ImageGalleryContent = () => {
dispatch(setGalleryView('assets'));
}, [dispatch]);
useEffect(() => {
if (images.length < 20) {
dispatch(
receivedPageOfImages({
categories,
boardId: selectedBoardId,
})
);
}
}, [categories, dispatch, images.length, selectedBoardId]);
return (
<VStack
sx={{