-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyInfo.js
More file actions
141 lines (134 loc) · 4.02 KB
/
myInfo.js
File metadata and controls
141 lines (134 loc) · 4.02 KB
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 from "react";
import { StyleSheet, Text, View, Image, TouchableOpacity, SafeAreaView, TextInput,
} from "react-native";
import { useState, useEffect } from "react";
import AvailabilitySelector from "../components/AvailabilitySelector";
import AsyncStorage from '@react-native-async-storage/async-storage';
export default function myInfo(props) {
const [availabilityShown, showAvailability] = useState(false);
useEffect(() => {
const time = new Date();
props.setNowInterval(
Math.floor((time.getHours() * 60 + time.getMinutes()) / 30)
);
}, []);
setValuesAsync = async (dryPower, washPower, dryTime, washTime) => {
try {
await AsyncStorage.setItem('@dryerPower', dryPower.toString())
await AsyncStorage.setItem('@washerPower', washPower.toString())
await AsyncStorage.setItem('@dryerTime', dryTime.toString())
await AsyncStorage.setItem('@washerTime', washTime.toString())
} catch(e) {
// save error
}
}
// write 4 numerical inputs to persistent storage when leaving the page
async function goHome() {
await setValuesAsync(props.dryPower, props.washPower, props.dryTime, props.washTime)
.then(() => props.goHome())
}
return (
<SafeAreaView style={styles.container}>
<View style={styles.backButtonRow}>
<TouchableOpacity
style={styles.backButton}
activeOpacity={0.5}
onPress={() => goHome()}
>
<Image
source={require("../assets/return.jpg")}
/>
</TouchableOpacity>
<Text style={styles.backButtonText}>My Info</Text>
</View>
<Text
onPress={() => showAvailability(!availabilityShown)}
style={styles.headers}
>
My Free Hours
</Text>
{availabilityShown && (
<View style={{ maxHeight: 500, minHeight: 300 }}>
<AvailabilitySelector
day={props.day}
setDay={props.setDay}
freeIntervals={props.freeIntervals}
setFreeIntervals={props.setFreeIntervals}
nowInterval={props.nowInterval}
/>
</View>
)}
<Text style={styles.headers}>Wash Time (Minutes)</Text>
<TextInput
style={styles.input}
onChangeText={(text) => props.setWashTime(text ? parseInt(text) : 0)}
value={props.washTime.toString()}
placeholder="Wash Time"
keyboardType="numeric"
/>
<Text style={styles.headers}>Dry Time (Minutes)</Text>
<TextInput
style={styles.input}
onChangeText={(text) => props.setDryTime(text ? parseInt(text) : 0)}
value={props.dryTime.toString()}
placeholder="Dry Time"
keyboardType="numeric"
/>
<Text style={styles.headers}>Washing Machine Power (W)</Text>
<TextInput
style={styles.input}
onChangeText={(text) => props.setWashPower(text ? parseInt(text) : 0)}
value={props.washPower.toString()}
placeholder="Washer Power"
keyboardType="numeric"
/>
<Text style={styles.headers}>Dryer Power (W)</Text>
<TextInput
style={styles.input}
onChangeText={(text) => props.setDryPower(text ? parseInt(text) : 0)}
value={props.dryPower.toString()}
placeholder="Dryer Power"
keyboardType="numeric"
/>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "flex-start",
},
input: {
height: 50,
width: 80,
textAlign: "center",
fontFamily: "nunito-regular",
marginTop: 5,
borderWidth: 1,
padding: 10,
backgroundColor: "#D9D9D9",
borderRadius: 50,
},
backButton: {
left: 15,
marginRight: "auto"
},
backButtonText: {
fontFamily: "Nunito-ExtraBold",
fontSize: 48,
marginRight: "30%",
},
backButtonRow: {
flexDirection: "row",
alignItems: "center",
width: "100%",
marginBottom: 10
},
headers: {
fontSize: 24,
fontFamily: "nunito-regular",
marginTop: 25
},
});