sipp11
7 years ago
13 changed files with 242 additions and 90 deletions
@ -0,0 +1,65 @@
|
||||
import React, { Component } from 'react' |
||||
import { components } from 'react-select' |
||||
import AsyncSelect from 'react-select/lib/Async' |
||||
|
||||
|
||||
const cbStopOptions = (inputValue, callback) => { |
||||
fetch(`https://api.goth.app/v1/stop/?search=${inputValue}`) |
||||
.then((response) => response.json()) |
||||
.then((json) => { |
||||
callback(json.results.map(ele => Object.assign(ele, { |
||||
value: ele.id, label: ele.name |
||||
}))) |
||||
}) |
||||
} |
||||
|
||||
const Option = (props) => { |
||||
const { stop_id, name, stop_desc } = props.data |
||||
return ( |
||||
<components.Option {...props}> |
||||
<code>{stop_id}</code> {name} |
||||
{stop_desc.length > 0 && <small><br />{stop_desc}</small>} |
||||
</components.Option> |
||||
); |
||||
}; |
||||
|
||||
class First extends Component { |
||||
|
||||
state = { inputValue: '' } |
||||
|
||||
handleInputChange = (newValue) => { |
||||
console.log("inputChange", newValue) |
||||
const inputValue = newValue.replace(/\W/g, '') |
||||
this.setState({ inputValue }) |
||||
return inputValue |
||||
} |
||||
|
||||
render() { |
||||
return ( |
||||
<div> |
||||
<br /> |
||||
<br /> |
||||
<br /> |
||||
<AsyncSelect |
||||
cacheOptions={true} |
||||
defaultOptions |
||||
defaultValue={{value: '1', label: 'test'}} |
||||
loadOptions={cbStopOptions} |
||||
components={{ Option }} |
||||
onChange={(item, evt) => { |
||||
console.log('on change', item, evt) |
||||
if (evt.action === 'select-option') { |
||||
console.log('select something', item) |
||||
return Object.assign(item, {value: item.name}) |
||||
} |
||||
console.log('?') |
||||
return item |
||||
}} |
||||
onInputChange={this.handleInputChange} |
||||
/> |
||||
</div> |
||||
) |
||||
} |
||||
} |
||||
|
||||
export default First |
@ -0,0 +1,60 @@
|
||||
|
||||
export const RouteTypeChoices = [ |
||||
{ value: '0', label: 'Tram, Light rail' }, |
||||
{ value: '1', label: 'Subway (within metro area)' }, |
||||
{ value: '2', label: 'Rail' }, |
||||
{ value: '3', label: 'Bus' }, |
||||
{ value: '4', label: 'Ferry' }, |
||||
{ value: '5', label: 'Cable car' }, |
||||
{ value: '6', label: 'Gondola' }, |
||||
{ value: '7', label: 'Funicular (steep inclines)' }, |
||||
] |
||||
|
||||
export const StopLocationTypes = [ |
||||
{ value: '0', label: 'Stop' }, |
||||
{ value: '1', label: 'Station' }, |
||||
{ value: '2', label: 'Station Entrance/Exit' }, |
||||
] |
||||
|
||||
export const StopWheelChairInfo = [ |
||||
{ value: '0', label: 'No information' }, |
||||
{ value: '1', label: 'Possible (partially or fully)' }, |
||||
{ value: '2', label: 'Not possible' }, |
||||
] |
||||
|
||||
export const DropOffTypes = [ |
||||
{ value: '0', label: 'Regularly scheduled dropoff' }, |
||||
{ value: '1', label: 'No drop off' }, |
||||
{ value: '2', label: 'Arrange drop off' }, |
||||
{ value: '3', label: 'Contact driver' }, |
||||
] |
||||
|
||||
export const TimePointChoices = [ |
||||
{ value: '0', label: 'times are considered approximate.' }, |
||||
{ value: '1', label: 'times are considered exact.' }, |
||||
] |
||||
|
||||
export const PickUpTypes = [ |
||||
{ value: '0', label: 'Regularly scheduled pickup' }, |
||||
{ value: '1', label: 'No pickup' }, |
||||
{ value: '2', label: 'Arrange pickup' }, |
||||
{ value: '3', label: 'Contact driver' }, |
||||
] |
||||
|
||||
export const DirectionChoices = [ |
||||
{ value: '0', label: 'outbound' }, |
||||
{ value: '1', label: 'inbound' }, |
||||
] |
||||
|
||||
export const WheelChairAccessibles = [ |
||||
{ value: '0', label: 'No information' }, |
||||
{ value: '1', label: 'Yes' }, |
||||
{ value: '2', label: 'Not possible' }, |
||||
] |
||||
|
||||
export const BikeAllowanceChoices = [ |
||||
{ value: '0', label: 'No information' }, |
||||
{ value: '1', label: 'Yes' }, |
||||
{ value: '2', label: 'Not possible' }, |
||||
] |
||||
|
@ -0,0 +1,13 @@
|
||||
|
||||
export const getItemFromList = (targetValue, list, defaultValue) => { |
||||
if (!targetValue && defaultValue === undefined) |
||||
return '' |
||||
let f = list.filter(ele => ele.value === targetValue) |
||||
if (f.length > 0) |
||||
return f[0] |
||||
// default value
|
||||
f = list.filter(ele => ele.value === defaultValue) |
||||
if (f.length > 0) |
||||
return f[0] |
||||
return '' |
||||
} |
Loading…
Reference in new issue