setting the default option to the first device in the list

This commit is contained in:
csawatzky 2025-11-20 16:17:16 -06:00
parent f228e1a574
commit 3cce11db6b

View file

@ -105,6 +105,8 @@ export default function ModeChangeDialog(props: Props){
const [outdoorTempInput, setOutdoorTempInput] = useState<string>("") const [outdoorTempInput, setOutdoorTempInput] = useState<string>("")
const [outdoorHumidityInput, setOutdoorHumidityInput] = useState<string>("") const [outdoorHumidityInput, setOutdoorHumidityInput] = useState<string>("")
const [deviceOption, setDeviceOption] = useState<Option>()
useEffect(()=>{ useEffect(()=>{
setMoistureInput(defaultTargetMoisture?.toFixed(2) ?? "0") setMoistureInput(defaultTargetMoisture?.toFixed(2) ?? "0")
setOutdoorTempInput(defaultOutdoorTemp?.toFixed(2) ?? "0") setOutdoorTempInput(defaultOutdoorTemp?.toFixed(2) ?? "0")
@ -185,7 +187,12 @@ if (!selectedDevice) return;
useEffect(() => { useEffect(() => {
let o: Option[] = []; let o: Option[] = [];
devices.forEach(device => { devices.forEach(device => {
o.push({ device: device, label: device.name() }); let newOption: Option = {device: device, label: device.name()}
if(deviceOption === undefined) {
setDeviceOption(newOption)
setSelectedDevice(device)
}
o.push(newOption);
}); });
setOptions(o); setOptions(o);
}, [devices, setOptions]); }, [devices, setOptions]);
@ -535,6 +542,7 @@ if (!selectedDevice) return;
<Autocomplete <Autocomplete
disablePortal disablePortal
options={options} options={options}
value={deviceOption}
fullWidth fullWidth
getOptionLabel={option => option.label || ""} getOptionLabel={option => option.label || ""}
onChange={(_, newValue) => { onChange={(_, newValue) => {