From 83cd07feee9166fd32b960dd37f27be8c9bb8117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Mon, 11 Dec 2023 16:06:53 +0100 Subject: [PATCH] updates SliderComponent to emit attribute updates (instead of full state dict) --- frontend/src/components/SliderComponent.tsx | 42 ++------------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/frontend/src/components/SliderComponent.tsx b/frontend/src/components/SliderComponent.tsx index fc4bb3a..6cd7464 100644 --- a/frontend/src/components/SliderComponent.tsx +++ b/frontend/src/components/SliderComponent.tsx @@ -58,50 +58,17 @@ export const SliderComponent = React.memo((props: SliderComponentProps) => { addNotification(`${parentPath}.${name}.stepSize changed to ${stepSize}.`); }, [props.stepSize]); - const emitSliderUpdate = ( - name: string, - parentPath: string, - value: number, - callback?: (ack: unknown) => void, - min: number = props.min, - max: number = props.max, - stepSize: number = props.stepSize - ) => { - setAttribute( - name, - parentPath, - { - value: value, - min: min, - max: max, - step_size: stepSize - }, - callback - ); - }; const handleOnChange = (event, newNumber: number | number[]) => { // This will never be the case as we do not have a range slider. However, we should // make sure this is properly handled. if (Array.isArray(newNumber)) { newNumber = newNumber[0]; } - emitSliderUpdate(name, parentPath, newNumber); + setAttribute(`${name}.value`, parentPath, newNumber); }; const handleValueChange = (newValue: number, valueType: string) => { - switch (valueType) { - case 'min': - emitSliderUpdate(name, parentPath, value, undefined, newValue); - break; - case 'max': - emitSliderUpdate(name, parentPath, value, undefined, min, newValue); - break; - case 'stepSize': - emitSliderUpdate(name, parentPath, value, undefined, min, max, newValue); - break; - default: - break; - } + setAttribute(`${name}.${valueType}`, parentPath, newValue); }; return ( @@ -136,13 +103,12 @@ export const SliderComponent = React.memo((props: SliderComponentProps) => { null} /> @@ -197,7 +163,7 @@ export const SliderComponent = React.memo((props: SliderComponentProps) => { handleValueChange(Number(e.target.value), 'stepSize')} + onChange={(e) => handleValueChange(Number(e.target.value), 'step_size')} />