This repository has been archived by the owner on Jun 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoti.js
85 lines (76 loc) · 1.84 KB
/
Roti.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
import React, { useEffect, useCallback } from "react";
import { AsyncStorage, Text, View, StyleSheet } from "react-native";
import Button from "./Button";
import {useRotis} from "./useRotis";
function guidGenerator() {
var S4 = function() {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
};
return (
S4() +
S4() +
"-" +
S4() +
"-" +
S4() +
"-" +
S4() +
"-" +
S4() +
S4() +
S4()
);
}
export const NewRotiScreen = ({ navigation }) => {
const [{ current, rotis }, setCurrent, setRotis] = useRotis();
useEffect(() => {
// init new roti entry
const uniqueRotiID = guidGenerator();
const initialRotiValues = {
id: uniqueRotiID,
date: Date.now(),
votes: []
};
setCurrent(initialRotiValues);
}, []);
const setRotiAndNavigate = useCallback(async () => {
setRotis([...rotis, current]);
setCurrent(null);
navigation.navigate("Result");
}, [navigation, current, rotis]);
return (
<View style={styles.top}>
<Text style={styles.titleText}>Pick a value</Text>
<View style={styles.centered}>
{[1, 2, 3, 4, 5].map(score => (
<Button
key={score}
title={score}
onPress={() => {
const { votes, ...rest } = current;
setCurrent({ ...rest, votes: [...votes, score] });
}}
/>
))}
<Button
key="Done"
title="Done"
type="success"
onPress={setRotiAndNavigate}
/>
</View>
</View>
);
};
const styles = StyleSheet.create({
baseText: {
fontFamily: "Cochin",
marginVertical: 20
},
titleText: {
fontSize: 36,
fontWeight: "bold"
},
top: { flex: 1, alignItems: "center", marginTop: 50 },
centered: { flex: 1, justifyContent: "center" }
});