Use MOTIS API now

This commit is contained in:
2024-11-11 21:24:01 +01:00
parent e3fd6a7f88
commit 1c99c5ca47
7 changed files with 116 additions and 193 deletions

View File

@ -1,9 +1,8 @@
import {Autocomplete, TextField} from "@mui/material";
import {useRef, useState} from "react";
import {useState} from "react";
function AutocompleteStation(params) {
const [options, setOptions] = useState([])
const previousController = useRef()
function onInputChange(event, value) {
if (!value) {
@ -11,17 +10,9 @@ function AutocompleteStation(params) {
return
}
if (previousController.current)
previousController.current.abort()
const controller = new AbortController()
const signal = controller.signal
previousController.current = controller
fetch("/api/core/station/?search=" + value, {signal})
fetch(`${process.env.REACT_APP_MOTIS_SERVER}/api/v1/geocode?language=fr&text=${value}`)
.then(response => response.json())
.then(data => data.results)
.then(setOptions)
.catch()
}
return <>
@ -29,7 +20,7 @@ function AutocompleteStation(params) {
id="stop"
options={options}
onInputChange={onInputChange}
filterOptions={(x) => x}
filterOptions={(x) => x.filter(stop => stop.type === "STOP").filter(stop => !stop.id.startsWith("node/"))}
getOptionKey={option => option.id}
getOptionLabel={option => option.name}
groupBy={option => getOptionGroup(option)}
@ -40,7 +31,7 @@ function AutocompleteStation(params) {
}
function getOptionGroup(option) {
return option.country
return option.id.split('_')[0]
}
export default AutocompleteStation;