-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewRestaurants.js
113 lines (92 loc) · 2.89 KB
/
ViewRestaurants.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import React, {Component} from 'react';
import {StyleSheet, ActivityIndicator, FlatList, Text, View, Button, TouchableHighlight} from 'react-native';
import {ListItem, Icon, SearchBar} from 'react-native-elements';
type Props = {};
const URL = "http://10.0.2.2:2000/api/veggierestaurants/";
export default class viewRestaurants extends Component<Props> {
static navigationOptions = {
title: 'View Restaurants',
headerStyle:{
backgroundColor: '#008000',
},
headerTitleStyle:{
color: 'white',
fontSize: 25,
},
headerTintColor: 'white',
};
constructor(props){
super(props);
this.state={
isLoading: true,
data:[],
search: "",
fullData:[],
value: '',
noData: false
};
this.arrayholder = [];
}
componentDidMount() {
this.makeRemoteRequest();
}
makeRemoteRequest = () => {
return fetch(URL)
.then(response => response.json())
.then((responseJSON) => {
this.setState({
isLoading:false,
data:responseJSON,
fullData: responseJSON,
}, function(){
});
this.arrayholder = responseJSON;
})
.catch((error) => {
console.error(error);
});
};
searchFilterFunction = text => {
this.setState({
value: text,
});
let newText = text.toLowerCase();
let fullList = this.state.fullData;
let filteredList = fullList.filter((item) => {
return item.name.toString().toLowerCase().match(newText)
});
this.setState({
data: filteredList
});
};
renderSeparator = () => {
return (
<View style = {{height: 1, width: '100%', backgroundColor: '#14812d' }}/>
);
};
renderHeader = () => {
return (
<SearchBar
placeholder = "Search Here..."
lightTheme
round
onChangeText={text => this.searchFilterFunction(text)}
value={this.state.value}/>);
};
render() {
return (
<FlatList data={this.state.data}
renderItem={({ item }) => (
<ListItem titleStyle={{fontWeight: 'bold', fontSize:20}}
title={`${item.name} - ${item.veg_level_description}`}
subtitle={item.address}
containerStyle={{borderBottomWidth: 0 }}
/>
)}
keyExtractor={item => item.id}
ItemSeparatorComponent={this.renderSeparator}
ListHeaderComponent={this.renderHeader}
/>
);
}
}