-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add image usage for board images and listener to handle actual deletion
- Loading branch information
1 parent
ba67e57
commit 723d68e
Showing
6 changed files
with
213 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
.../frontend/web/src/app/store/middleware/listenerMiddleware/listeners/boardImagesDeleted.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { requestedBoardImagesDeletion } from 'features/gallery/store/actions'; | ||
import { startAppListening } from '..'; | ||
import { imageSelected } from 'features/gallery/store/gallerySlice'; | ||
import { | ||
imagesRemoved, | ||
selectImagesAll, | ||
selectImagesById, | ||
} from 'features/gallery/store/imagesSlice'; | ||
import { resetCanvas } from 'features/canvas/store/canvasSlice'; | ||
import { controlNetReset } from 'features/controlNet/store/controlNetSlice'; | ||
import { clearInitialImage } from 'features/parameters/store/generationSlice'; | ||
import { nodeEditorReset } from 'features/nodes/store/nodesSlice'; | ||
import { LIST_TAG, api } from 'services/api'; | ||
import { boardsApi } from '../../../../../services/api/endpoints/boards'; | ||
|
||
export const addRequestedBoardImageDeletionListener = () => { | ||
startAppListening({ | ||
actionCreator: requestedBoardImagesDeletion, | ||
effect: async (action, { dispatch, getState, condition }) => { | ||
const { board, imagesUsage } = action.payload; | ||
|
||
const { board_id } = board; | ||
|
||
const state = getState(); | ||
const selectedImage = state.gallery.selectedImage | ||
? selectImagesById(state, state.gallery.selectedImage) | ||
: undefined; | ||
|
||
if (selectedImage && selectedImage.board_id === board_id) { | ||
dispatch(imageSelected()); | ||
} | ||
|
||
// We need to reset the features where the board images are in use - none of these work if their image(s) don't exist | ||
|
||
if (imagesUsage.isCanvasImage) { | ||
dispatch(resetCanvas()); | ||
} | ||
|
||
if (imagesUsage.isControlNetImage) { | ||
dispatch(controlNetReset()); | ||
} | ||
|
||
if (imagesUsage.isInitialImage) { | ||
dispatch(clearInitialImage()); | ||
} | ||
|
||
if (imagesUsage.isNodesImage) { | ||
dispatch(nodeEditorReset()); | ||
} | ||
|
||
// Preemptively remove from gallery | ||
const images = selectImagesAll(state).reduce((acc: string[], img) => { | ||
if (img.board_id === board_id) { | ||
acc.push(img.image_name); | ||
} | ||
return acc; | ||
}, []); | ||
dispatch(imagesRemoved(images)); | ||
|
||
// Delete from server | ||
dispatch(boardsApi.endpoints.deleteBoardAndImages.initiate(board_id)); | ||
const result = | ||
boardsApi.endpoints.deleteBoardAndImages.select(board_id)(state); | ||
const { isSuccess } = result; | ||
|
||
// Wait for successful deletion, then trigger boards to re-fetch | ||
const wasBoardDeleted = await condition(() => !!isSuccess, 30000); | ||
|
||
if (wasBoardDeleted) { | ||
dispatch( | ||
api.util.invalidateTags([ | ||
{ type: 'Board', id: board_id }, | ||
{ type: 'Image', id: LIST_TAG }, | ||
]) | ||
); | ||
} | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters