-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
77 lines (70 loc) · 1.86 KB
/
App.tsx
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
import React, { useState } from "react";
import {
FlatList,
StyleSheet,
SwitchChangeEvent,
Text,
View,
} from "react-native";
import CategoryComponent from "./src/components/Category";
import SearchBar from "./src/components/SearchBar";
import Toggle from "./src/components/Toggle";
import Products from "./src/data/Products";
import parseData from "./src/utils/parseData";
const categories = parseData(Products);
export default function App() {
const [filters, setFilters] = useState({
onlyProductsInStock: false,
searchString: "",
});
function toggleOnlyShowProductsInStock(onlyProductsInStock: boolean) {
setFilters({ ...filters, onlyProductsInStock });
}
function search(searchString: string) {
setFilters({ ...filters, searchString });
}
return (
<View style={styles.container}>
<View>
<Text style={styles.header}>📊 My Stock</Text>
<View style={styles.categoriesContainer}>
<FlatList
data={categories}
renderItem={({ item }) =>
CategoryComponent({ category: item, filters })
}
extraData={filters}
></FlatList>
</View>
</View>
<View>
<View style={{ marginBottom: 10 }}>
<SearchBar value={filters.searchString} onChange={search}></SearchBar>
</View>
<Toggle
label="Only show products in stock"
value={filters.onlyProductsInStock}
onChange={toggleOnlyShowProductsInStock}
></Toggle>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
paddingTop: 18,
paddingBottom: 35,
paddingHorizontal: 35,
display: "flex",
flexDirection: "column",
justifyContent: "space-between",
flex: 1,
},
header: {
fontSize: 24,
fontWeight: "500",
},
categoriesContainer: {
marginTop: 20,
},
});