import React from 'react'; import { connect } from 'react-redux'; import {ScrollView, SafeAreaView, Text, View, TouchableOpacity, Platform} from 'react-native'; import {Divider} from 'react-native-elements'; import Theme from '../../components/theme.style.js'; import CustomHeader from '../../components/header.js'; import Icon from '../../components/icons.js'; import DB from '../../components/storage'; import REQUEST from '../../components/api'; import SearchFragment from './fragments/searchbar.js'; class PayatpumpStationSearch extends React.Component { constructor(props) { super(props) } state = { searchValue: this.props.route.params.value || "", cities: "", cityDropDown: [] } componentDidMount() { this.init() } componentWillUnmount() { } init = async () => { let SESSION = await DB.session() REQUEST('station_search', 'post', { Authorization: SESSION.token }, {}, {}, function(res){ setcities(res.data) },function(error){ console.log(error) }) } search = (value) => { let result = [] for(var x=0;x 0) result.push(cities[x]) } this.setState({ searchValue: value, cityDropDown: result }) } renderDropDown = () => { return this.state.cityDropDown.map((city, i) => { return ( { this.props.route.params.onBackPress(this.state.searchValue, city, false) this.props.navigation.goBack() }} key={i} style={{flex: 1}}> {city.name.toUpperCase()} ) }) } render() { return ( this.props.navigation.goBack()} navigation={this.props.navigation} /> this.search(value)} onClear={() => this.setState({ searchValue: "", cityDropDown: [] })}/> { this.props.route.params.onBackPress(this.state.searchValue, {}, true) this.props.navigation.goBack() }} style={{ flexDirection: 'row', height: 60, padding: 15, marginTop: 80}}> My Favorites {this.state.cityDropDown.length > 0 && this.state.searchValue != "" ? this.renderDropDown() : null} ) } } const mapStateToProps = (state) => { return { app_theme: state.appThemeReducer.theme } } export default connect(mapStateToProps, null)(PayatpumpStationSearch)