-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
141 lines (129 loc) · 3.33 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
import React, { useState } from "react";
import { Text, StyleSheet, View, FlatList } from "react-native";
import {
TouchableRipple,
DefaultTheme,
Provider as PaperProvider,
Appbar,
TextInput,
Button,
List,
Portal,
Dialog,
Paragraph
} from "react-native-paper";
import WordItem from "./components/WordItem";
import UserInput from "./components/UserInput";
export default function App() {
const [codes, setCodes] = useState([]);
const [isHelpVisible, setHelpVisible] = useState(false);
const [isAddMode, setAddMode] = useState(false);
const addWordHandler = word => {
if (word.length > 0) {
newWord = word.split("").map(char => {
return ICAO.has(char.toUpperCase())
? ICAO.get(char.toUpperCase())
: char;
});
setCodes(newWord);
setAddMode(false);
}
};
const showDialog = () => {
setHelpVisible(true);
console.log(isHelpVisible);
};
const hideDialog = () => setHelpVisible(false);
const ICAO = new Map(
Object.entries({
A: "Alfa",
B: "Bravo",
C: "Charlie",
D: "Delta",
E: "Echo",
F: "Foxtrot",
G: "Golf",
H: "Hotel",
I: "India",
J: "Juliett",
K: "Kilo",
L: "Lima",
M: "Mike",
N: "November",
O: "Oscar",
P: "Papa",
Q: "Quebec",
R: "Romeo",
S: "Sierra",
T: "Tango",
U: "Uniform",
V: "Victor",
W: "Whiskey",
X: "X-ray",
Y: "Yankee",
Z: "Zulu"
})
);
const cancelAddWordHandler = () => setAddMode(false);
return (
<PaperProvider theme={theme}>
<Appbar.Header>
<Appbar.Content title="Clear Spell" color="white" />
<Appbar.Action icon="help-outline" color="white" onPress={showDialog} />
<Portal>
<Dialog
dismissable={true}
visible={isHelpVisible}
onDismiss={hideDialog}
>
<Dialog.Title>What's This?</Dialog.Title>
<Dialog.Content>
<Paragraph>
When you need to spell information like your name, email or home
address over the phone – use the NATO Phonetic Alphabet. This
phonetic alphabets – also called spelling alphabets –– replace
the 26 letters of the English alphabet with 26 code words.
</Paragraph>
</Dialog.Content>
<Dialog.Actions>
<Button onPress={hideDialog}>Done</Button>
</Dialog.Actions>
</Dialog>
</Portal>
</Appbar.Header>
<View style={styles.screen}>
<Button onPress={() => setAddMode(true)}>SPELL NOW</Button>
<UserInput
visible={isAddMode}
onWordSubmit={addWordHandler}
onCancel={cancelAddWordHandler}
/>
<View style={styles.flatListContainer}>
<FlatList
keyExtractor={() => Math.random().toString()}
data={codes}
renderItem={itemData => <WordItem title={itemData.item} />}
/>
</View>
</View>
</PaperProvider>
);
}
const theme = {
...DefaultTheme,
roundness: 2,
colors: {
...DefaultTheme.colors,
primary: "#ff4081",
accent: "#f1c40h"
}
};
const styles = StyleSheet.create({
screen: {
padding: 10,
flex: 1
},
flatListContainer: {
flex: 1
}
});