Browse Source

Grouped all services in a single class for easier manipulation

Arnaud Vergnet 3 years ago
parent
commit
ac19b77fd3

+ 2
- 1
src/components/Lists/CardList/CardList.js View File

@@ -13,6 +13,7 @@ type Props = {
13 13
 }
14 14
 
15 15
 export type cardItem = {
16
+    key: string,
16 17
     title: string,
17 18
     subtitle: string,
18 19
     image: string | number,
@@ -44,7 +45,7 @@ export default class CardList extends React.Component<Props> {
44 45
             return <CardListItem item={item} key={item.title}/>;
45 46
     };
46 47
 
47
-    keyExtractor = (item: cardItem) => item.title;
48
+    keyExtractor = (item: cardItem) => item.key;
48 49
 
49 50
     render() {
50 51
         let containerStyle = {};

+ 261
- 0
src/managers/ServicesManager.js View File

@@ -0,0 +1,261 @@
1
+// @flow
2
+
3
+import type {cardList} from "../components/Lists/CardList/CardList";
4
+import i18n from "i18n-js";
5
+import AvailableWebsites from "../constants/AvailableWebsites";
6
+import {StackNavigationProp} from "@react-navigation/stack";
7
+import ConnectionManager from "./ConnectionManager";
8
+
9
+const CLUBS_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Clubs.png";
10
+const PROFILE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ProfilAmicaliste.png";
11
+const EQUIPMENT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Materiel.png";
12
+const VOTE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Vote.png";
13
+const AMICALE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/WebsiteAmicale.png";
14
+
15
+const PROXIMO_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Proximo.png"
16
+const WIKETUD_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Wiketud.png";
17
+const EE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/EEC.png";
18
+const TUTORINSA_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/TutorINSA.png";
19
+
20
+const BIB_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Bib.png";
21
+const RU_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/RU.png";
22
+const ROOM_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Salles.png";
23
+const EMAIL_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Bluemind.png";
24
+const ENT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ENT.png";
25
+const ACCOUNT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Account.png";
26
+
27
+export const SERVICES_KEY = {
28
+    CLUBS: "clubs",
29
+    PROFILE:"profile",
30
+    EQUIPMENT: "equipment",
31
+    AMICALE_WEBSITE: "amicale_website",
32
+    VOTE: "vote",
33
+    PROXIMO: "proximo",
34
+    WIKETUD: "wiketud",
35
+    ELUS_ETUDIANTS: "elus_etudiants",
36
+    TUTOR_INSA: "tutor_insa",
37
+    RU: "ru",
38
+    AVAILABLE_ROOMS: "available_rooms",
39
+    BIB: "bib",
40
+    EMAIL: "email",
41
+    ENT: "ent",
42
+    INSA_ACCOUNT: "insa_account",
43
+}
44
+
45
+export default class ServicesManager {
46
+
47
+    navigation: StackNavigationProp;
48
+
49
+    amicaleDataset: cardList;
50
+    studentsDataset: cardList;
51
+    insaDataset: cardList;
52
+
53
+    constructor(nav: StackNavigationProp) {
54
+        this.navigation = nav;
55
+        this.amicaleDataset = [
56
+            {
57
+                key: SERVICES_KEY.CLUBS,
58
+                title: i18n.t('screens.clubs.title'),
59
+                subtitle: i18n.t('screens.services.descriptions.clubs'),
60
+                image: CLUBS_IMAGE,
61
+                onPress: () => this.onAmicaleServicePress("club-list"),
62
+            },
63
+            {
64
+                key: SERVICES_KEY.PROFILE,
65
+                title: i18n.t('screens.profile.title'),
66
+                subtitle: i18n.t('screens.services.descriptions.profile'),
67
+                image: PROFILE_IMAGE,
68
+                onPress: () => this.onAmicaleServicePress("profile"),
69
+            },
70
+            {
71
+                key: SERVICES_KEY.EQUIPMENT,
72
+                title: i18n.t('screens.equipment.title'),
73
+                subtitle: i18n.t('screens.services.descriptions.equipment'),
74
+                image: EQUIPMENT_IMAGE,
75
+                onPress: () => this.onAmicaleServicePress("equipment-list"),
76
+            },
77
+            {
78
+                key: SERVICES_KEY.AMICALE_WEBSITE,
79
+                title: i18n.t('screens.websites.amicale'),
80
+                subtitle: i18n.t('screens.services.descriptions.amicaleWebsite'),
81
+                image: AMICALE_IMAGE,
82
+                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.AMICALE, title: i18n.t('screens.websites.amicale')}),
83
+            },
84
+            {
85
+                key: SERVICES_KEY.VOTE,
86
+                title: i18n.t('screens.vote.title'),
87
+                subtitle: i18n.t('screens.services.descriptions.vote'),
88
+                image: VOTE_IMAGE,
89
+                onPress: () => this.onAmicaleServicePress("vote"),
90
+            },
91
+        ];
92
+        this.studentsDataset = [
93
+            {
94
+                key: SERVICES_KEY.PROXIMO,
95
+                title: i18n.t('screens.proximo.title'),
96
+                subtitle: i18n.t('screens.services.descriptions.proximo'),
97
+                image: PROXIMO_IMAGE,
98
+                onPress: () => nav.navigate("proximo"),
99
+            },
100
+            {
101
+                key: SERVICES_KEY.WIKETUD,
102
+                title: "Wiketud",
103
+                subtitle: i18n.t('screens.services.descriptions.wiketud'),
104
+                image: WIKETUD_IMAGE,
105
+                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.WIKETUD, title: "Wiketud"}),
106
+            },
107
+            {
108
+                key: SERVICES_KEY.ELUS_ETUDIANTS,
109
+                title: "Élus Étudiants",
110
+                subtitle: i18n.t('screens.services.descriptions.elusEtudiants'),
111
+                image: EE_IMAGE,
112
+                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.WIKETUD, title: "Wiketud"}),
113
+            },
114
+            {
115
+                key: SERVICES_KEY.TUTOR_INSA,
116
+                title: "Tutor'INSA",
117
+                subtitle: i18n.t('screens.services.descriptions.tutorInsa'),
118
+                image: TUTORINSA_IMAGE,
119
+                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.TUTOR_INSA, title: "Tutor'INSA"})
120
+            },
121
+        ];
122
+        this.insaDataset = [
123
+            {
124
+                key: SERVICES_KEY.RU,
125
+                title: i18n.t('screens.menu.title'),
126
+                subtitle: i18n.t('screens.services.descriptions.self'),
127
+                image: RU_IMAGE,
128
+                onPress: () => nav.navigate("self-menu"),
129
+            },
130
+            {
131
+                key: SERVICES_KEY.AVAILABLE_ROOMS,
132
+                title: i18n.t('screens.websites.rooms'),
133
+                subtitle: i18n.t('screens.services.descriptions.availableRooms'),
134
+                image: ROOM_IMAGE,
135
+                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.AVAILABLE_ROOMS, title: i18n.t('screens.websites.rooms')}),
136
+            },
137
+            {
138
+                key: SERVICES_KEY.BIB,
139
+                title: i18n.t('screens.websites.bib'),
140
+                subtitle: i18n.t('screens.services.descriptions.bib'),
141
+                image: BIB_IMAGE,
142
+                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.BIB, title: i18n.t('screens.websites.bib')}),
143
+            },
144
+            {
145
+                key: SERVICES_KEY.EMAIL,
146
+                title: i18n.t('screens.websites.mails'),
147
+                subtitle: i18n.t('screens.services.descriptions.mails'),
148
+                image: EMAIL_IMAGE,
149
+                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.BLUEMIND, title: i18n.t('screens.websites.mails')}),
150
+            },
151
+            {
152
+                key: SERVICES_KEY.ENT,
153
+                title: i18n.t('screens.websites.ent'),
154
+                subtitle: i18n.t('screens.services.descriptions.ent'),
155
+                image: ENT_IMAGE,
156
+                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.ENT, title: i18n.t('screens.websites.ent')}),
157
+            },
158
+            {
159
+                key: SERVICES_KEY.INSA_ACCOUNT,
160
+                title: i18n.t('screens.insaAccount.title'),
161
+                subtitle: i18n.t('screens.services.descriptions.insaAccount'),
162
+                image: ACCOUNT_IMAGE,
163
+                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.INSA_ACCOUNT, title: i18n.t('screens.insaAccount.title')}),
164
+            },
165
+        ];
166
+    }
167
+
168
+    /**
169
+     * Redirects the user to the login screen if he is not logged in
170
+     *
171
+     * @param route
172
+     * @returns {null}
173
+     */
174
+    onAmicaleServicePress(route: string) {
175
+        if (ConnectionManager.getInstance().isLoggedIn())
176
+            this.navigation.navigate(route);
177
+        else
178
+            this.navigation.navigate("login", {nextScreen: route});
179
+    }
180
+
181
+    /**
182
+     * Gets the given services list without items of the given ids
183
+     *
184
+     * @param idList The ids of items to remove
185
+     * @param sourceList The item list to use as source
186
+     * @returns {[]}
187
+     */
188
+    getStrippedList(idList: Array<string>, sourceList: cardList) {
189
+        let newArray = [];
190
+        for (let i = 0; i < sourceList.length; i++) {
191
+            const item = sourceList[i];
192
+            if (!(idList.includes(item.key)))
193
+                newArray.push(item);
194
+        }
195
+        return newArray;
196
+    }
197
+
198
+    /**
199
+     * Gets a services list of items with the given ids only
200
+     *
201
+     * @param idList The ids of items to find
202
+     * @returns {[]}
203
+     */
204
+    getServicesOfId(idList: Array<string>) {
205
+        const allServices = [
206
+            ...this.amicaleDataset,
207
+            ...this.studentsDataset,
208
+            ...this.insaDataset,
209
+        ]
210
+        let servicesFound = [];
211
+        for (let i = 0; i < allServices.length; i++) {
212
+            const item = allServices[i];
213
+            if (idList.includes(item.key)) {
214
+                servicesFound.push(item);
215
+                if (servicesFound.length === idList.length)
216
+                    break;
217
+            }
218
+        }
219
+        return servicesFound;
220
+    }
221
+
222
+    /**
223
+     * Gets the list of amicale's services
224
+     *
225
+     * @param excludedItems Ids of items to exclude from the returned list
226
+     * @returns {cardList|*[]}
227
+     */
228
+    getAmicaleServices(excludedItems?: Array<string>) {
229
+        if (excludedItems != null)
230
+            return this.getStrippedList(excludedItems, this.amicaleDataset)
231
+        else
232
+            return this.amicaleDataset;
233
+    }
234
+
235
+    /**
236
+     * Gets the list of students' services
237
+     *
238
+     * @param excludedItems Ids of items to exclude from the returned list
239
+     * @returns {cardList|*[]}
240
+     */
241
+    getStudentServices(excludedItems?: Array<string>) {
242
+        if (excludedItems != null)
243
+            return this.getStrippedList(excludedItems, this.studentsDataset)
244
+        else
245
+            return this.studentsDataset;
246
+    }
247
+
248
+    /**
249
+     * Gets the list of INSA's services
250
+     *
251
+     * @param excludedItems Ids of items to exclude from the returned list
252
+     * @returns {cardList|*[]}
253
+     */
254
+    getINSAServices(excludedItems?: Array<string>) {
255
+        if (excludedItems != null)
256
+            return this.getStrippedList(excludedItems, this.insaDataset)
257
+        else
258
+            return this.insaDataset;
259
+    }
260
+
261
+}

+ 5
- 30
src/screens/Amicale/ProfileScreen.js View File

@@ -16,6 +16,7 @@ import {StackNavigationProp} from "@react-navigation/stack";
16 16
 import type {CustomTheme} from "../../managers/ThemeManager";
17 17
 import AvailableWebsites from "../../constants/AvailableWebsites";
18 18
 import Mascot, {MASCOT_STYLE} from "../../components/Mascot/Mascot";
19
+import ServicesManager, {SERVICES_KEY} from "../../managers/ServicesManager";
19 20
 
20 21
 type Props = {
21 22
     navigation: StackNavigationProp,
@@ -44,11 +45,6 @@ type Club = {
44 45
     is_manager: boolean,
45 46
 }
46 47
 
47
-const CLUBS_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Clubs.png";
48
-const VOTE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Vote.png";
49
-
50
-const ICON_AMICALE = require('../../../assets/amicale.png');
51
-
52 48
 class ProfileScreen extends React.Component<Props, State> {
53 49
 
54 50
     state = {
@@ -60,37 +56,16 @@ class ProfileScreen extends React.Component<Props, State> {
60 56
     flatListData: Array<{ id: string }>;
61 57
     amicaleDataset: cardList;
62 58
 
63
-    constructor() {
64
-        super();
59
+    constructor(props: Props) {
60
+        super(props);
65 61
         this.flatListData = [
66 62
             {id: '0'},
67 63
             {id: '1'},
68 64
             {id: '2'},
69 65
             {id: '3'},
70 66
         ]
71
-        this.amicaleDataset = [
72
-            {
73
-                title: i18n.t('screens.clubs.title'),
74
-                subtitle: i18n.t('screens.services.descriptions.clubs'),
75
-                image: CLUBS_IMAGE,
76
-                onPress: () => this.props.navigation.navigate("club-list"),
77
-            },
78
-            {
79
-                title: i18n.t('screens.vote.title'),
80
-                subtitle: i18n.t('screens.services.descriptions.vote'),
81
-                image: VOTE_IMAGE,
82
-                onPress: () => this.props.navigation.navigate("vote"),
83
-            },
84
-            {
85
-                title: i18n.t('screens.websites.amicale'),
86
-                subtitle: i18n.t('screens.services.descriptions.amicaleWebsite'),
87
-                image: ICON_AMICALE,
88
-                onPress: () => this.props.navigation.navigate("website", {
89
-                    host: AvailableWebsites.websites.AMICALE,
90
-                    title: i18n.t('screens.websites.amicale')
91
-                }),
92
-            },
93
-        ];
67
+        const services = new ServicesManager(props.navigation);
68
+        this.amicaleDataset = services.getAmicaleServices([SERVICES_KEY.PROFILE]);
94 69
     }
95 70
 
96 71
     componentDidMount() {

+ 5
- 116
src/screens/Services/ServicesScreen.js View File

@@ -13,10 +13,10 @@ import i18n from 'i18n-js';
13 13
 import MaterialHeaderButtons, {Item} from "../../components/Overrides/CustomHeaderButton";
14 14
 import ConnectionManager from "../../managers/ConnectionManager";
15 15
 import {StackNavigationProp} from "@react-navigation/stack";
16
-import AvailableWebsites from "../../constants/AvailableWebsites";
17 16
 import {MASCOT_STYLE} from "../../components/Mascot/Mascot";
18 17
 import MascotPopup from "../../components/Mascot/MascotPopup";
19 18
 import AsyncStorageManager from "../../managers/AsyncStorageManager";
19
+import ServicesManager from "../../managers/ServicesManager";
20 20
 
21 21
 type Props = {
22 22
     navigation: StackNavigationProp,
@@ -38,24 +38,6 @@ export type listItem = {
38 38
 
39 39
 const AMICALE_LOGO = require("../../../assets/amicale.png");
40 40
 
41
-const CLUBS_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Clubs.png";
42
-const PROFILE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ProfilAmicaliste.png";
43
-const EQUIPMENT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Materiel.png";
44
-const VOTE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Vote.png";
45
-const AMICALE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/WebsiteAmicale.png";
46
-
47
-const PROXIMO_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Proximo.png"
48
-const WIKETUD_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Wiketud.png";
49
-const EE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/EEC.png";
50
-const TUTORINSA_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/TutorINSA.png";
51
-
52
-const BIB_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Bib.png";
53
-const RU_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/RU.png";
54
-const ROOM_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Salles.png";
55
-const EMAIL_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Bluemind.png";
56
-const ENT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ENT.png";
57
-const ACCOUNT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Account.png";
58
-
59 41
 class ServicesScreen extends React.Component<Props, State> {
60 42
 
61 43
     amicaleDataset: cardList;
@@ -70,103 +52,10 @@ class ServicesScreen extends React.Component<Props, State> {
70 52
 
71 53
     constructor(props) {
72 54
         super(props);
73
-        const nav = props.navigation;
74
-        this.amicaleDataset = [
75
-            {
76
-                title: i18n.t('screens.clubs.title'),
77
-                subtitle: i18n.t('screens.services.descriptions.clubs'),
78
-                image: CLUBS_IMAGE,
79
-                onPress: () => this.onAmicaleServicePress("club-list"),
80
-            },
81
-            {
82
-                title: i18n.t('screens.profile.title'),
83
-                subtitle: i18n.t('screens.services.descriptions.profile'),
84
-                image: PROFILE_IMAGE,
85
-                onPress: () => this.onAmicaleServicePress("profile"),
86
-            },
87
-            {
88
-                title: i18n.t('screens.equipment.title'),
89
-                subtitle: i18n.t('screens.services.descriptions.equipment'),
90
-                image: EQUIPMENT_IMAGE,
91
-                onPress: () => this.onAmicaleServicePress("equipment-list"),
92
-            },
93
-            {
94
-                title: i18n.t('screens.websites.amicale'),
95
-                subtitle: i18n.t('screens.services.descriptions.amicaleWebsite'),
96
-                image: AMICALE_IMAGE,
97
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.AMICALE, title: i18n.t('screens.websites.amicale')}),
98
-            },
99
-            {
100
-                title: i18n.t('screens.vote.title'),
101
-                subtitle: i18n.t('screens.services.descriptions.vote'),
102
-                image: VOTE_IMAGE,
103
-                onPress: () => this.onAmicaleServicePress("vote"),
104
-            },
105
-        ];
106
-        this.studentsDataset = [
107
-            {
108
-                title: i18n.t('screens.proximo.title'),
109
-                subtitle: i18n.t('screens.services.descriptions.proximo'),
110
-                image: PROXIMO_IMAGE,
111
-                onPress: () => nav.navigate("proximo"),
112
-            },
113
-            {
114
-                title: "Wiketud",
115
-                subtitle: i18n.t('screens.services.descriptions.wiketud'),
116
-                image: WIKETUD_IMAGE,
117
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.WIKETUD, title: "Wiketud"}),
118
-            },
119
-            {
120
-                title: "Élus Étudiants",
121
-                subtitle: i18n.t('screens.services.descriptions.elusEtudiants'),
122
-                image: EE_IMAGE,
123
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.ELUS_ETUDIANTS, title: "Élus Étudiants"}),
124
-            },
125
-            {
126
-                title: "Tutor'INSA",
127
-                subtitle: i18n.t('screens.services.descriptions.tutorInsa'),
128
-                image: TUTORINSA_IMAGE,
129
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.TUTOR_INSA, title: "Tutor'INSA"})
130
-            },
131
-        ];
132
-        this.insaDataset = [
133
-            {
134
-                title: i18n.t('screens.menu.title'),
135
-                subtitle: i18n.t('screens.services.descriptions.self'),
136
-                image: RU_IMAGE,
137
-                onPress: () => nav.navigate("self-menu"),
138
-            },
139
-            {
140
-                title: i18n.t('screens.websites.rooms'),
141
-                subtitle: i18n.t('screens.services.descriptions.availableRooms'),
142
-                image: ROOM_IMAGE,
143
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.AVAILABLE_ROOMS, title: i18n.t('screens.websites.rooms')}),
144
-            },
145
-            {
146
-                title: i18n.t('screens.websites.bib'),
147
-                subtitle: i18n.t('screens.services.descriptions.bib'),
148
-                image: BIB_IMAGE,
149
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.BIB, title: i18n.t('screens.websites.bib')}),
150
-            },
151
-            {
152
-                title: i18n.t('screens.websites.mails'),
153
-                subtitle: i18n.t('screens.services.descriptions.mails'),
154
-                image: EMAIL_IMAGE,
155
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.BLUEMIND, title: i18n.t('screens.websites.mails')}),
156
-            },
157
-            {
158
-                title: i18n.t('screens.websites.ent'),
159
-                subtitle: i18n.t('screens.services.descriptions.ent'),
160
-                image: ENT_IMAGE,
161
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.ENT, title: i18n.t('screens.websites.ent')}),
162
-            },
163
-            {
164
-                title: i18n.t('screens.insaAccount.title'),
165
-                subtitle: i18n.t('screens.services.descriptions.insaAccount'),
166
-                image: ACCOUNT_IMAGE,
167
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.INSA_ACCOUNT, title: i18n.t('screens.insaAccount.title')}),
168
-            },
169
-        ];
55
+        const services = new ServicesManager(props.navigation);
56
+        this.amicaleDataset = services.getAmicaleServices();
57
+        this.studentsDataset = services.getStudentServices();
58
+        this.insaDataset = services.getINSAServices();
170 59
         this.finalDataset = [
171 60
             {
172 61
                 title: i18n.t("screens.services.categories.amicale"),

Loading…
Cancel
Save