Use MOTIS API now
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user