Better datetime handle
This commit is contained in:
parent
e58ad34e43
commit
f0964d8fb7
@ -26,7 +26,6 @@ function DateTimeSelector({datetime, setDatetime}) {
|
||||
Modifier la date et l'heure de recherche :
|
||||
</FormLabel>
|
||||
<DateTimePicker name="date" label="Date" onChange={setDatetime} value={datetime} />
|
||||
<Button type="submit">Rechercher</Button>
|
||||
</Box>
|
||||
</>
|
||||
}
|
||||
@ -36,7 +35,11 @@ function Station() {
|
||||
let {theme, stationId} = useParams()
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
let [searchParams, setSearchParams] = useSearchParams()
|
||||
const [datetime, setDatetime] = useState(dayjs())
|
||||
const [datetime, setDatetime] = useState(dayjs(searchParams.get('time') || undefined))
|
||||
if (datetime.format() !== searchParams.get('time')) {
|
||||
searchParams.set('time', datetime.format())
|
||||
window.history.replaceState({}, '', '?' + searchParams.toString())
|
||||
}
|
||||
|
||||
useQueryClient()
|
||||
const stationQuery = useQuery({
|
||||
|
@ -69,10 +69,10 @@ function TrainsTableBody({station, datetime, tableType}) {
|
||||
.then(response => response.json())
|
||||
.then(data => data.stopTimes)
|
||||
.then(data => [...data])
|
||||
}, [station.stopId, datetime, tableType])
|
||||
}, [station.stopId, tableType, datetime])
|
||||
|
||||
const trainsQuery = useQuery({
|
||||
queryKey: ['trains', station.stopId, tableType],
|
||||
queryKey: ['trains', station.stopId, tableType, datetime],
|
||||
queryFn: updateTrains,
|
||||
enabled: !!station.stopId,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user