forked from oodminds/Anicca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHomeScreen.jsx
131 lines (123 loc) · 3.01 KB
/
HomeScreen.jsx
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
import React, {useEffect, useState} from 'react';
import {
StyleSheet,
Text,
TextInput,
TouchableOpacity,
View,
} from 'react-native';
import {Rating} from 'react-native-ratings';
import Realm from 'realm';
import {AniccaLog} from './schema/schema';
const HomeScreen = () => {
const [awareness, setAwareness] = useState(0);
const [anicca, setAnicca] = useState(0);
const [comment, setComment] = useState('');
const realm = new Realm({schema: [AniccaLog]});
const logs = realm.objects('aniccaLog');
const saveLog = () => {
realm.write(() => {
const myLog = {
id: Math.floor(Math.random() * 10000000) + 1,
awareness: awareness,
anicca: anicca,
comment: comment,
date: new Date(),
};
realm.create('aniccaLog', myLog);
});
};
useEffect(() => {
console.log('logs', logs);
}, [logs]);
return (
<View style={styles.container}>
<View style={styles.formContainer}>
<View style={styles.rowContainer}>
<Text style={styles.label}>Awareness</Text>
<Rating
showRating={false}
ratingCount={7}
imageSize={32}
tintColor="#E4D8CA"
type="heart"
onFinishRating={rating => setAwareness(rating)}
/>
</View>
<View style={styles.rowContainer}>
<Text style={styles.label}>Anicca</Text>
<Rating
showRating={false}
ratingCount={7}
imageSize={32}
tintColor="#E4D8CA"
type="heart"
onFinishRating={rating => setAnicca(rating)}
/>
</View>
<View style={styles.commentContainer}>
<Text style={styles.label}>Comment</Text>
<TextInput
placeholder="Enter your Comment..."
value={comment}
onChangeText={text => setComment(text)}
style={styles.input}
/>
</View>
<TouchableOpacity
onPress={() => {
saveLog();
setComment('');
}}
style={styles.button}>
<Text style={styles.buttonText}>Submit</Text>
</TouchableOpacity>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#E4D8CA',
justifyContent: 'center',
alignItems: 'center',
},
formContainer: {
padding: 20,
backgroundColor: '#E4D8CA',
},
rowContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: 20,
},
label: {
fontSize: 20,
},
commentContainer: {
flexDirection: 'row',
alignItems: 'center',
marginBottom: 20,
},
input: {
marginLeft: 60,
borderWidth: 1,
width: 220,
paddingLeft: 8,
borderRadius: 5,
},
button: {
backgroundColor: '#646F57',
padding: 10,
justifyContent: 'center',
alignItems: 'center',
borderRadius: 10,
},
buttonText: {
color: 'white',
fontSize: 20,
},
});
export default HomeScreen;