-
Notifications
You must be signed in to change notification settings - Fork 0
/
BrowseCat1.js
98 lines (86 loc) · 2.4 KB
/
BrowseCat1.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
import React, { Component } from 'react';
import { Text, Image, View, StyleSheet, ScrollView } from 'react-native';
import { db } from './App';
const category="FOOD";
class BrowseCat1 extends Component {
constructor(props) {
super(props)
this.state = {
names: [],
}
this.setupFirebaseListener()
}
setupFirebaseListener = () => {
db
.ref('Retailers/')
.once('value')
.then((snapshot) => {
let retailers = []
snapshot.forEach((childSnapshot) => {
var val = childSnapshot.val();
if (val.storetype == 'Food') {
retailers.push(val);
}
});
this.setState({
...this.state,
names: retailers,
})
});
}
render() {
return (
<View>
<View style={styles.header}>
<Text style={styles.title}>{category}</Text>
</View>
<View>
<ScrollView>
{
this.state.names.map((item, index) => (
<View
key={item.key}
style={styles.item} >
<Text
onPress={() => {
this.props.navigation.navigate('Restaurant Info', {
restaurant: item.storename
});
}}>
{item.storename}
</Text>
</View>
))
}
</ScrollView>
</View>
</View>
)
}
componentDidMount() {
this.setupFirebaseListener()
}
}
export default BrowseCat1
const styles = StyleSheet.create ({
header: {
justifyContent: 'center',
margin: 5,
},
title: {
marginTop: 5,
marginBottom: 5,
fontSize: 20,
textAlign: 'center',
},
item: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
padding: 30,
margin: 2,
borderColor: '#2a4944',
borderWidth: 1,
backgroundColor: '#FFFF'
}
})