|
@@ -8,8 +8,9 @@ import {withCollapsible} from "../../utils/withCollapsible";
|
8
|
8
|
import {Collapsible} from "react-navigation-collapsible";
|
9
|
9
|
import {CommonActions} from "@react-navigation/native";
|
10
|
10
|
import {Animated, View} from "react-native";
|
11
|
|
-import {Avatar, Card, Divider, List, TouchableRipple, withTheme} from "react-native-paper";
|
|
11
|
+import {Avatar, Button, Card, Divider, List, Title, TouchableRipple, withTheme} from "react-native-paper";
|
12
|
12
|
import type {CustomTheme} from "../../managers/ThemeManager";
|
|
13
|
+import ConnectionManager from "../../managers/ConnectionManager";
|
13
|
14
|
|
14
|
15
|
type Props = {
|
15
|
16
|
navigation: Object,
|
|
@@ -29,14 +30,19 @@ const AMICALE_IMAGE = require("../../../assets/amicale.png");
|
29
|
30
|
const EE_IMAGE = "https://etud.insa-toulouse.fr/~eeinsat/wp-content/uploads/2019/09/logo-blanc.png";
|
30
|
31
|
const TUTORINSA_IMAGE = "https://www.etud.insa-toulouse.fr/~tutorinsa/public/images/logo-gray.png";
|
31
|
32
|
|
32
|
|
-type listItem = {
|
|
33
|
+export type listItem = {
|
33
|
34
|
title: string,
|
34
|
35
|
description: string,
|
35
|
36
|
image: string | number,
|
|
37
|
+ shouldLogin: boolean,
|
36
|
38
|
content: cardList,
|
37
|
39
|
}
|
38
|
40
|
|
39
|
|
-class ServicesScreen extends React.Component<Props> {
|
|
41
|
+type State = {
|
|
42
|
+ isLoggedIn: boolean,
|
|
43
|
+}
|
|
44
|
+
|
|
45
|
+class ServicesScreen extends React.Component<Props, State> {
|
40
|
46
|
|
41
|
47
|
amicaleDataset: cardList;
|
42
|
48
|
studentsDataset: cardList;
|
|
@@ -148,29 +154,40 @@ class ServicesScreen extends React.Component<Props> {
|
148
|
154
|
title: "AMICALE",
|
149
|
155
|
description: "LOGIN",
|
150
|
156
|
image: AMICALE_IMAGE,
|
|
157
|
+ shouldLogin: true,
|
151
|
158
|
content: this.amicaleDataset
|
152
|
159
|
},
|
153
|
160
|
{
|
154
|
161
|
title: "STUDENTS",
|
155
|
162
|
description: "SERVICES OFFERED BY STUDENTS",
|
156
|
163
|
image: 'account-group',
|
|
164
|
+ shouldLogin: false,
|
157
|
165
|
content: this.studentsDataset
|
158
|
166
|
},
|
159
|
167
|
{
|
160
|
168
|
title: "INSA",
|
161
|
169
|
description: "SERVICES OFFERED BY INSA",
|
162
|
170
|
image: 'school',
|
|
171
|
+ shouldLogin: false,
|
163
|
172
|
content: this.insaDataset
|
164
|
173
|
},
|
165
|
|
- ]
|
|
174
|
+ ];
|
|
175
|
+ this.state = {
|
|
176
|
+ isLoggedIn: ConnectionManager.getInstance().isLoggedIn()
|
|
177
|
+ }
|
166
|
178
|
}
|
167
|
179
|
|
168
|
180
|
componentDidMount() {
|
169
|
|
- this.props.navigation.addListener('focus', this.handleNavigationParams);
|
|
181
|
+ this.props.navigation.addListener('focus', this.onFocus);
|
|
182
|
+
|
|
183
|
+ }
|
170
|
184
|
|
|
185
|
+ onFocus = () => {
|
|
186
|
+ this.handleNavigationParams();
|
|
187
|
+ this.setState({isLoggedIn: ConnectionManager.getInstance().isLoggedIn()})
|
171
|
188
|
}
|
172
|
189
|
|
173
|
|
- handleNavigationParams = () => {
|
|
190
|
+ handleNavigationParams() {
|
174
|
191
|
if (this.props.route.params != null) {
|
175
|
192
|
if (this.props.route.params.nextScreen != null) {
|
176
|
193
|
this.props.navigation.navigate(this.props.route.params.nextScreen);
|
|
@@ -198,25 +215,57 @@ class ServicesScreen extends React.Component<Props> {
|
198
|
215
|
/>
|
199
|
216
|
}
|
200
|
217
|
|
|
218
|
+ getLoginMessage() {
|
|
219
|
+ return (
|
|
220
|
+ <View>
|
|
221
|
+ <Title style={{
|
|
222
|
+ marginLeft: 'auto',
|
|
223
|
+ marginRight: 'auto',
|
|
224
|
+ }}>
|
|
225
|
+ NOT LOGGED IN
|
|
226
|
+ </Title>
|
|
227
|
+ <Button
|
|
228
|
+ icon="login"
|
|
229
|
+ mode="contained"
|
|
230
|
+ onPress={() => this.props.navigation.navigate("login")}
|
|
231
|
+ style={{
|
|
232
|
+ marginLeft: 'auto',
|
|
233
|
+ marginRight: 'auto',
|
|
234
|
+ }}>
|
|
235
|
+ LOGIN
|
|
236
|
+ </Button>
|
|
237
|
+ </View>
|
|
238
|
+ )
|
|
239
|
+ }
|
|
240
|
+
|
201
|
241
|
renderItem = ({item}: { item: listItem }) => {
|
|
242
|
+ const shouldShowLogin = !this.state.isLoggedIn && item.shouldLogin;
|
202
|
243
|
return (
|
203
|
244
|
<TouchableRipple
|
204
|
245
|
style={{
|
205
|
246
|
margin: 5,
|
206
|
247
|
marginBottom: 20,
|
207
|
248
|
}}
|
208
|
|
- onPress={() => this.props.navigation.navigate("services-section", {data: item})}
|
|
249
|
+ onPress={shouldShowLogin
|
|
250
|
+ ? undefined
|
|
251
|
+ : () => this.props.navigation.navigate("services-section", {data: item})}
|
209
|
252
|
>
|
210
|
253
|
<View>
|
211
|
254
|
<Card.Title
|
212
|
255
|
title={item.title}
|
213
|
256
|
left={(props) => this.getAvatar(props, item.image)}
|
214
|
|
- right={(props) => <List.Icon {...props} icon="chevron-right"/>}
|
215
|
|
- />
|
216
|
|
- <CardList
|
217
|
|
- dataset={item.content}
|
218
|
|
- isHorizontal={true}
|
|
257
|
+ right={shouldShowLogin
|
|
258
|
+ ? undefined
|
|
259
|
+ : (props) => <List.Icon {...props} icon="chevron-right"/>}
|
219
|
260
|
/>
|
|
261
|
+ {
|
|
262
|
+ shouldShowLogin
|
|
263
|
+ ? this.getLoginMessage()
|
|
264
|
+ : <CardList
|
|
265
|
+ dataset={item.content}
|
|
266
|
+ isHorizontal={true}
|
|
267
|
+ />
|
|
268
|
+ }
|
220
|
269
|
</View>
|
221
|
270
|
</TouchableRipple>
|
222
|
271
|
|