1
0
Fork 0

🐛 Fixed SA draft option to hold value across renders

This commit is contained in:
Joost De Cock 2019-07-04 07:42:30 +02:00
parent 693b94a4e2
commit 2a4c6b8656
3 changed files with 26 additions and 4 deletions

View file

@ -6,9 +6,19 @@ import { formatMm, roundMm, defaultSa, sliderStep } from "@freesewing/utils";
import OptionPreamble from "../OptionPreamble";
const DraftSettingSa = props => {
const [value, setValue] = useState("dflt");
const [saValue, setSaValue] = useState(defaultSa[props.units]);
const [customValue, setCustomValue] = useState(10);
const [value, setValue] = useState(
props.value === defaultSa[props.units]
? "dflt"
: props.value === 0
? "none"
: "custom"
);
const [saValue, setSaValue] = useState(
props.value === null ? defaultSa[props.units] : props.value
);
const [customValue, setCustomValue] = useState(
value === "custom" ? props.value : 10
);
const [expanded, setExpanded] = useState(false);
const update = (name, newValue, evt) => {

View file

@ -66,6 +66,13 @@ const DraftSettings = props => {
childProps.parts[part] = <FormattedMessage id={"parts." + part} />;
}
}
if (
typeof props.gist !== "undefined" &&
typeof props.gist.settings !== "undefined" &&
typeof props.gist.settings[setting] !== "undefined"
)
childProps.value = props.gist.settings[setting];
else childProps.value = null;
return childProps;
};

View file

@ -28,7 +28,12 @@ const OptionGroup = props => {
key: name,
noDocs: props.noDocs
};
if (typeof props.gist.settings.options[name] !== "undefined")
if (
typeof props.gist !== "undefined" &&
typeof props.gist.settings !== "undefined" &&
typeof props.gist.settings.options !== "undefined" &&
typeof props.gist.settings.options[name] !== "undefined"
)
extraProps.value = props.gist.settings.options[name];
else extraProps.value = null;