-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
172 lines (161 loc) · 4.73 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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import { StatusBar } from "expo-status-bar";
import * as React from "react";
import {
ToastAndroid,
Image,
Text,
View,
Platform,
Pressable,
} from "react-native";
import RNPickerSelect from "react-native-picker-select";
import { Storage } from "./storage";
import styles from "./styles/App.styles";
import logo from "./assets/nmw-logo.png";
import Clipboard from "expo-clipboard";
interface appstate {
level1: String;
level2: String;
level3: String;
level1Options: [];
level2Options: [];
level3Options: [];
nmwCode: String;
}
class App extends React.Component<{}, appstate> {
storage: Storage;
constructor(props = {}) {
super(props);
this.storage = new Storage();
this.storage.clearStorage();
this.storage.createTable(() =>
this.storage.lookupCodesByDepth(1, "0-0-0", (values) =>
this.populateLevel(
(data) => this.setState({ level1Options: data }),
values
)
)
);
this.state = {
level1: "",
level2: "",
level3: "",
level1Options: [],
level2Options: [],
level3Options: [],
nmwCode: "",
};
}
populateLevel(setLevelxOptions: Function, values) {
let results = [];
for (let i in values._array) {
let result = values.item(i);
results.push({ value: result.id, label: result.description });
}
setLevelxOptions(results);
}
render() {
const styling = {
inputAndroid: { color: "black" },
inputIOS: { color: "black" },
viewContainer: {
borderWidth: 1,
padding: 10,
borderRadius: 25,
marginBottom: 10,
},
};
return (
<View style={styles.container}>
<View style={styles.titleContainer}>
<Image source={logo} style={styles.logo} />
<Text style={styles.titleText}>NarrateMyWay Beacon Setup</Text>
</View>
<RNPickerSelect
placeholder={{ value: "", label: "Select a top level category..." }}
onValueChange={(value) => {
this.setState({ level1: value });
if (value != "") {
this.setState({ nmwCode: value });
}
this.storage.lookupCodesByDepth(2, value, (values) =>
this.populateLevel(
(data) => this.setState({ level2Options: data }),
values
)
);
}}
items={this.state.level1Options}
style={styling}
/>
<RNPickerSelect
placeholder={{
value: "",
label: "(Optional) Select a middle level category...",
}}
onValueChange={(value) => {
this.setState({ level2: value });
if (value != "") {
this.setState({ nmwCode: value });
} else {
this.setState({ nmwCode: this.state.level1 });
}
this.storage.lookupCodesByDepth(3, value, (values) =>
this.populateLevel(
(data) => this.setState({ level3Options: data }),
values
)
);
}}
items={this.state.level2Options}
disabled={this.state.level1 == ""}
style={styling}
/>
<RNPickerSelect
placeholder={{
value: "",
label: "(Optional) Select a low level category...",
}}
onValueChange={(value) => {
this.setState({ level3: value });
if (value != "") {
this.setState({ nmwCode: value });
} else if (this.state.level2 != "") {
this.setState({ nmwCode: this.state.level2 });
}
}}
items={this.state.level3Options}
disabled={this.state.level1 == "" || this.state.level2 == ""}
style={styling}
/>
<View style={styles.codeContainer}>
<Text style={styles.codeTitle}>
Tap the code below to copy to clipboard:
</Text>
<Pressable
style={styles.codeTextContainer}
onPress={() => {
if (this.state.level1 != "") {
Clipboard.setString("nmw:" + this.state.nmwCode);
if (Platform.OS === "android") {
ToastAndroid.show(
'Code "nmw:' +
this.state.nmwCode +
'" copied to clipboard!',
ToastAndroid.SHORT
);
}
}
}}
>
<Text style={styles.codeText} adjustsFontSizeToFit>
{this.state.nmwCode == "" ? "-" : "nmw:" + this.state.nmwCode}
</Text>
</Pressable>
</View>
<StatusBar style="auto" />
</View>
);
}
}
export default App;