fix(ui): edge cases in auto-process

This commit is contained in:
psychedelicious 2024-05-02 08:39:08 +10:00 committed by Kent Keirsey
parent 45c2ac41d5
commit 6effa19626
2 changed files with 24 additions and 12 deletions

View File

@ -38,17 +38,20 @@ export const addControlAdapterPreprocessor = (startAppListening: AppStartListeni
.find((l) => l.id === layerId);
// Conditions to bail
const layerDoesNotExist = !precheckLayer;
const layerHasNoImage = !precheckLayer?.controlAdapter.image;
const layerHasNoProcessorConfig = !precheckLayer?.controlAdapter.processorConfig;
const layerIsAlreadyProcessingImage = precheckLayer?.controlAdapter.isProcessingImage;
const areImageAndProcessorUnchanged =
isEqual(precheckLayer?.controlAdapter.image, precheckLayerOriginal?.controlAdapter.image) &&
isEqual(precheckLayer?.controlAdapter.processorConfig, precheckLayerOriginal?.controlAdapter.processorConfig);
if (
// Layer doesn't exist
!precheckLayer ||
// Layer doesn't have an image
!precheckLayer.controlAdapter.image ||
// Layer doesn't have a processor config
!precheckLayer.controlAdapter.processorConfig ||
// Layer is already processing an image
precheckLayer.controlAdapter.isProcessingImage ||
// Processor config is the same
isEqual(precheckLayerOriginal?.controlAdapter.processorConfig, precheckLayer.controlAdapter.processorConfig)
layerDoesNotExist ||
layerHasNoImage ||
layerHasNoProcessorConfig ||
areImageAndProcessorUnchanged ||
layerIsAlreadyProcessingImage
) {
return;
}

View File

@ -250,8 +250,17 @@ export const controlLayersSlice = createSlice({
layer.bbox = null;
layer.bboxNeedsUpdate = true;
layer.isEnabled = true;
layer.controlAdapter.image = imageDTO ? imageDTOToImageWithDims(imageDTO) : null;
layer.controlAdapter.processedImage = null;
if (imageDTO) {
const newImage = imageDTOToImageWithDims(imageDTO);
if (isEqual(newImage, layer.controlAdapter.image)) {
return;
}
layer.controlAdapter.image = newImage;
layer.controlAdapter.processedImage = null;
} else {
layer.controlAdapter.image = null;
layer.controlAdapter.processedImage = null;
}
},
caLayerProcessedImageChanged: (state, action: PayloadAction<{ layerId: string; imageDTO: ImageDTO | null }>) => {
const { layerId, imageDTO } = action.payload;