|
@@ -4,12 +4,17 @@ import * as React from 'react';
|
4
|
4
|
import {FlatList, RefreshControl, View} from "react-native";
|
5
|
5
|
import AuthenticatedScreen from "../../components/Amicale/AuthenticatedScreen";
|
6
|
6
|
import {getTimeOnlyString, stringToDate} from "../../utils/Planning";
|
7
|
|
-import VoteTitle from "../../components/Amicale/Vote/VoteTitle";
|
8
|
7
|
import VoteTease from "../../components/Amicale/Vote/VoteTease";
|
9
|
8
|
import VoteSelect from "../../components/Amicale/Vote/VoteSelect";
|
10
|
9
|
import VoteResults from "../../components/Amicale/Vote/VoteResults";
|
11
|
10
|
import VoteWait from "../../components/Amicale/Vote/VoteWait";
|
12
|
11
|
import {StackNavigationProp} from "@react-navigation/stack";
|
|
12
|
+import i18n from "i18n-js";
|
|
13
|
+import {MASCOT_STYLE} from "../../components/Mascot/Mascot";
|
|
14
|
+import MascotPopup from "../../components/Mascot/MascotPopup";
|
|
15
|
+import AsyncStorageManager from "../../managers/AsyncStorageManager";
|
|
16
|
+import {Button} from "react-native-paper";
|
|
17
|
+import VoteNotAvailable from "../../components/Amicale/Vote/VoteNotAvailable";
|
13
|
18
|
|
14
|
19
|
export type team = {
|
15
|
20
|
id: number,
|
|
@@ -37,10 +42,10 @@ type objectVoteDates = {
|
37
|
42
|
}
|
38
|
43
|
|
39
|
44
|
// const FAKE_DATE = {
|
40
|
|
-// "date_begin": "2020-04-19 15:50",
|
41
|
|
-// "date_end": "2020-04-19 15:50",
|
42
|
|
-// "date_result_begin": "2020-04-19 19:50",
|
43
|
|
-// "date_result_end": "2020-04-19 22:50",
|
|
45
|
+// "date_begin": "2020-08-19 15:50",
|
|
46
|
+// "date_end": "2020-08-19 15:50",
|
|
47
|
+// "date_result_begin": "2020-08-19 19:50",
|
|
48
|
+// "date_result_end": "2020-08-19 22:50",
|
44
|
49
|
// };
|
45
|
50
|
//
|
46
|
51
|
// const FAKE_DATE2 = {
|
|
@@ -92,6 +97,7 @@ type Props = {
|
92
|
97
|
|
93
|
98
|
type State = {
|
94
|
99
|
hasVoted: boolean,
|
|
100
|
+ mascotDialogVisible: boolean,
|
95
|
101
|
}
|
96
|
102
|
|
97
|
103
|
/**
|
|
@@ -101,6 +107,7 @@ export default class VoteScreen extends React.Component<Props, State> {
|
101
|
107
|
|
102
|
108
|
state = {
|
103
|
109
|
hasVoted: false,
|
|
110
|
+ mascotDialogVisible: AsyncStorageManager.getInstance().preferences.voteShowBanner.current === "1",
|
104
|
111
|
};
|
105
|
112
|
|
106
|
113
|
teams: Array<team>;
|
|
@@ -200,11 +207,23 @@ export default class VoteScreen extends React.Component<Props, State> {
|
200
|
207
|
|
201
|
208
|
mainRenderItem = ({item}: { item: { key: string } }) => {
|
202
|
209
|
if (item.key === 'info')
|
203
|
|
- return <VoteTitle/>;
|
204
|
|
- else if (item.key === 'main' && this.dates != null)
|
205
|
|
- return this.getContent();
|
|
210
|
+ return (
|
|
211
|
+ <View>
|
|
212
|
+ <Button
|
|
213
|
+ mode={"contained"}
|
|
214
|
+ icon={"help-circle"}
|
|
215
|
+ onPress={this.showMascotDialog}
|
|
216
|
+ style={{
|
|
217
|
+ marginLeft: "auto",
|
|
218
|
+ marginRight: "auto",
|
|
219
|
+ marginTop: 20
|
|
220
|
+ }}>
|
|
221
|
+ {i18n.t("screens.vote.mascotDialog.title")}
|
|
222
|
+ </Button>
|
|
223
|
+ </View>
|
|
224
|
+ );
|
206
|
225
|
else
|
207
|
|
- return null;
|
|
226
|
+ return this.getContent();
|
208
|
227
|
};
|
209
|
228
|
|
210
|
229
|
getScreen = (data: Array<{ [key: string]: any } | null>) => {
|
|
@@ -254,7 +273,7 @@ export default class VoteScreen extends React.Component<Props, State> {
|
254
|
273
|
else if (this.isResultRunning())
|
255
|
274
|
return this.getVoteResultCard();
|
256
|
275
|
else
|
257
|
|
- return null;
|
|
276
|
+ return <VoteNotAvailable/>;
|
258
|
277
|
}
|
259
|
278
|
|
260
|
279
|
onVoteSuccess = () => this.setState({hasVoted: true});
|
|
@@ -278,7 +297,7 @@ export default class VoteScreen extends React.Component<Props, State> {
|
278
|
297
|
this.datesString.date_result_end)}
|
279
|
298
|
/>;
|
280
|
299
|
else
|
281
|
|
- return null;
|
|
300
|
+ return <VoteNotAvailable/>;
|
282
|
301
|
}
|
283
|
302
|
|
284
|
303
|
/**
|
|
@@ -289,7 +308,7 @@ export default class VoteScreen extends React.Component<Props, State> {
|
289
|
308
|
return <VoteTease
|
290
|
309
|
startDate={this.getDateString(this.dates.date_begin, this.datesString.date_begin)}/>;
|
291
|
310
|
else
|
292
|
|
- return null;
|
|
311
|
+ return <VoteNotAvailable/>;
|
293
|
312
|
}
|
294
|
313
|
|
295
|
314
|
/**
|
|
@@ -304,6 +323,18 @@ export default class VoteScreen extends React.Component<Props, State> {
|
304
|
323
|
isVoteRunning={this.isVoteRunning()}/>;
|
305
|
324
|
}
|
306
|
325
|
|
|
326
|
+ showMascotDialog = () => {
|
|
327
|
+ this.setState({mascotDialogVisible: true})
|
|
328
|
+ };
|
|
329
|
+
|
|
330
|
+ hideMascotDialog = () => {
|
|
331
|
+ AsyncStorageManager.getInstance().savePref(
|
|
332
|
+ AsyncStorageManager.getInstance().preferences.voteShowBanner.key,
|
|
333
|
+ '0'
|
|
334
|
+ );
|
|
335
|
+ this.setState({mascotDialogVisible: false})
|
|
336
|
+ };
|
|
337
|
+
|
307
|
338
|
/**
|
308
|
339
|
* Renders the authenticated screen.
|
309
|
340
|
*
|
|
@@ -313,23 +344,40 @@ export default class VoteScreen extends React.Component<Props, State> {
|
313
|
344
|
*/
|
314
|
345
|
render() {
|
315
|
346
|
return (
|
316
|
|
- <AuthenticatedScreen
|
317
|
|
- {...this.props}
|
318
|
|
- ref={this.authRef}
|
319
|
|
- requests={[
|
320
|
|
- {
|
321
|
|
- link: 'elections/teams',
|
322
|
|
- params: {},
|
323
|
|
- mandatory: false,
|
324
|
|
- },
|
325
|
|
- {
|
326
|
|
- link: 'elections/dates',
|
327
|
|
- params: {},
|
328
|
|
- mandatory: false,
|
329
|
|
- },
|
330
|
|
- ]}
|
331
|
|
- renderFunction={this.getScreen}
|
332
|
|
- />
|
|
347
|
+ <View style={{flex: 1}}>
|
|
348
|
+ <AuthenticatedScreen
|
|
349
|
+ {...this.props}
|
|
350
|
+ ref={this.authRef}
|
|
351
|
+ requests={[
|
|
352
|
+ {
|
|
353
|
+ link: 'elections/teams',
|
|
354
|
+ params: {},
|
|
355
|
+ mandatory: false,
|
|
356
|
+ },
|
|
357
|
+ {
|
|
358
|
+ link: 'elections/dates',
|
|
359
|
+ params: {},
|
|
360
|
+ mandatory: false,
|
|
361
|
+ },
|
|
362
|
+ ]}
|
|
363
|
+ renderFunction={this.getScreen}
|
|
364
|
+ />
|
|
365
|
+ <MascotPopup
|
|
366
|
+ visible={this.state.mascotDialogVisible}
|
|
367
|
+ title={i18n.t("screens.vote.mascotDialog.title")}
|
|
368
|
+ message={i18n.t("screens.vote.mascotDialog.message")}
|
|
369
|
+ icon={"vote"}
|
|
370
|
+ buttons={{
|
|
371
|
+ action: null,
|
|
372
|
+ cancel: {
|
|
373
|
+ message: i18n.t("screens.vote.mascotDialog.button"),
|
|
374
|
+ icon: "check",
|
|
375
|
+ onPress: this.hideMascotDialog,
|
|
376
|
+ }
|
|
377
|
+ }}
|
|
378
|
+ emotion={MASCOT_STYLE.CUTE}
|
|
379
|
+ />
|
|
380
|
+ </View>
|
333
|
381
|
);
|
334
|
382
|
}
|
335
|
383
|
}
|