Fix Station-Select

This commit is contained in:
PxlLoewe
2025-07-22 11:06:00 -07:00
parent 228feb0512
commit a905872f25
5 changed files with 40 additions and 25 deletions

View File

@@ -45,16 +45,9 @@ export function StationsSelect({
queryFn: () => getStationsAPI(),
});
const [value, setValue] = useState<string[]>(selectedStations?.map((id) => String(id)) || []);
useEffect(() => {
setValue([
...(selectedStations || []).map((id) => String(id)),
...(vehicleStates.hpgAmbulanceState !== HpgState.NOT_REQUESTED || undefined ? ["RTW"] : []),
...(vehicleStates.hpgFireEngineState !== HpgState.NOT_REQUESTED || undefined ? ["FW"] : []),
...(vehicleStates.hpgPoliceState !== HpgState.NOT_REQUESTED || undefined ? ["POL"] : []),
]);
}, [selectedStations, vehicleStates]);
const [value, setValue] = useState<string[] | string | null>(
selectedStations?.map((id) => String(id)) || [],
);
// Helper to check if a station is a vehicle and its state is NOT_REQUESTED
const stationsOptions = [
@@ -101,6 +94,20 @@ export function StationsSelect({
return true;
});
useEffect(() => {
if (isMulti) {
setValue([
...(selectedStations || []).map((id) => String(id)),
...(vehicleStates.hpgAmbulanceState !== HpgState.NOT_REQUESTED || undefined ? ["RTW"] : []),
...(vehicleStates.hpgFireEngineState !== HpgState.NOT_REQUESTED || undefined ? ["FW"] : []),
...(vehicleStates.hpgPoliceState !== HpgState.NOT_REQUESTED || undefined ? ["POL"] : []),
]);
} else {
console.log("clear selected stations");
setValue(null);
}
}, [selectedStations, vehicleStates, isMulti]);
return (
<Select
className={className}

View File

@@ -135,7 +135,7 @@ export const ConnectionBtn = () => {
/>
</div>
)}
<fieldset className="fieldset mt-2 w-full">
<fieldset className="fieldset mt-4 w-full">
<label className="floating-label w-full text-base">
<span>Logoff Zeit (LCL)</span>
<input