-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
144 lines (135 loc) · 2.96 KB
/
App.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import * as React from "react";
import {
Text,
View,
StyleSheet,
FlatList,
Pressable,
TextInput,
SafeAreaView,
} from "react-native";
import Popup from "./components/Modal";
import customData from "./data.json";
const darkModeCategories = [
"Breads, Cereals, Grains and Pasta",
"Drinks",
"Sweeteners",
];
const categoryStyles = {
"Breads, Cereals, Grains and Pasta": "#694f3d",
Milk: "#9bc3ff",
Dairy: "#68a3fd",
"Nuts and Seeds": "#ffff80",
"Cooking ingredients, Herbs and Spices": "#cfcfcf",
Drinks: "#2e2e2e",
"Vegetables and legumes": "#b3ffb3",
Sweeteners: "#444e8a",
Cheese: "#fffb23",
"Meat & Substitutes": "#ff4848",
Condiments: "#caaae7",
Fruit: "#39ff74",
};
const Item = ({ title }) => (
<View
style={[styles.item, { backgroundColor: categoryStyles[title.category] }]}
>
<Text
style={
darkModeCategories.includes(title.category)
? styles.titleLight
: styles.title
}
>
{title.name}
{title.qty ? ` (Quantity: ${title.qty})` : ""}
</Text>
<Text
style={
darkModeCategories.includes(title.category)
? styles.subtitleLight
: styles.subtitle
}
>
{title.category}
</Text>
</View>
);
export default function App() {
const [modalVisible, setModalVisible] = React.useState(false);
const [activeItem, setActiveItem] = React.useState(null);
const [searchText, setSearchText] = React.useState("");
const searchFilteredData = searchText
? customData.filter((x) =>
x.name.toLowerCase().includes(searchText.toLowerCase())
)
: customData;
const onPress = (item) => {
setActiveItem(item);
setModalVisible(true);
};
const renderItem = ({ item }) => (
<Pressable onPress={() => onPress(item)}>
<Item title={item} />
</Pressable>
);
return (
<View style={styles.container}>
<TextInput
style={styles.input}
onChangeText={(text) => {
setSearchText(text);
}}
value={searchText}
placeholder="Enter food..."
placeholderTextColor="#e4e4e4"
/>
<FlatList
data={searchFilteredData}
renderItem={renderItem}
keyExtractor={(item) => item.id}
/>
<Popup
modalVisible={modalVisible}
setModalVisible={setModalVisible}
activeItem={activeItem}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#111111",
},
input: {
height: 60,
margin: 17.5,
borderWidth: 1,
padding: 15,
borderRadius: 10,
borderColor: "#969696",
fontSize: 18,
color: "#e4e4e4",
marginTop: 30,
},
item: {
padding: 14,
marginVertical: 4,
marginHorizontal: 16,
borderRadius: 15,
},
title: {
fontSize: 20,
},
subtitle: {
fontSize: 13.5,
},
titleLight: {
fontSize: 20,
color: "white",
},
subtitleLight: {
fontSize: 13.5,
color: "white",
},
});