|
@@ -1,267 +0,0 @@
|
1
|
|
-// @flow
|
2
|
|
-
|
3
|
|
-import * as React from 'react';
|
4
|
|
-import {Dimensions, FlatList, Image, StyleSheet, View,} from 'react-native';
|
5
|
|
-import i18n from "i18n-js";
|
6
|
|
-import {TouchableRipple} from "react-native-paper";
|
7
|
|
-import ConnectionManager from "../../managers/ConnectionManager";
|
8
|
|
-import LogoutDialog from "../Amicale/LogoutDialog";
|
9
|
|
-import SideBarSection from "./SideBarSection";
|
10
|
|
-import {DrawerNavigationProp} from "@react-navigation/drawer";
|
11
|
|
-
|
12
|
|
-const deviceWidth = Dimensions.get("window").width;
|
13
|
|
-
|
14
|
|
-type Props = {
|
15
|
|
- navigation: DrawerNavigationProp,
|
16
|
|
- state: {[key: string] : any},
|
17
|
|
- theme?: Object,
|
18
|
|
-};
|
19
|
|
-
|
20
|
|
-type State = {
|
21
|
|
- isLoggedIn: boolean,
|
22
|
|
- dialogVisible: boolean,
|
23
|
|
-};
|
24
|
|
-
|
25
|
|
-/**
|
26
|
|
- * Component used to render the drawer menu content
|
27
|
|
- */
|
28
|
|
-class SideBar extends React.Component<Props, State> {
|
29
|
|
-
|
30
|
|
- dataSet: Array<Object>;
|
31
|
|
- activeRoute: string;
|
32
|
|
- /**
|
33
|
|
- * Generate the dataset
|
34
|
|
- *
|
35
|
|
- * @param props
|
36
|
|
- */
|
37
|
|
- constructor(props: Props) {
|
38
|
|
- super(props);
|
39
|
|
- this.activeRoute = 'main';
|
40
|
|
- // Dataset used to render the drawer
|
41
|
|
- const mainData = [
|
42
|
|
- {
|
43
|
|
- name: i18n.t('screens.home'),
|
44
|
|
- route: "main",
|
45
|
|
- icon: "home",
|
46
|
|
- },
|
47
|
|
- ];
|
48
|
|
- const amicaleData = [
|
49
|
|
- {
|
50
|
|
- name: i18n.t('screens.login'),
|
51
|
|
- route: "login",
|
52
|
|
- icon: "login",
|
53
|
|
- onlyWhenLoggedOut: true,
|
54
|
|
- shouldEmphasis: true,
|
55
|
|
- },
|
56
|
|
- {
|
57
|
|
- name: i18n.t('screens.amicaleAbout'),
|
58
|
|
- route: "amicale-contact",
|
59
|
|
- icon: "information",
|
60
|
|
- },
|
61
|
|
- {
|
62
|
|
- name: i18n.t('screens.profile'),
|
63
|
|
- route: "profile",
|
64
|
|
- icon: "account",
|
65
|
|
- onlyWhenLoggedIn: true,
|
66
|
|
- },
|
67
|
|
- {
|
68
|
|
- name: i18n.t('clubs.clubList'),
|
69
|
|
- route: "club-list",
|
70
|
|
- icon: "account-group",
|
71
|
|
- onlyWhenLoggedIn: true,
|
72
|
|
- },
|
73
|
|
- {
|
74
|
|
- name: i18n.t('screens.vote'),
|
75
|
|
- route: "vote",
|
76
|
|
- icon: "vote",
|
77
|
|
- onlyWhenLoggedIn: true,
|
78
|
|
- },
|
79
|
|
- {
|
80
|
|
- name: i18n.t('screens.logout'),
|
81
|
|
- route: 'disconnect',
|
82
|
|
- action: this.showDisconnectDialog,
|
83
|
|
- icon: "logout",
|
84
|
|
- onlyWhenLoggedIn: true,
|
85
|
|
- },
|
86
|
|
- ];
|
87
|
|
- const servicesData = [
|
88
|
|
- {
|
89
|
|
- name: i18n.t('screens.menuSelf'),
|
90
|
|
- route: "self-menu",
|
91
|
|
- icon: "silverware-fork-knife",
|
92
|
|
- },
|
93
|
|
- {
|
94
|
|
- name: i18n.t('screens.availableRooms'),
|
95
|
|
- route: "available-rooms",
|
96
|
|
- icon: "calendar-check",
|
97
|
|
- },
|
98
|
|
- {
|
99
|
|
- name: i18n.t('screens.bib'),
|
100
|
|
- route: "bib",
|
101
|
|
- icon: "book",
|
102
|
|
- },
|
103
|
|
- {
|
104
|
|
- name: i18n.t('screens.bluemind'),
|
105
|
|
- route: "bluemind",
|
106
|
|
- link: "https://etud-mel.insa-toulouse.fr/webmail/",
|
107
|
|
- icon: "email",
|
108
|
|
- },
|
109
|
|
- {
|
110
|
|
- name: i18n.t('screens.ent'),
|
111
|
|
- route: "ent",
|
112
|
|
- link: "https://ent.insa-toulouse.fr/",
|
113
|
|
- icon: "notebook",
|
114
|
|
- },
|
115
|
|
- ];
|
116
|
|
- const websitesData = [
|
117
|
|
- {
|
118
|
|
- name: "Amicale",
|
119
|
|
- route: "amicale-website",
|
120
|
|
- icon: "alpha-a-box",
|
121
|
|
- },
|
122
|
|
- {
|
123
|
|
- name: "Élus Étudiants",
|
124
|
|
- route: "elus-etudiants",
|
125
|
|
- icon: "alpha-e-box",
|
126
|
|
- },
|
127
|
|
- {
|
128
|
|
- name: "Wiketud",
|
129
|
|
- route: "wiketud",
|
130
|
|
- icon: "wikipedia",
|
131
|
|
- },
|
132
|
|
- {
|
133
|
|
- name: "Tutor'INSA",
|
134
|
|
- route: "tutorinsa",
|
135
|
|
- icon: "school",
|
136
|
|
- },
|
137
|
|
- ];
|
138
|
|
- const othersData = [
|
139
|
|
- {
|
140
|
|
- name: i18n.t('screens.settings'),
|
141
|
|
- route: "settings",
|
142
|
|
- icon: "settings",
|
143
|
|
- },
|
144
|
|
- {
|
145
|
|
- name: i18n.t('screens.about'),
|
146
|
|
- route: "about",
|
147
|
|
- icon: "information",
|
148
|
|
- },
|
149
|
|
- ];
|
150
|
|
-
|
151
|
|
- this.dataSet = [
|
152
|
|
- {
|
153
|
|
- key: '1',
|
154
|
|
- name: i18n.t('screens.home'),
|
155
|
|
- startOpen: true, // App always starts on Main
|
156
|
|
- data: mainData
|
157
|
|
- },
|
158
|
|
- {
|
159
|
|
- key: '2',
|
160
|
|
- name: i18n.t('sidenav.divider4'),
|
161
|
|
- startOpen: false, // TODO set by user preferences
|
162
|
|
- data: amicaleData
|
163
|
|
- },
|
164
|
|
- {
|
165
|
|
- key: '3',
|
166
|
|
- name: i18n.t('sidenav.divider2'),
|
167
|
|
- startOpen: false,
|
168
|
|
- data: servicesData
|
169
|
|
- },
|
170
|
|
- {
|
171
|
|
- key: '4',
|
172
|
|
- name: i18n.t('sidenav.divider1'),
|
173
|
|
- startOpen: false,
|
174
|
|
- data: websitesData
|
175
|
|
- },
|
176
|
|
- {
|
177
|
|
- key: '5',
|
178
|
|
- name: i18n.t('sidenav.divider3'),
|
179
|
|
- startOpen: false,
|
180
|
|
- data: othersData
|
181
|
|
- },
|
182
|
|
- ];
|
183
|
|
- ConnectionManager.getInstance().addLoginStateListener(this.onLoginStateChange);
|
184
|
|
- this.state = {
|
185
|
|
- isLoggedIn: ConnectionManager.getInstance().isLoggedIn(),
|
186
|
|
- dialogVisible: false,
|
187
|
|
- };
|
188
|
|
- }
|
189
|
|
-
|
190
|
|
- shouldComponentUpdate(nextProps: Props, nextState: State): boolean {
|
191
|
|
- const nextNavigationState = nextProps.state.routes[0].state;
|
192
|
|
- const nextRoute = nextNavigationState.routes[nextNavigationState.index].name;
|
193
|
|
-
|
194
|
|
- let currentRoute = "main";
|
195
|
|
- const currentNavigationState = this.props.state.routes[0].state;
|
196
|
|
- if (currentNavigationState != null) {
|
197
|
|
- currentRoute = currentNavigationState.routes[currentNavigationState.index].name;
|
198
|
|
- }
|
199
|
|
-
|
200
|
|
-
|
201
|
|
- this.activeRoute = nextRoute;
|
202
|
|
- return (nextState !== this.state)
|
203
|
|
- || (nextRoute !== currentRoute);
|
204
|
|
- }
|
205
|
|
-
|
206
|
|
- showDisconnectDialog = () => this.setState({dialogVisible: true});
|
207
|
|
-
|
208
|
|
- hideDisconnectDialog = () => this.setState({dialogVisible: false});
|
209
|
|
-
|
210
|
|
- onLoginStateChange = (isLoggedIn: boolean) => this.setState({isLoggedIn: isLoggedIn});
|
211
|
|
-
|
212
|
|
- /**
|
213
|
|
- * Gets the render item for the given list item
|
214
|
|
- *
|
215
|
|
- * @param item The item to render
|
216
|
|
- * @return {*}
|
217
|
|
- */
|
218
|
|
- getRenderItem = ({item}: Object) => {
|
219
|
|
- return <SideBarSection
|
220
|
|
- {...this.props}
|
221
|
|
- listKey={item.key}
|
222
|
|
- activeRoute={this.activeRoute}
|
223
|
|
- isLoggedIn={this.state.isLoggedIn}
|
224
|
|
- sectionName={item.name}
|
225
|
|
- startOpen={item.startOpen}
|
226
|
|
- listData={item.data}
|
227
|
|
- />
|
228
|
|
- };
|
229
|
|
-
|
230
|
|
- render() {
|
231
|
|
- return (
|
232
|
|
- <View style={{height: '100%'}}>
|
233
|
|
- <TouchableRipple
|
234
|
|
- onPress={() => this.props.navigation.navigate("tetris")}
|
235
|
|
- >
|
236
|
|
- <Image
|
237
|
|
- source={require("../../../assets/drawer-cover.png")}
|
238
|
|
- style={styles.drawerCover}
|
239
|
|
- />
|
240
|
|
- </TouchableRipple>
|
241
|
|
- {/*$FlowFixMe*/}
|
242
|
|
- <FlatList
|
243
|
|
- data={this.dataSet}
|
244
|
|
- extraData={this.state.isLoggedIn.toString() + this.activeRoute}
|
245
|
|
- renderItem={this.getRenderItem}
|
246
|
|
- />
|
247
|
|
- <LogoutDialog
|
248
|
|
- {...this.props}
|
249
|
|
- visible={this.state.dialogVisible}
|
250
|
|
- onDismiss={this.hideDisconnectDialog}
|
251
|
|
- />
|
252
|
|
- </View>
|
253
|
|
- );
|
254
|
|
- }
|
255
|
|
-}
|
256
|
|
-
|
257
|
|
-const styles = StyleSheet.create({
|
258
|
|
- drawerCover: {
|
259
|
|
- height: deviceWidth / 3,
|
260
|
|
- width: 2 * deviceWidth / 3,
|
261
|
|
- position: "relative",
|
262
|
|
- marginBottom: 10,
|
263
|
|
- marginTop: 20
|
264
|
|
- },
|
265
|
|
-});
|
266
|
|
-
|
267
|
|
-export default SideBar;
|