-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
HowYaDoinScreen.tsx
193 lines (174 loc) Β· 5.06 KB
/
HowYaDoinScreen.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import React from "react";
import theme from "../theme";
import {
Container,
MediumHeader,
HintHeader,
RoundedSelectorButton,
SubHeader,
ActionButton,
} from "../ui";
import ScreenProps from "../ScreenProps";
import Constants from "expo-constants";
import {
ScrollView,
KeyboardAvoidingView,
TextInput,
View,
} from "react-native";
import haptic from "../haptic";
import * as Haptic from "expo-haptics";
import {
newCheckup,
saveCheckup,
Checkup,
saveNextCheckupDate,
} from "./checkupstore";
import { textInputStyle, textInputPlaceholderColor } from "../textInputStyle";
import { get } from "lodash";
import { MAIN_SCREEN } from "../screens";
import dayjs from "dayjs";
import { CHECKUP_ONESIGNAL_TEMPLATE } from "../main/followups/templates";
import { userFinishedCheckup } from "../stats";
import scheduleNotification from "../notifications/scheduleNotification";
import { CHECKUP_REDIRECT_SCREEN } from "./screens";
import { scheduleBoost } from "../main/pulse/pulsestore";
import { COMPLETE_CHECKUP, FELT_BETTER } from "../main/pulse/constants";
export default class HowYaDoinScreen extends React.Component<
ScreenProps,
{
checkup: Checkup | null;
}
> {
static navigationOptions = {
header: null,
};
state = {
checkup: newCheckup(),
};
refresh = args => {
const checkup = get(args, "action.params.checkup");
if (checkup) {
this.setState({
checkup,
});
}
};
componentDidMount() {
this.props.navigation.addListener("willFocus", this.refresh);
this.props.navigation.addListener("didFocus", this.refresh);
}
onNext = async () => {
if (this.state.checkup.currentMood === "unselected") {
return;
}
haptic.notification(Haptic.NotificationFeedbackType.Success);
await saveCheckup(this.state.checkup);
await scheduleBoost(COMPLETE_CHECKUP);
if (this.state.checkup.currentMood === "good") {
await scheduleBoost(FELT_BETTER);
}
const nextCheckupDate = dayjs()
.add(1, "week")
.toISOString();
await saveNextCheckupDate(nextCheckupDate);
scheduleNotification(nextCheckupDate, CHECKUP_ONESIGNAL_TEMPLATE);
userFinishedCheckup(this.state.checkup.currentMood);
if (this.state.checkup.currentMood === "bad") {
this.props.navigation.navigate(CHECKUP_REDIRECT_SCREEN);
return;
}
this.props.navigation.navigate(MAIN_SCREEN);
};
onFeeling = async (mood: "good" | "neutral" | "bad") => {
haptic.impact(Haptic.ImpactFeedbackStyle.Light);
this.setState(prevState => {
if (!prevState.checkup) {
return prevState;
}
prevState.checkup.currentMood = mood;
return prevState;
});
};
onChangeNote = (note: string) => {
this.setState(prevState => {
if (!prevState.checkup) {
return prevState;
}
prevState.checkup.note = note;
return prevState;
});
};
render() {
return (
<Container
style={{
paddingTop: 24 + Constants.statusBarHeight,
backgroundColor: theme.lightOffwhite,
flex: 1,
}}
>
<ScrollView>
<KeyboardAvoidingView
behavior="position"
style={{
paddingBottom: 128,
}}
>
<MediumHeader>How has it been going?</MediumHeader>
<HintHeader
style={{
marginBottom: 24,
}}
>
Be honest, Quirk adapts based on how you're doing.
</HintHeader>
<RoundedSelectorButton
title="It's going well π"
onPress={() => this.onFeeling("good")}
selected={this.state.checkup.currentMood === "good"}
/>
<RoundedSelectorButton
title="It's going okay π€·β"
onPress={() => this.onFeeling("neutral")}
selected={this.state.checkup.currentMood === "neutral"}
/>
<RoundedSelectorButton
title="It's going poorly π"
onPress={() => this.onFeeling("bad")}
selected={this.state.checkup.currentMood === "bad"}
/>
<SubHeader
style={{
marginTop: 24,
}}
>
Add a note (optional)
</SubHeader>
<View
style={{
marginBottom: 24,
}}
>
<TextInput
style={textInputStyle}
placeholderTextColor={textInputPlaceholderColor}
placeholder={"The past few days have been..."}
value={this.state.checkup.note}
multiline={true}
numberOfLines={6}
onChangeText={this.onChangeNote}
/>
</View>
<ActionButton
title="Finish"
width="100%"
disabled={this.state.checkup.currentMood === "unselected"}
onPress={this.onNext}
/>
</KeyboardAvoidingView>
</ScrollView>
</Container>
);
}
}