Browse Source

Improve vote screens to match linter

Arnaud Vergnet 3 years ago
parent
commit
142b861ccb

+ 28
- 26
src/components/Amicale/Vote/VoteNotAvailable.js View File

@@ -2,36 +2,38 @@
2 2
 
3 3
 import * as React from 'react';
4 4
 import {View} from 'react-native';
5
-import {Headline, withTheme} from "react-native-paper";
5
+import {Headline, withTheme} from 'react-native-paper';
6 6
 import i18n from 'i18n-js';
7
-import type {CustomTheme} from "../../../managers/ThemeManager";
7
+import type {CustomTheme} from '../../../managers/ThemeManager';
8 8
 
9
-type Props = {
10
-    theme: CustomTheme
11
-}
12
-
13
-class VoteNotAvailable extends React.Component<Props> {
9
+type PropsType = {
10
+  theme: CustomTheme,
11
+};
14 12
 
15
-    shouldComponentUpdate() {
16
-        return false;
17
-    }
13
+class VoteNotAvailable extends React.Component<PropsType> {
14
+  shouldComponentUpdate(): boolean {
15
+    return false;
16
+  }
18 17
 
19
-    render() {
20
-        return (
21
-            <View style={{
22
-                width: "100%",
23
-                marginTop: 10,
24
-                marginBottom: 10,
25
-            }}>
26
-                <Headline
27
-                    style={{
28
-                        color: this.props.theme.colors.textDisabled,
29
-                        textAlign: "center",
30
-                    }}
31
-                >{i18n.t("screens.vote.noVote")}</Headline>
32
-            </View>
33
-        );
34
-    }
18
+  render(): React.Node {
19
+    const {props} = this;
20
+    return (
21
+      <View
22
+        style={{
23
+          width: '100%',
24
+          marginTop: 10,
25
+          marginBottom: 10,
26
+        }}>
27
+        <Headline
28
+          style={{
29
+            color: props.theme.colors.textDisabled,
30
+            textAlign: 'center',
31
+          }}>
32
+          {i18n.t('screens.vote.noVote')}
33
+        </Headline>
34
+      </View>
35
+    );
36
+  }
35 37
 }
36 38
 
37 39
 export default withTheme(VoteNotAvailable);

+ 114
- 96
src/components/Amicale/Vote/VoteResults.js View File

@@ -1,116 +1,134 @@
1 1
 // @flow
2 2
 
3 3
 import * as React from 'react';
4
-import {Avatar, Card, List, ProgressBar, Subheading, withTheme} from "react-native-paper";
5
-import {FlatList, StyleSheet} from "react-native";
4
+import {
5
+  Avatar,
6
+  Card,
7
+  List,
8
+  ProgressBar,
9
+  Subheading,
10
+  withTheme,
11
+} from 'react-native-paper';
12
+import {FlatList, StyleSheet} from 'react-native';
6 13
 import i18n from 'i18n-js';
7
-import type {team} from "../../../screens/Amicale/VoteScreen";
8
-import type {CustomTheme} from "../../../managers/ThemeManager";
14
+import type {VoteTeamType} from '../../../screens/Amicale/VoteScreen';
15
+import type {CustomTheme} from '../../../managers/ThemeManager';
9 16
 
17
+type PropsType = {
18
+  teams: Array<VoteTeamType>,
19
+  dateEnd: string,
20
+  theme: CustomTheme,
21
+};
10 22
 
11
-type Props = {
12
-    teams: Array<team>,
13
-    dateEnd: string,
14
-    theme: CustomTheme,
15
-}
16
-
17
-class VoteResults extends React.Component<Props> {
23
+const styles = StyleSheet.create({
24
+  card: {
25
+    margin: 10,
26
+  },
27
+  icon: {
28
+    backgroundColor: 'transparent',
29
+  },
30
+});
18 31
 
19
-    totalVotes: number;
20
-    winnerIds: Array<number>;
32
+class VoteResults extends React.Component<PropsType> {
33
+  totalVotes: number;
21 34
 
22
-    constructor(props) {
23
-        super();
24
-        props.teams.sort(this.sortByVotes);
25
-        this.getTotalVotes(props.teams);
26
-        this.getWinnerIds(props.teams);
27
-    }
35
+  winnerIds: Array<number>;
28 36
 
29
-    shouldComponentUpdate() {
30
-        return false;
31
-    }
37
+  constructor(props: PropsType) {
38
+    super();
39
+    props.teams.sort(this.sortByVotes);
40
+    this.getTotalVotes(props.teams);
41
+    this.getWinnerIds(props.teams);
42
+  }
32 43
 
33
-    sortByVotes = (a: team, b: team) => b.votes - a.votes;
44
+  shouldComponentUpdate(): boolean {
45
+    return false;
46
+  }
34 47
 
35
-    getTotalVotes(teams: Array<team>) {
36
-        this.totalVotes = 0;
37
-        for (let i = 0; i < teams.length; i++) {
38
-            this.totalVotes += teams[i].votes;
39
-        }
48
+  getTotalVotes(teams: Array<VoteTeamType>) {
49
+    this.totalVotes = 0;
50
+    for (let i = 0; i < teams.length; i += 1) {
51
+      this.totalVotes += teams[i].votes;
40 52
     }
53
+  }
41 54
 
42
-    getWinnerIds(teams: Array<team>) {
43
-        let max = teams[0].votes;
44
-        this.winnerIds = [];
45
-        for (let i = 0; i < teams.length; i++) {
46
-            if (teams[i].votes === max)
47
-                this.winnerIds.push(teams[i].id);
48
-            else
49
-                break;
50
-        }
55
+  getWinnerIds(teams: Array<VoteTeamType>) {
56
+    const max = teams[0].votes;
57
+    this.winnerIds = [];
58
+    for (let i = 0; i < teams.length; i += 1) {
59
+      if (teams[i].votes === max) this.winnerIds.push(teams[i].id);
60
+      else break;
51 61
     }
62
+  }
52 63
 
53
-    voteKeyExtractor = (item: team) => item.id.toString();
64
+  sortByVotes = (a: VoteTeamType, b: VoteTeamType): number => b.votes - a.votes;
54 65
 
55
-    resultRenderItem = ({item}: { item: team }) => {
56
-        const isWinner = this.winnerIds.indexOf(item.id) !== -1;
57
-        const isDraw = this.winnerIds.length > 1;
58
-        const colors = this.props.theme.colors;
59
-        return (
60
-            <Card style={{
61
-                marginTop: 10,
62
-                elevation: isWinner ? 5 : 3,
63
-            }}>
64
-                <List.Item
65
-                    title={item.name}
66
-                    description={item.votes + ' ' + i18n.t('screens.vote.results.votes')}
67
-                    left={props => isWinner
68
-                        ? <List.Icon {...props} icon={isDraw ? "trophy-outline" : "trophy"} color={colors.primary}/>
69
-                        : null}
70
-                    titleStyle={{
71
-                        color: isWinner
72
-                            ? colors.primary
73
-                            : colors.text
74
-                    }}
75
-                    style={{padding: 0}}
76
-                />
77
-                <ProgressBar progress={item.votes / this.totalVotes} color={colors.primary}/>
78
-            </Card>
79
-        );
80
-    };
66
+  voteKeyExtractor = (item: VoteTeamType): string => item.id.toString();
81 67
 
82
-    render() {
83
-        return (
84
-            <Card style={styles.card}>
85
-                <Card.Title
86
-                    title={i18n.t('screens.vote.results.title')}
87
-                    subtitle={i18n.t('screens.vote.results.subtitle') + ' ' + this.props.dateEnd}
88
-                    left={(props) => <Avatar.Icon
89
-                        {...props}
90
-                        icon={"podium-gold"}
91
-                    />}
92
-                />
93
-                <Card.Content>
94
-                    <Subheading>{i18n.t('screens.vote.results.totalVotes') + ' ' + this.totalVotes}</Subheading>
95
-                    {/*$FlowFixMe*/}
96
-                    <FlatList
97
-                        data={this.props.teams}
98
-                        keyExtractor={this.voteKeyExtractor}
99
-                        renderItem={this.resultRenderItem}
100
-                    />
101
-                </Card.Content>
102
-            </Card>
103
-        );
104
-    }
105
-}
68
+  resultRenderItem = ({item}: {item: VoteTeamType}): React.Node => {
69
+    const isWinner = this.winnerIds.indexOf(item.id) !== -1;
70
+    const isDraw = this.winnerIds.length > 1;
71
+    const {props} = this;
72
+    return (
73
+      <Card
74
+        style={{
75
+          marginTop: 10,
76
+          elevation: isWinner ? 5 : 3,
77
+        }}>
78
+        <List.Item
79
+          title={item.name}
80
+          description={`${item.votes} ${i18n.t('screens.vote.results.votes')}`}
81
+          left={({size}: {size: number}): React.Node =>
82
+            isWinner ? (
83
+              <List.Icon
84
+                size={size}
85
+                icon={isDraw ? 'trophy-outline' : 'trophy'}
86
+                color={props.theme.colors.primary}
87
+              />
88
+            ) : null
89
+          }
90
+          titleStyle={{
91
+            color: isWinner
92
+              ? props.theme.colors.primary
93
+              : props.theme.colors.text,
94
+          }}
95
+          style={{padding: 0}}
96
+        />
97
+        <ProgressBar
98
+          progress={item.votes / this.totalVotes}
99
+          color={props.theme.colors.primary}
100
+        />
101
+      </Card>
102
+    );
103
+  };
106 104
 
107
-const styles = StyleSheet.create({
108
-    card: {
109
-        margin: 10,
110
-    },
111
-    icon: {
112
-        backgroundColor: 'transparent'
113
-    },
114
-});
105
+  render(): React.Node {
106
+    const {props} = this;
107
+    return (
108
+      <Card style={styles.card}>
109
+        <Card.Title
110
+          title={i18n.t('screens.vote.results.title')}
111
+          subtitle={`${i18n.t('screens.vote.results.subtitle')} ${
112
+            props.dateEnd
113
+          }`}
114
+          left={({size}: {size: number}): React.Node => (
115
+            <Avatar.Icon size={size} icon="podium-gold" />
116
+          )}
117
+        />
118
+        <Card.Content>
119
+          <Subheading>{`${i18n.t('screens.vote.results.totalVotes')} ${
120
+            this.totalVotes
121
+          }`}</Subheading>
122
+          {/* $FlowFixMe */}
123
+          <FlatList
124
+            data={props.teams}
125
+            keyExtractor={this.voteKeyExtractor}
126
+            renderItem={this.resultRenderItem}
127
+          />
128
+        </Card.Content>
129
+      </Card>
130
+    );
131
+  }
132
+}
115 133
 
116 134
 export default withTheme(VoteResults);

+ 134
- 125
src/components/Amicale/Vote/VoteSelect.js View File

@@ -1,137 +1,146 @@
1 1
 // @flow
2 2
 
3 3
 import * as React from 'react';
4
-import {Avatar, Button, Card, RadioButton} from "react-native-paper";
5
-import {FlatList, StyleSheet, View} from "react-native";
6
-import ConnectionManager from "../../../managers/ConnectionManager";
7
-import LoadingConfirmDialog from "../../Dialogs/LoadingConfirmDialog";
8
-import ErrorDialog from "../../Dialogs/ErrorDialog";
4
+import {Avatar, Button, Card, RadioButton} from 'react-native-paper';
5
+import {FlatList, StyleSheet, View} from 'react-native';
9 6
 import i18n from 'i18n-js';
10
-import type {team} from "../../../screens/Amicale/VoteScreen";
7
+import ConnectionManager from '../../../managers/ConnectionManager';
8
+import LoadingConfirmDialog from '../../Dialogs/LoadingConfirmDialog';
9
+import ErrorDialog from '../../Dialogs/ErrorDialog';
10
+import type {VoteTeamType} from '../../../screens/Amicale/VoteScreen';
11
+
12
+type PropsType = {
13
+  teams: Array<VoteTeamType>,
14
+  onVoteSuccess: () => void,
15
+  onVoteError: () => void,
16
+};
17
+
18
+type StateType = {
19
+  selectedTeam: string,
20
+  voteDialogVisible: boolean,
21
+  errorDialogVisible: boolean,
22
+  currentError: number,
23
+};
11 24
 
12
-type Props = {
13
-    teams: Array<team>,
14
-    onVoteSuccess: () => void,
15
-    onVoteError: () => void,
16
-}
17
-
18
-type State = {
19
-    selectedTeam: string,
20
-    voteDialogVisible: boolean,
21
-    errorDialogVisible: boolean,
22
-    currentError: number,
23
-}
24
-
25
-
26
-export default class VoteSelect extends React.PureComponent<Props, State> {
25
+const styles = StyleSheet.create({
26
+  card: {
27
+    margin: 10,
28
+  },
29
+  icon: {
30
+    backgroundColor: 'transparent',
31
+  },
32
+});
27 33
 
28
-    state = {
29
-        selectedTeam: "none",
30
-        voteDialogVisible: false,
31
-        errorDialogVisible: false,
32
-        currentError: 0,
34
+export default class VoteSelect extends React.PureComponent<
35
+  PropsType,
36
+  StateType,
37
+> {
38
+  constructor() {
39
+    super();
40
+    this.state = {
41
+      selectedTeam: 'none',
42
+      voteDialogVisible: false,
43
+      errorDialogVisible: false,
44
+      currentError: 0,
33 45
     };
34
-
35
-    onVoteSelectionChange = (team: string) => this.setState({selectedTeam: team});
36
-
37
-    voteKeyExtractor = (item: team) => item.id.toString();
38
-
39
-    voteRenderItem = ({item}: { item: team }) => <RadioButton.Item label={item.name} value={item.id.toString()}/>;
40
-
41
-    showVoteDialog = () => this.setState({voteDialogVisible: true});
42
-
43
-    onVoteDialogDismiss = () => this.setState({voteDialogVisible: false,});
44
-
45
-    onVoteDialogAccept = async () => {
46
-        return new Promise((resolve) => {
47
-            ConnectionManager.getInstance().authenticatedRequest(
48
-                "elections/vote",
49
-                {"team": parseInt(this.state.selectedTeam)})
50
-                .then(() => {
51
-                    this.onVoteDialogDismiss();
52
-                    this.props.onVoteSuccess();
53
-                    resolve();
54
-                })
55
-                .catch((error: number) => {
56
-                    this.onVoteDialogDismiss();
57
-                    this.showErrorDialog(error);
58
-                    resolve();
59
-                });
46
+  }
47
+
48
+  onVoteSelectionChange = (teamName: string): void =>
49
+    this.setState({selectedTeam: teamName});
50
+
51
+  voteKeyExtractor = (item: VoteTeamType): string => item.id.toString();
52
+
53
+  voteRenderItem = ({item}: {item: VoteTeamType}): React.Node => (
54
+    <RadioButton.Item label={item.name} value={item.id.toString()} />
55
+  );
56
+
57
+  showVoteDialog = (): void => this.setState({voteDialogVisible: true});
58
+
59
+  onVoteDialogDismiss = (): void => this.setState({voteDialogVisible: false});
60
+
61
+  onVoteDialogAccept = async (): Promise<void> => {
62
+    return new Promise((resolve: () => void) => {
63
+      const {state} = this;
64
+      ConnectionManager.getInstance()
65
+        .authenticatedRequest('elections/vote', {
66
+          team: parseInt(state.selectedTeam, 10),
67
+        })
68
+        .then(() => {
69
+          this.onVoteDialogDismiss();
70
+          const {props} = this;
71
+          props.onVoteSuccess();
72
+          resolve();
73
+        })
74
+        .catch((error: number) => {
75
+          this.onVoteDialogDismiss();
76
+          this.showErrorDialog(error);
77
+          resolve();
60 78
         });
61
-    };
62
-
63
-    showErrorDialog = (error: number) => this.setState({
64
-        errorDialogVisible: true,
65
-        currentError: error,
66 79
     });
80
+  };
67 81
 
68
-    onErrorDialogDismiss = () => {
69
-        this.setState({errorDialogVisible: false});
70
-        this.props.onVoteError();
71
-    };
82
+  showErrorDialog = (error: number): void =>
83
+    this.setState({
84
+      errorDialogVisible: true,
85
+      currentError: error,
86
+    });
72 87
 
73
-    render() {
74
-        return (
75
-            <View>
76
-                <Card style={styles.card}>
77
-                    <Card.Title
78
-                        title={i18n.t('screens.vote.select.title')}
79
-                        subtitle={i18n.t('screens.vote.select.subtitle')}
80
-                        left={(props) =>
81
-                            <Avatar.Icon
82
-                                {...props}
83
-                                icon={"alert-decagram"}
84
-                            />}
85
-                    />
86
-                    <Card.Content>
87
-                        <RadioButton.Group
88
-                            onValueChange={this.onVoteSelectionChange}
89
-                            value={this.state.selectedTeam}
90
-                        >
91
-                            {/*$FlowFixMe*/}
92
-                            <FlatList
93
-                                data={this.props.teams}
94
-                                keyExtractor={this.voteKeyExtractor}
95
-                                extraData={this.state.selectedTeam}
96
-                                renderItem={this.voteRenderItem}
97
-                            />
98
-                        </RadioButton.Group>
99
-                    </Card.Content>
100
-                    <Card.Actions>
101
-                        <Button
102
-                            icon="send"
103
-                            mode="contained"
104
-                            onPress={this.showVoteDialog}
105
-                            style={{marginLeft: 'auto'}}
106
-                            disabled={this.state.selectedTeam === "none"}
107
-                        >
108
-                            {i18n.t('screens.vote.select.sendButton')}
109
-                        </Button>
110
-                    </Card.Actions>
111
-                </Card>
112
-                <LoadingConfirmDialog
113
-                    visible={this.state.voteDialogVisible}
114
-                    onDismiss={this.onVoteDialogDismiss}
115
-                    onAccept={this.onVoteDialogAccept}
116
-                    title={i18n.t('screens.vote.select.dialogTitle')}
117
-                    titleLoading={i18n.t('screens.vote.select.dialogTitleLoading')}
118
-                    message={i18n.t('screens.vote.select.dialogMessage')}
119
-                />
120
-                <ErrorDialog
121
-                    visible={this.state.errorDialogVisible}
122
-                    onDismiss={this.onErrorDialogDismiss}
123
-                    errorCode={this.state.currentError}
124
-                />
125
-            </View>
126
-        );
127
-    }
88
+  onErrorDialogDismiss = () => {
89
+    this.setState({errorDialogVisible: false});
90
+    const {props} = this;
91
+    props.onVoteError();
92
+  };
93
+
94
+  render(): React.Node {
95
+    const {state, props} = this;
96
+    return (
97
+      <View>
98
+        <Card style={styles.card}>
99
+          <Card.Title
100
+            title={i18n.t('screens.vote.select.title')}
101
+            subtitle={i18n.t('screens.vote.select.subtitle')}
102
+            left={({size}: {size: number}): React.Node => (
103
+              <Avatar.Icon size={size} icon="alert-decagram" />
104
+            )}
105
+          />
106
+          <Card.Content>
107
+            <RadioButton.Group
108
+              onValueChange={this.onVoteSelectionChange}
109
+              value={state.selectedTeam}>
110
+              {/* $FlowFixMe */}
111
+              <FlatList
112
+                data={props.teams}
113
+                keyExtractor={this.voteKeyExtractor}
114
+                extraData={state.selectedTeam}
115
+                renderItem={this.voteRenderItem}
116
+              />
117
+            </RadioButton.Group>
118
+          </Card.Content>
119
+          <Card.Actions>
120
+            <Button
121
+              icon="send"
122
+              mode="contained"
123
+              onPress={this.showVoteDialog}
124
+              style={{marginLeft: 'auto'}}
125
+              disabled={state.selectedTeam === 'none'}>
126
+              {i18n.t('screens.vote.select.sendButton')}
127
+            </Button>
128
+          </Card.Actions>
129
+        </Card>
130
+        <LoadingConfirmDialog
131
+          visible={state.voteDialogVisible}
132
+          onDismiss={this.onVoteDialogDismiss}
133
+          onAccept={this.onVoteDialogAccept}
134
+          title={i18n.t('screens.vote.select.dialogTitle')}
135
+          titleLoading={i18n.t('screens.vote.select.dialogTitleLoading')}
136
+          message={i18n.t('screens.vote.select.dialogMessage')}
137
+        />
138
+        <ErrorDialog
139
+          visible={state.errorDialogVisible}
140
+          onDismiss={this.onErrorDialogDismiss}
141
+          errorCode={state.currentError}
142
+        />
143
+      </View>
144
+    );
145
+  }
128 146
 }
129
-
130
-const styles = StyleSheet.create({
131
-    card: {
132
-        margin: 10,
133
-    },
134
-    icon: {
135
-        backgroundColor: 'transparent'
136
-    },
137
-});

+ 36
- 36
src/components/Amicale/Vote/VoteTease.js View File

@@ -1,45 +1,45 @@
1 1
 // @flow
2 2
 
3 3
 import * as React from 'react';
4
-import {Avatar, Card, Paragraph} from "react-native-paper";
5
-import {StyleSheet} from "react-native";
4
+import {Avatar, Card, Paragraph} from 'react-native-paper';
5
+import {StyleSheet} from 'react-native';
6 6
 import i18n from 'i18n-js';
7 7
 
8
-type Props = {
9
-    startDate: string,
10
-}
8
+type PropsType = {
9
+  startDate: string,
10
+};
11 11
 
12
-export default class VoteTease extends React.Component<Props> {
12
+const styles = StyleSheet.create({
13
+  card: {
14
+    margin: 10,
15
+  },
16
+  icon: {
17
+    backgroundColor: 'transparent',
18
+  },
19
+});
13 20
 
14
-    shouldComponentUpdate() {
15
-        return false;
16
-    }
21
+export default class VoteTease extends React.Component<PropsType> {
22
+  shouldComponentUpdate(): boolean {
23
+    return false;
24
+  }
17 25
 
18
-    render() {
19
-        return (
20
-            <Card style={styles.card}>
21
-                <Card.Title
22
-                    title={i18n.t('screens.vote.tease.title')}
23
-                    subtitle={i18n.t('screens.vote.tease.subtitle')}
24
-                    left={props => <Avatar.Icon
25
-                        {...props}
26
-                        icon="vote"/>}
27
-                />
28
-                <Card.Content>
29
-                    <Paragraph>
30
-                        {i18n.t('screens.vote.tease.message') + ' ' + this.props.startDate}
31
-                    </Paragraph>
32
-                </Card.Content>
33
-            </Card>
34
-        );
35
-    }
26
+  render(): React.Node {
27
+    const {props} = this;
28
+    return (
29
+      <Card style={styles.card}>
30
+        <Card.Title
31
+          title={i18n.t('screens.vote.tease.title')}
32
+          subtitle={i18n.t('screens.vote.tease.subtitle')}
33
+          left={({size}: {size: number}): React.Node => (
34
+            <Avatar.Icon size={size} icon="vote" />
35
+          )}
36
+        />
37
+        <Card.Content>
38
+          <Paragraph>
39
+            {`${i18n.t('screens.vote.tease.message')} ${props.startDate}`}
40
+          </Paragraph>
41
+        </Card.Content>
42
+      </Card>
43
+    );
44
+  }
36 45
 }
37
-
38
-const styles = StyleSheet.create({
39
-    card: {
40
-        margin: 10,
41
-    },
42
-    icon: {
43
-        backgroundColor: 'transparent'
44
-    },
45
-});

+ 67
- 61
src/components/Amicale/Vote/VoteWait.js View File

@@ -1,72 +1,78 @@
1 1
 // @flow
2 2
 
3 3
 import * as React from 'react';
4
-import {ActivityIndicator, Card, Paragraph, withTheme} from "react-native-paper";
5
-import {StyleSheet} from "react-native";
4
+import {
5
+  ActivityIndicator,
6
+  Card,
7
+  Paragraph,
8
+  withTheme,
9
+} from 'react-native-paper';
10
+import {StyleSheet} from 'react-native';
6 11
 import i18n from 'i18n-js';
7
-import type {CustomTheme} from "../../../managers/ThemeManager";
12
+import type {CustomTheme} from '../../../managers/ThemeManager';
8 13
 
9
-type Props = {
10
-    startDate: string | null,
11
-    justVoted: boolean,
12
-    hasVoted: boolean,
13
-    isVoteRunning: boolean,
14
-    theme: CustomTheme,
15
-}
14
+type PropsType = {
15
+  startDate: string | null,
16
+  justVoted: boolean,
17
+  hasVoted: boolean,
18
+  isVoteRunning: boolean,
19
+  theme: CustomTheme,
20
+};
16 21
 
17
-class VoteWait extends React.Component<Props> {
22
+const styles = StyleSheet.create({
23
+  card: {
24
+    margin: 10,
25
+  },
26
+  icon: {
27
+    backgroundColor: 'transparent',
28
+  },
29
+});
18 30
 
19
-    shouldComponentUpdate() {
20
-        return false;
21
-    }
31
+class VoteWait extends React.Component<PropsType> {
32
+  shouldComponentUpdate(): boolean {
33
+    return false;
34
+  }
22 35
 
23
-    render() {
24
-        const colors = this.props.theme.colors;
25
-        const startDate = this.props.startDate;
26
-        return (
27
-            <Card style={styles.card}>
28
-                <Card.Title
29
-                    title={this.props.isVoteRunning
30
-                        ? i18n.t('screens.vote.wait.titleSubmitted')
31
-                        : i18n.t('screens.vote.wait.titleEnded')}
32
-                    subtitle={i18n.t('screens.vote.wait.subtitle')}
33
-                    left={(props) => <ActivityIndicator {...props}/>}
34
-                />
35
-                <Card.Content>
36
-                    {
37
-                        this.props.justVoted
38
-                            ? <Paragraph style={{color: colors.success}}>
39
-                                {i18n.t('screens.vote.wait.messageSubmitted')}
40
-                            </Paragraph>
41
-                            : null
42
-                    }
43
-                    {
44
-                        this.props.hasVoted
45
-                            ? <Paragraph style={{color: colors.success}}>
46
-                                {i18n.t('screens.vote.wait.messageVoted')}
47
-                            </Paragraph>
48
-                            : null
49
-                    }
50
-                    {
51
-                        startDate != null
52
-                            ? <Paragraph>
53
-                                {i18n.t('screens.vote.wait.messageDate') + ' ' + startDate}
54
-                            </Paragraph>
55
-                            : <Paragraph>{i18n.t('screens.vote.wait.messageDateUndefined')}</Paragraph>
56
-                    }
57
-                </Card.Content>
58
-            </Card>
59
-        );
60
-    }
36
+  render(): React.Node {
37
+    const {props} = this;
38
+    const {startDate} = props;
39
+    return (
40
+      <Card style={styles.card}>
41
+        <Card.Title
42
+          title={
43
+            props.isVoteRunning
44
+              ? i18n.t('screens.vote.wait.titleSubmitted')
45
+              : i18n.t('screens.vote.wait.titleEnded')
46
+          }
47
+          subtitle={i18n.t('screens.vote.wait.subtitle')}
48
+          left={({size}: {size: number}): React.Node => (
49
+            <ActivityIndicator size={size} />
50
+          )}
51
+        />
52
+        <Card.Content>
53
+          {props.justVoted ? (
54
+            <Paragraph style={{color: props.theme.colors.success}}>
55
+              {i18n.t('screens.vote.wait.messageSubmitted')}
56
+            </Paragraph>
57
+          ) : null}
58
+          {props.hasVoted ? (
59
+            <Paragraph style={{color: props.theme.colors.success}}>
60
+              {i18n.t('screens.vote.wait.messageVoted')}
61
+            </Paragraph>
62
+          ) : null}
63
+          {startDate != null ? (
64
+            <Paragraph>
65
+              {`${i18n.t('screens.vote.wait.messageDate')} ${startDate}`}
66
+            </Paragraph>
67
+          ) : (
68
+            <Paragraph>
69
+              {i18n.t('screens.vote.wait.messageDateUndefined')}
70
+            </Paragraph>
71
+          )}
72
+        </Card.Content>
73
+      </Card>
74
+    );
75
+  }
61 76
 }
62 77
 
63
-const styles = StyleSheet.create({
64
-    card: {
65
-        margin: 10,
66
-    },
67
-    icon: {
68
-        backgroundColor: 'transparent'
69
-    },
70
-});
71
-
72 78
 export default withTheme(VoteWait);

Loading…
Cancel
Save