|
@@ -10,53 +10,78 @@ import VoteSelect from "../../components/Amicale/Vote/VoteSelect";
|
10
|
10
|
import VoteResults from "../../components/Amicale/Vote/VoteResults";
|
11
|
11
|
import VoteWait from "../../components/Amicale/Vote/VoteWait";
|
12
|
12
|
|
13
|
|
-const FAKE_DATE = {
|
14
|
|
- "date_begin": "2020-04-09 15:50",
|
15
|
|
- "date_end": "2020-04-09 15:50",
|
16
|
|
- "date_result_begin": "2020-04-09 15:50",
|
17
|
|
- "date_result_end": "2020-04-09 22:50",
|
18
|
|
-};
|
|
13
|
+export type team = {
|
|
14
|
+ id: number,
|
|
15
|
+ name: string,
|
|
16
|
+ votes: number,
|
|
17
|
+}
|
19
|
18
|
|
20
|
|
-const FAKE_DATE2 = {
|
21
|
|
- "date_begin": null,
|
22
|
|
- "date_end": null,
|
23
|
|
- "date_result_begin": null,
|
24
|
|
- "date_result_end": null,
|
|
19
|
+type teamResponse = {
|
|
20
|
+ has_voted: boolean,
|
|
21
|
+ teams: Array<team>,
|
25
|
22
|
};
|
26
|
23
|
|
27
|
|
-const FAKE_TEAMS = {
|
28
|
|
- has_voted: false,
|
29
|
|
- teams: [
|
30
|
|
- {
|
31
|
|
- id: 1,
|
32
|
|
- name: "TEST TEAM1",
|
33
|
|
- },
|
34
|
|
- {
|
35
|
|
- id: 2,
|
36
|
|
- name: "TEST TEAM2",
|
37
|
|
- },
|
38
|
|
- ],
|
39
|
|
-};
|
40
|
|
-const FAKE_TEAMS2 = {
|
41
|
|
- has_voted: false,
|
42
|
|
- teams: [
|
43
|
|
- {
|
44
|
|
- id: 1,
|
45
|
|
- name: "TEST TEAM1",
|
46
|
|
- votes: 9,
|
47
|
|
- },
|
48
|
|
- {
|
49
|
|
- id: 2,
|
50
|
|
- name: "TEST TEAM2",
|
51
|
|
- votes: 9,
|
52
|
|
- },
|
53
|
|
- {
|
54
|
|
- id: 3,
|
55
|
|
- name: "TEST TEAM3",
|
56
|
|
- votes: 5,
|
57
|
|
- },
|
58
|
|
- ],
|
59
|
|
-};
|
|
24
|
+type stringVoteDates = {
|
|
25
|
+ date_begin: string,
|
|
26
|
+ date_end: string,
|
|
27
|
+ date_result_begin: string,
|
|
28
|
+ date_result_end: string,
|
|
29
|
+}
|
|
30
|
+
|
|
31
|
+type objectVoteDates = {
|
|
32
|
+ date_begin: Date,
|
|
33
|
+ date_end: Date,
|
|
34
|
+ date_result_begin: Date,
|
|
35
|
+ date_result_end: Date,
|
|
36
|
+}
|
|
37
|
+
|
|
38
|
+// const FAKE_DATE = {
|
|
39
|
+// "date_begin": "2020-04-19 15:50",
|
|
40
|
+// "date_end": "2020-04-19 15:50",
|
|
41
|
+// "date_result_begin": "2020-04-19 19:50",
|
|
42
|
+// "date_result_end": "2020-04-19 22:50",
|
|
43
|
+// };
|
|
44
|
+//
|
|
45
|
+// const FAKE_DATE2 = {
|
|
46
|
+// "date_begin": null,
|
|
47
|
+// "date_end": null,
|
|
48
|
+// "date_result_begin": null,
|
|
49
|
+// "date_result_end": null,
|
|
50
|
+// };
|
|
51
|
+//
|
|
52
|
+// const FAKE_TEAMS = {
|
|
53
|
+// has_voted: false,
|
|
54
|
+// teams: [
|
|
55
|
+// {
|
|
56
|
+// id: 1,
|
|
57
|
+// name: "TEST TEAM1",
|
|
58
|
+// },
|
|
59
|
+// {
|
|
60
|
+// id: 2,
|
|
61
|
+// name: "TEST TEAM2",
|
|
62
|
+// },
|
|
63
|
+// ],
|
|
64
|
+// };
|
|
65
|
+// const FAKE_TEAMS2 = {
|
|
66
|
+// has_voted: false,
|
|
67
|
+// teams: [
|
|
68
|
+// {
|
|
69
|
+// id: 1,
|
|
70
|
+// name: "TEST TEAM1",
|
|
71
|
+// votes: 9,
|
|
72
|
+// },
|
|
73
|
+// {
|
|
74
|
+// id: 2,
|
|
75
|
+// name: "TEST TEAM2",
|
|
76
|
+// votes: 9,
|
|
77
|
+// },
|
|
78
|
+// {
|
|
79
|
+// id: 3,
|
|
80
|
+// name: "TEST TEAM3",
|
|
81
|
+// votes: 5,
|
|
82
|
+// },
|
|
83
|
+// ],
|
|
84
|
+// };
|
60
|
85
|
|
61
|
86
|
const MIN_REFRESH_TIME = 5 * 1000;
|
62
|
87
|
|
|
@@ -74,17 +99,17 @@ export default class VoteScreen extends React.Component<Props, State> {
|
74
|
99
|
hasVoted: false,
|
75
|
100
|
};
|
76
|
101
|
|
77
|
|
- teams: Array<Object>;
|
|
102
|
+ teams: Array<team>;
|
78
|
103
|
hasVoted: boolean;
|
79
|
|
- datesString: Object;
|
80
|
|
- dates: Object;
|
|
104
|
+ datesString: null | stringVoteDates;
|
|
105
|
+ dates: null | objectVoteDates;
|
81
|
106
|
|
82
|
107
|
today: Date;
|
83
|
108
|
|
84
|
|
- mainFlatListData: Array<Object>;
|
|
109
|
+ mainFlatListData: Array<{ key: string }>;
|
85
|
110
|
lastRefresh: Date;
|
86
|
111
|
|
87
|
|
- authRef: Object;
|
|
112
|
+ authRef: { current: null | AuthenticatedScreen };
|
88
|
113
|
|
89
|
114
|
constructor() {
|
90
|
115
|
super();
|
|
@@ -103,69 +128,81 @@ export default class VoteScreen extends React.Component<Props, State> {
|
103
|
128
|
canRefresh = (new Date().getTime() - this.lastRefresh.getTime()) > MIN_REFRESH_TIME;
|
104
|
129
|
else
|
105
|
130
|
canRefresh = true;
|
106
|
|
- if (canRefresh)
|
|
131
|
+ if (canRefresh && this.authRef.current != null)
|
107
|
132
|
this.authRef.current.reload()
|
108
|
133
|
};
|
109
|
134
|
|
110
|
135
|
generateDateObject() {
|
111
|
|
- this.dates = {
|
112
|
|
- date_begin: stringToDate(this.datesString.date_begin),
|
113
|
|
- date_end: stringToDate(this.datesString.date_end),
|
114
|
|
- date_result_begin: stringToDate(this.datesString.date_result_begin),
|
115
|
|
- date_result_end: stringToDate(this.datesString.date_result_end),
|
116
|
|
- };
|
|
136
|
+ const strings = this.datesString;
|
|
137
|
+ if (strings != null) {
|
|
138
|
+ const dateBegin = stringToDate(strings.date_begin);
|
|
139
|
+ const dateEnd = stringToDate(strings.date_end);
|
|
140
|
+ const dateResultBegin = stringToDate(strings.date_result_begin);
|
|
141
|
+ const dateResultEnd = stringToDate(strings.date_result_end);
|
|
142
|
+ if (dateBegin != null && dateEnd != null && dateResultBegin != null && dateResultEnd != null) {
|
|
143
|
+ this.dates = {
|
|
144
|
+ date_begin: dateBegin,
|
|
145
|
+ date_end: dateEnd,
|
|
146
|
+ date_result_begin: dateResultBegin,
|
|
147
|
+ date_result_end: dateResultEnd,
|
|
148
|
+ };
|
|
149
|
+ } else
|
|
150
|
+ this.dates = null;
|
|
151
|
+ } else
|
|
152
|
+ this.dates = null;
|
117
|
153
|
}
|
118
|
154
|
|
119
|
155
|
getDateString(date: Date, dateString: string): string {
|
120
|
156
|
if (this.today.getDate() === date.getDate()) {
|
121
|
157
|
const str = getTimeOnlyString(dateString);
|
122
|
|
- return str !== null ? str : "";
|
|
158
|
+ return str != null ? str : "";
|
123
|
159
|
} else
|
124
|
160
|
return dateString;
|
125
|
161
|
}
|
126
|
162
|
|
127
|
|
- isVoteAvailable() {
|
128
|
|
- return this.dates.date_begin !== null;
|
129
|
|
- }
|
130
|
|
-
|
131
|
163
|
isVoteRunning() {
|
132
|
|
- return this.today > this.dates.date_begin && this.today < this.dates.date_end;
|
|
164
|
+ return this.dates != null && this.today > this.dates.date_begin && this.today < this.dates.date_end;
|
133
|
165
|
}
|
134
|
166
|
|
135
|
167
|
isVoteStarted() {
|
136
|
|
- return this.today > this.dates.date_begin;
|
|
168
|
+ return this.dates != null && this.today > this.dates.date_begin;
|
137
|
169
|
}
|
138
|
170
|
|
139
|
171
|
isResultRunning() {
|
140
|
|
- return this.today > this.dates.date_result_begin && this.today < this.dates.date_result_end;
|
|
172
|
+ return this.dates != null && this.today > this.dates.date_result_begin && this.today < this.dates.date_result_end;
|
141
|
173
|
}
|
142
|
174
|
|
143
|
175
|
isResultStarted() {
|
144
|
|
- return this.today > this.dates.date_result_begin;
|
|
176
|
+ return this.dates != null && this.today > this.dates.date_result_begin;
|
145
|
177
|
}
|
146
|
178
|
|
147
|
179
|
mainRenderItem = ({item}: Object) => {
|
148
|
180
|
if (item.key === 'info')
|
149
|
181
|
return <VoteTitle/>;
|
150
|
|
- else if (item.key === 'main' && this.isVoteAvailable())
|
|
182
|
+ else if (item.key === 'main' && this.dates != null)
|
151
|
183
|
return this.getContent();
|
152
|
184
|
else
|
153
|
185
|
return null;
|
154
|
186
|
};
|
155
|
187
|
|
156
|
|
- getScreen = (data: Array<Object | null>) => {
|
|
188
|
+ getScreen = (data: Array<{ [key: string]: any } | null>) => {
|
157
|
189
|
// data[0] = FAKE_TEAMS2;
|
158
|
190
|
// data[1] = FAKE_DATE;
|
159
|
191
|
this.lastRefresh = new Date();
|
160
|
192
|
|
161
|
|
- if (data[1] === null)
|
162
|
|
- data[1] = {date_begin: null};
|
|
193
|
+ const teams : teamResponse | null = data[0];
|
|
194
|
+ const dateStrings : stringVoteDates | null = data[1];
|
163
|
195
|
|
164
|
|
- if (data[0] !== null) {
|
165
|
|
- this.teams = data[0].teams;
|
166
|
|
- this.hasVoted = data[0].has_voted;
|
|
196
|
+ if (dateStrings != null && dateStrings.date_begin == null)
|
|
197
|
+ this.datesString = null;
|
|
198
|
+ else
|
|
199
|
+ this.datesString = dateStrings;
|
|
200
|
+
|
|
201
|
+ if (teams != null) {
|
|
202
|
+ this.teams = teams.teams;
|
|
203
|
+ this.hasVoted = teams.has_voted;
|
167
|
204
|
}
|
168
|
|
- this.datesString = data[1];
|
|
205
|
+
|
169
|
206
|
this.generateDateObject();
|
170
|
207
|
return (
|
171
|
208
|
<View>
|
|
@@ -211,15 +248,26 @@ export default class VoteScreen extends React.Component<Props, State> {
|
211
|
248
|
* Votes have ended, results can be displayed
|
212
|
249
|
*/
|
213
|
250
|
getVoteResultCard() {
|
214
|
|
- return <VoteResults teams={this.teams}
|
215
|
|
- dateEnd={this.getDateString(this.dates.date_result_end, this.datesString.date_result_end)}/>;
|
|
251
|
+ if (this.dates != null && this.datesString != null)
|
|
252
|
+ return <VoteResults
|
|
253
|
+ teams={this.teams}
|
|
254
|
+ dateEnd={this.getDateString(
|
|
255
|
+ this.dates.date_result_end,
|
|
256
|
+ this.datesString.date_result_end)}
|
|
257
|
+ />;
|
|
258
|
+ else
|
|
259
|
+ return null;
|
216
|
260
|
}
|
217
|
261
|
|
218
|
262
|
/**
|
219
|
263
|
* Vote will open shortly
|
220
|
264
|
*/
|
221
|
265
|
getTeaseVoteCard() {
|
222
|
|
- return <VoteTease startDate={this.getDateString(this.dates.date_begin, this.datesString.date_begin)}/>;
|
|
266
|
+ if (this.dates != null && this.datesString != null)
|
|
267
|
+ return <VoteTease
|
|
268
|
+ startDate={this.getDateString(this.dates.date_begin, this.datesString.date_begin)}/>;
|
|
269
|
+ else
|
|
270
|
+ return null;
|
223
|
271
|
}
|
224
|
272
|
|
225
|
273
|
/**
|
|
@@ -227,7 +275,7 @@ export default class VoteScreen extends React.Component<Props, State> {
|
227
|
275
|
*/
|
228
|
276
|
getWaitVoteCard() {
|
229
|
277
|
let startDate = null;
|
230
|
|
- if (this.dates.date_result_begin !== null)
|
|
278
|
+ if (this.dates != null && this.datesString != null && this.dates.date_result_begin != null)
|
231
|
279
|
startDate = this.getDateString(this.dates.date_result_begin, this.datesString.date_result_begin);
|
232
|
280
|
return <VoteWait startDate={startDate} hasVoted={this.hasVoted || this.state.hasVoted}
|
233
|
281
|
justVoted={this.state.hasVoted}
|