fix(ui): discarding last single canvas image breaks canvas

We need to reset the staging area if we are discarding the last image.
This commit is contained in:
psychedelicious 2024-04-04 20:41:23 +11:00 committed by Kent Keirsey
parent 8a32baf2dc
commit 13027891d9

View File

@ -289,12 +289,19 @@ export const canvasSlice = createSlice({
const { images, selectedImageIndex } = state.layerState.stagingArea;
pushToPrevLayerStates(state);
if (!images.length) {
return;
}
images.splice(selectedImageIndex, 1);
if (images.length === 0) {
pushToPrevLayerStates(state);
state.layerState.stagingArea = deepClone(initialLayerState.stagingArea);
state.futureLayerStates = [];
state.shouldShowStagingOutline = true;
state.shouldShowStagingImage = true;
state.batchIds = [];
}
if (selectedImageIndex >= images.length) {
state.layerState.stagingArea.selectedImageIndex = images.length - 1;
}