Browse Source

Show amicale services even when not logged in

Arnaud Vergnet 3 years ago
parent
commit
fe9089881a
1 changed files with 8 additions and 69 deletions
  1. 8
    69
      src/screens/Services/ServicesScreen.js

+ 8
- 69
src/screens/Services/ServicesScreen.js View File

@@ -6,11 +6,9 @@ import CardList from "../../components/Lists/CardList/CardList";
6 6
 import CustomTabBar from "../../components/Tabbar/CustomTabBar";
7 7
 import {withCollapsible} from "../../utils/withCollapsible";
8 8
 import {Collapsible} from "react-navigation-collapsible";
9
-import {CommonActions} from "@react-navigation/native";
10 9
 import {Animated, View} from "react-native";
11
-import {Avatar, Button, Card, Divider, List, Title, TouchableRipple, withTheme} from "react-native-paper";
10
+import {Avatar, Card, Divider, List, TouchableRipple, withTheme} from "react-native-paper";
12 11
 import type {CustomTheme} from "../../managers/ThemeManager";
13
-import ConnectionManager from "../../managers/ConnectionManager";
14 12
 import i18n from 'i18n-js';
15 13
 import MaterialHeaderButtons, {Item} from "../../components/Overrides/CustomHeaderButton";
16 14
 
@@ -45,9 +43,7 @@ export type listItem = {
45 43
     content: cardList,
46 44
 }
47 45
 
48
-type State = {
49
-    isLoggedIn: boolean,
50
-}
46
+type State = {}
51 47
 
52 48
 class ServicesScreen extends React.Component<Props, State> {
53 49
 
@@ -111,12 +107,6 @@ class ServicesScreen extends React.Component<Props, State> {
111 107
                 image: TUTORINSA_IMAGE,
112 108
                 onPress: () => nav.navigate("tutorinsa"),
113 109
             },
114
-            {
115
-                title: i18n.t('screens.amicaleWebsite'),
116
-                subtitle: i18n.t('servicesScreen.descriptions.amicaleWebsite'),
117
-                image: AMICALE_IMAGE,
118
-                onPress: () => nav.navigate("amicale-website"),
119
-            },
120 110
         ];
121 111
         this.insaDataset = [
122 112
             {
@@ -173,13 +163,9 @@ class ServicesScreen extends React.Component<Props, State> {
173 163
                 content: this.insaDataset
174 164
             },
175 165
         ];
176
-        this.state = {
177
-            isLoggedIn: ConnectionManager.getInstance().isLoggedIn()
178
-        }
179 166
     }
180 167
 
181 168
     componentDidMount() {
182
-        this.props.navigation.addListener('focus', this.onFocus);
183 169
         this.props.navigation.setOptions({
184 170
             headerRight: this.getAboutButton,
185 171
         });
@@ -192,21 +178,6 @@ class ServicesScreen extends React.Component<Props, State> {
192 178
 
193 179
     onAboutPress = () => this.props.navigation.navigate('amicale-contact');
194 180
 
195
-    onFocus = () => {
196
-        this.handleNavigationParams();
197
-        this.setState({isLoggedIn: ConnectionManager.getInstance().isLoggedIn()})
198
-    }
199
-
200
-    handleNavigationParams() {
201
-        if (this.props.route.params != null) {
202
-            if (this.props.route.params.nextScreen != null) {
203
-                this.props.navigation.navigate(this.props.route.params.nextScreen);
204
-                // reset params to prevent infinite loop
205
-                this.props.navigation.dispatch(CommonActions.setParams({nextScreen: null}));
206
-            }
207
-        }
208
-    };
209
-
210 181
     getAvatar(props, source: string | number) {
211 182
         if (typeof source === "number")
212 183
             return <Avatar.Image
@@ -225,57 +196,25 @@ class ServicesScreen extends React.Component<Props, State> {
225 196
             />
226 197
     }
227 198
 
228
-    getLoginMessage() {
229
-        return (
230
-            <View>
231
-                <Title style={{
232
-                    marginLeft: 'auto',
233
-                    marginRight: 'auto',
234
-                }}>
235
-                    {i18n.t("servicesScreen.notLoggedIn")}
236
-                </Title>
237
-                <Button
238
-                    icon="login"
239
-                    mode="contained"
240
-                    onPress={() => this.props.navigation.navigate("login")}
241
-                    style={{
242
-                        marginLeft: 'auto',
243
-                        marginRight: 'auto',
244
-                    }}>
245
-                    {i18n.t("screens.login")}
246
-                </Button>
247
-            </View>
248
-        )
249
-    }
250
-
251 199
     renderItem = ({item}: { item: listItem }) => {
252
-        const shouldShowLogin = !this.state.isLoggedIn && item.shouldLogin;
253 200
         return (
254 201
             <TouchableRipple
255 202
                 style={{
256 203
                     margin: 5,
257 204
                     marginBottom: 20,
258 205
                 }}
259
-                onPress={shouldShowLogin
260
-                    ? undefined
261
-                    : () => this.props.navigation.navigate("services-section", {data: item})}
206
+                onPress={() => this.props.navigation.navigate("services-section", {data: item})}
262 207
             >
263 208
                 <View>
264 209
                     <Card.Title
265 210
                         title={item.title}
266 211
                         left={(props) => this.getAvatar(props, item.image)}
267
-                        right={shouldShowLogin
268
-                            ? undefined
269
-                            : (props) => <List.Icon {...props} icon="chevron-right"/>}
212
+                        right={(props) => <List.Icon {...props} icon="chevron-right"/>}
213
+                    />
214
+                    <CardList
215
+                        dataset={item.content}
216
+                        isHorizontal={true}
270 217
                     />
271
-                    {
272
-                        shouldShowLogin
273
-                            ? this.getLoginMessage()
274
-                            : <CardList
275
-                                dataset={item.content}
276
-                                isHorizontal={true}
277
-                            />
278
-                    }
279 218
                 </View>
280 219
             </TouchableRipple>
281 220
 

Loading…
Cancel
Save