diff --git a/client/src/pages/spools/edit.tsx b/client/src/pages/spools/edit.tsx index 4c43ab0..36f52fe 100644 --- a/client/src/pages/spools/edit.tsx +++ b/client/src/pages/spools/edit.tsx @@ -20,6 +20,12 @@ We also need to stringify them again before sending them back to the API, which the form's onFinish method. Form.Item's normalize should do this, but it doesn't seem to work. */ +enum WeightToEnter { + used_weight = 1, + remaining_weight = 2, + measured_weight = 3, +} + export const SpoolEdit: React.FC = () => { const t = useTranslate(); const [messageApi, contextHolder] = message.useMessage(); @@ -94,17 +100,17 @@ export const SpoolEdit: React.FC = () => { const newSelectedFilament = filamentOptions?.find((obj) => { return obj.value === newID; }); - const newFilamentWeight = newSelectedFilament?.weight || 0; - const newSpoolWeight = newSelectedFilament?.spool_weight || 0; + const filamentHasWeight = newSelectedFilament?.weight || 0; + const filamentHasSpoolWeight = newSelectedFilament?.spool_weight || 0; - if (weightToEnter >= 3) { - if (!(newFilamentWeight && newSpoolWeight)) { - setWeightToEnter(2); + if (weightToEnter == WeightToEnter.measured_weight) { + if (!(filamentHasWeight && filamentHasSpoolWeight)) { + setWeightToEnter(WeightToEnter.remaining_weight); } } - if (weightToEnter >= 2) { - if (!newFilamentWeight) { - setWeightToEnter(1); + if (weightToEnter == WeightToEnter.remaining_weight || weightToEnter == WeightToEnter.measured_weight) { + if (!filamentHasWeight) { + setWeightToEnter(WeightToEnter.used_weight); } } }; @@ -232,14 +238,14 @@ export const SpoolEdit: React.FC = () => { onChange={(value) => { setWeightToEnter(value.target.value); }} - defaultValue={1} + defaultValue={WeightToEnter.used_weight} value={weightToEnter} > - {t("spool.fields.used_weight")} - + {t("spool.fields.used_weight")} + {t("spool.fields.remaining_weight")} - + {t("spool.fields.measured_weight")} @@ -251,7 +257,7 @@ export const SpoolEdit: React.FC = () => { precision={1} formatter={numberFormatter} parser={numberParser} - disabled={weightToEnter != 1} + disabled={weightToEnter != WeightToEnter.used_weight} value={usedWeight} onChange={(value) => { weightChange(value ?? 0); @@ -265,7 +271,7 @@ export const SpoolEdit: React.FC = () => { precision={1} formatter={numberFormatter} parser={numberParser} - disabled={weightToEnter != 2} + disabled={weightToEnter != WeightToEnter.remaining_weight} value={filamentWeight ? filamentWeight - usedWeight : 0} onChange={(value) => { weightChange(filamentWeight - (value ?? 0)); @@ -279,7 +285,7 @@ export const SpoolEdit: React.FC = () => { precision={1} formatter={numberFormatter} parser={numberParser} - disabled={weightToEnter != 3} + disabled={weightToEnter != WeightToEnter.measured_weight} value={filamentWeight && spoolWeight ? filamentWeight - usedWeight + spoolWeight : 0} onChange={(value) => { weightChange(filamentWeight - ((value ?? 0) - spoolWeight));