Browse Source

Dashboard can now display any service from ServicesManager.js

Arnaud Vergnet 3 years ago
parent
commit
2022b738f5

+ 51
- 35
src/components/Home/SmallDashboardItem.js View File

@@ -1,17 +1,15 @@
1 1
 // @flow
2 2
 
3 3
 import * as React from 'react';
4
-import {Badge, IconButton, withTheme} from 'react-native-paper';
5
-import {View} from "react-native";
4
+import {Badge, TouchableRipple, withTheme} from 'react-native-paper';
5
+import {Dimensions, Image, View} from "react-native";
6 6
 import type {CustomTheme} from "../../managers/ThemeManager";
7 7
 import * as Animatable from "react-native-animatable";
8 8
 
9 9
 type Props = {
10
-    color: string,
11
-    icon: string,
12
-    clickAction: () => void,
13
-    isAvailable: boolean,
14
-    badgeNumber: number,
10
+    image: string,
11
+    onPress: () => void,
12
+    badgeCount: number | null,
15 13
     theme: CustomTheme,
16 14
 };
17 15
 
@@ -22,42 +20,60 @@ const AnimatableBadge = Animatable.createAnimatableComponent(Badge);
22 20
  */
23 21
 class SmallDashboardItem extends React.Component<Props> {
24 22
 
23
+    itemSize: number;
24
+
25
+    constructor(props: Props) {
26
+        super(props);
27
+        this.itemSize = Dimensions.get('window').width / 8;
28
+    }
29
+
25 30
     shouldComponentUpdate(nextProps: Props) {
26 31
         return (nextProps.theme.dark !== this.props.theme.dark)
27
-            || (nextProps.isAvailable !== this.props.isAvailable)
28
-            || (nextProps.badgeNumber !== this.props.badgeNumber);
32
+            || (nextProps.badgeCount !== this.props.badgeCount);
29 33
     }
30 34
 
31 35
     render() {
32 36
         const props = this.props;
33
-        const colors = props.theme.colors;
34 37
         return (
35
-            <View>
36
-                <IconButton
37
-                    icon={props.icon}
38
-                    color={
39
-                        props.isAvailable
40
-                            ? props.color
41
-                            : colors.textDisabled
42
-                    }
43
-                    size={35}
44
-                    onPress={props.clickAction}
45
-                />
46
-                {
47
-                    props.badgeNumber > 0 ?
48
-                        <AnimatableBadge
49
-                            animation={"zoomIn"}
50
-                            duration={300}
51
-                            useNativeDriver
38
+                <TouchableRipple
39
+                    onPress={this.props.onPress}
40
+                    borderless={true}
41
+                    style={{
42
+                        marginLeft: 5,
43
+                        marginRight: 5,
44
+                    }}
45
+                >
46
+                    <View style={{
47
+                        width: this.itemSize,
48
+                        height: this.itemSize,
49
+                    }}>
50
+                        <Image
51
+                            source={{uri: props.image}}
52 52
                             style={{
53
-                                position: 'absolute',
54
-                                top: 5,
55
-                                right: 5
56
-                            }}>
57
-                            {props.badgeNumber}
58
-                        </AnimatableBadge> : null
59
-                }
60
-            </View>
53
+                                width: "100%",
54
+                                height: "100%",
55
+                            }}
56
+                        />
57
+                        {
58
+                            props.badgeCount != null && props.badgeCount > 0 ?
59
+                                <AnimatableBadge
60
+                                    animation={"zoomIn"}
61
+                                    duration={300}
62
+                                    useNativeDriver
63
+                                    style={{
64
+                                        position: 'absolute',
65
+                                        top: 0,
66
+                                        right: 0,
67
+                                        backgroundColor: props.theme.colors.primary,
68
+                                        borderColor: "#fff",
69
+                                        borderWidth: 1,
70
+                                    }}>
71
+                                    {props.badgeCount}
72
+                                </AnimatableBadge> : null
73
+                        }
74
+                    </View>
75
+                </TouchableRipple>
76
+
61 77
         );
62 78
     }
63 79
 

+ 12
- 0
src/managers/AsyncStorageManager.js View File

@@ -1,6 +1,7 @@
1 1
 // @flow
2 2
 
3 3
 import AsyncStorage from '@react-native-community/async-storage';
4
+import {SERVICES_KEY} from "./ServicesManager";
4 5
 
5 6
 /**
6 7
  * Singleton used to manage preferences.
@@ -119,6 +120,17 @@ export default class AsyncStorageManager {
119 120
             default: '[]',
120 121
             current: '',
121 122
         },
123
+        dashboardItems: {
124
+            key: 'dashboardItems',
125
+            default: JSON.stringify([
126
+                SERVICES_KEY.EMAIL,
127
+                SERVICES_KEY.WASHERS,
128
+                SERVICES_KEY.PROXIMO,
129
+                SERVICES_KEY.TUTOR_INSA,
130
+                SERVICES_KEY.RU,
131
+            ]),
132
+            current: '',
133
+        },
122 134
     };
123 135
 
124 136
     /**

+ 26
- 0
src/managers/DashboardManager.js View File

@@ -0,0 +1,26 @@
1
+// @flow
2
+
3
+import type {ServiceItem} from "./ServicesManager";
4
+import ServicesManager from "./ServicesManager";
5
+import {StackNavigationProp} from "@react-navigation/stack";
6
+import {getSublistWithIds} from "../utils/Utils";
7
+import AsyncStorageManager from "./AsyncStorageManager";
8
+
9
+
10
+export default class DashboardManager extends ServicesManager{
11
+
12
+    constructor(nav: StackNavigationProp) {
13
+        super(nav)
14
+    }
15
+
16
+    getCurrentDashboard(): Array<ServiceItem> {
17
+        const dashboardIdList = JSON.parse(AsyncStorageManager.getInstance().preferences.dashboardItems.current);
18
+        const allDatasets = [
19
+            ...this.amicaleDataset,
20
+            ...this.studentsDataset,
21
+            ...this.insaDataset,
22
+            ...this.specialDataset,
23
+        ];
24
+        return getSublistWithIds(dashboardIdList, allDatasets);
25
+    }
26
+}

+ 94
- 41
src/managers/ServicesManager.js View File

@@ -1,22 +1,25 @@
1 1
 // @flow
2 2
 
3
-import type {cardList} from "../components/Lists/CardList/CardList";
4 3
 import i18n from "i18n-js";
5 4
 import AvailableWebsites from "../constants/AvailableWebsites";
6 5
 import {StackNavigationProp} from "@react-navigation/stack";
7 6
 import ConnectionManager from "./ConnectionManager";
7
+import type {fullDashboard} from "../screens/Home/HomeScreen";
8 8
 
9
+// AMICALE
9 10
 const CLUBS_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Clubs.png";
10 11
 const PROFILE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ProfilAmicaliste.png";
11 12
 const EQUIPMENT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Materiel.png";
12 13
 const VOTE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Vote.png";
13 14
 const AMICALE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/WebsiteAmicale.png";
14 15
 
16
+// STUDENTS
15 17
 const PROXIMO_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Proximo.png"
16 18
 const WIKETUD_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Wiketud.png";
17 19
 const EE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/EEC.png";
18 20
 const TUTORINSA_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/TutorINSA.png";
19 21
 
22
+// INSA
20 23
 const BIB_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Bib.png";
21 24
 const RU_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/RU.png";
22 25
 const ROOM_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Salles.png";
@@ -24,9 +27,13 @@ const EMAIL_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Bluemind.
24 27
 const ENT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ENT.png";
25 28
 const ACCOUNT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Account.png";
26 29
 
30
+// SPECIAL
31
+const WASHER_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ProxiwashLaveLinge.png";
32
+const DRYER_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ProxiwashSecheLinge.png";
33
+
27 34
 export const SERVICES_KEY = {
28 35
     CLUBS: "clubs",
29
-    PROFILE:"profile",
36
+    PROFILE: "profile",
30 37
     EQUIPMENT: "equipment",
31 38
     AMICALE_WEBSITE: "amicale_website",
32 39
     VOTE: "vote",
@@ -40,15 +47,27 @@ export const SERVICES_KEY = {
40 47
     EMAIL: "email",
41 48
     ENT: "ent",
42 49
     INSA_ACCOUNT: "insa_account",
50
+    WASHERS: "washers",
51
+    DRYERS: "dryers",
52
+}
53
+
54
+export type ServiceItem = {
55
+    key: string,
56
+    title: string,
57
+    subtitle: string,
58
+    image: string,
59
+    onPress: () => void,
60
+    badgeFunction?: (dashboard: fullDashboard) => number,
43 61
 }
44 62
 
45 63
 export default class ServicesManager {
46 64
 
47 65
     navigation: StackNavigationProp;
48 66
 
49
-    amicaleDataset: cardList;
50
-    studentsDataset: cardList;
51
-    insaDataset: cardList;
67
+    amicaleDataset: Array<ServiceItem>;
68
+    studentsDataset: Array<ServiceItem>;
69
+    insaDataset: Array<ServiceItem>;
70
+    specialDataset: Array<ServiceItem>;
52 71
 
53 72
     constructor(nav: StackNavigationProp) {
54 73
         this.navigation = nav;
@@ -79,7 +98,10 @@ export default class ServicesManager {
79 98
                 title: i18n.t('screens.websites.amicale'),
80 99
                 subtitle: i18n.t('screens.services.descriptions.amicaleWebsite'),
81 100
                 image: AMICALE_IMAGE,
82
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.AMICALE, title: i18n.t('screens.websites.amicale')}),
101
+                onPress: () => nav.navigate("website", {
102
+                    host: AvailableWebsites.websites.AMICALE,
103
+                    title: i18n.t('screens.websites.amicale')
104
+                }),
83 105
             },
84 106
             {
85 107
                 key: SERVICES_KEY.VOTE,
@@ -96,6 +118,7 @@ export default class ServicesManager {
96 118
                 subtitle: i18n.t('screens.services.descriptions.proximo'),
97 119
                 image: PROXIMO_IMAGE,
98 120
                 onPress: () => nav.navigate("proximo"),
121
+                badgeFunction: (dashboard: fullDashboard) => dashboard.proximo_articles
99 122
             },
100 123
             {
101 124
                 key: SERVICES_KEY.WIKETUD,
@@ -109,14 +132,21 @@ export default class ServicesManager {
109 132
                 title: "Élus Étudiants",
110 133
                 subtitle: i18n.t('screens.services.descriptions.elusEtudiants'),
111 134
                 image: EE_IMAGE,
112
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.WIKETUD, title: "Wiketud"}),
135
+                onPress: () => nav.navigate("website", {
136
+                    host: AvailableWebsites.websites.ELUS_ETUDIANTS,
137
+                    title: "Élus Étudiants"
138
+                }),
113 139
             },
114 140
             {
115 141
                 key: SERVICES_KEY.TUTOR_INSA,
116 142
                 title: "Tutor'INSA",
117 143
                 subtitle: i18n.t('screens.services.descriptions.tutorInsa'),
118 144
                 image: TUTORINSA_IMAGE,
119
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.TUTOR_INSA, title: "Tutor'INSA"})
145
+                onPress: () => nav.navigate("website", {
146
+                    host: AvailableWebsites.websites.TUTOR_INSA,
147
+                    title: "Tutor'INSA"
148
+                }),
149
+                badgeFunction: (dashboard: fullDashboard) => dashboard.available_tutorials
120 150
             },
121 151
         ];
122 152
         this.insaDataset = [
@@ -126,43 +156,77 @@ export default class ServicesManager {
126 156
                 subtitle: i18n.t('screens.services.descriptions.self'),
127 157
                 image: RU_IMAGE,
128 158
                 onPress: () => nav.navigate("self-menu"),
159
+                badgeFunction: (dashboard: fullDashboard) => dashboard.today_menu.length
129 160
             },
130 161
             {
131 162
                 key: SERVICES_KEY.AVAILABLE_ROOMS,
132 163
                 title: i18n.t('screens.websites.rooms'),
133 164
                 subtitle: i18n.t('screens.services.descriptions.availableRooms'),
134 165
                 image: ROOM_IMAGE,
135
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.AVAILABLE_ROOMS, title: i18n.t('screens.websites.rooms')}),
166
+                onPress: () => nav.navigate("website", {
167
+                    host: AvailableWebsites.websites.AVAILABLE_ROOMS,
168
+                    title: i18n.t('screens.websites.rooms')
169
+                }),
136 170
             },
137 171
             {
138 172
                 key: SERVICES_KEY.BIB,
139 173
                 title: i18n.t('screens.websites.bib'),
140 174
                 subtitle: i18n.t('screens.services.descriptions.bib'),
141 175
                 image: BIB_IMAGE,
142
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.BIB, title: i18n.t('screens.websites.bib')}),
176
+                onPress: () => nav.navigate("website", {
177
+                    host: AvailableWebsites.websites.BIB,
178
+                    title: i18n.t('screens.websites.bib')
179
+                }),
143 180
             },
144 181
             {
145 182
                 key: SERVICES_KEY.EMAIL,
146 183
                 title: i18n.t('screens.websites.mails'),
147 184
                 subtitle: i18n.t('screens.services.descriptions.mails'),
148 185
                 image: EMAIL_IMAGE,
149
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.BLUEMIND, title: i18n.t('screens.websites.mails')}),
186
+                onPress: () => nav.navigate("website", {
187
+                    host: AvailableWebsites.websites.BLUEMIND,
188
+                    title: i18n.t('screens.websites.mails')
189
+                }),
150 190
             },
151 191
             {
152 192
                 key: SERVICES_KEY.ENT,
153 193
                 title: i18n.t('screens.websites.ent'),
154 194
                 subtitle: i18n.t('screens.services.descriptions.ent'),
155 195
                 image: ENT_IMAGE,
156
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.ENT, title: i18n.t('screens.websites.ent')}),
196
+                onPress: () => nav.navigate("website", {
197
+                    host: AvailableWebsites.websites.ENT,
198
+                    title: i18n.t('screens.websites.ent')
199
+                }),
157 200
             },
158 201
             {
159 202
                 key: SERVICES_KEY.INSA_ACCOUNT,
160 203
                 title: i18n.t('screens.insaAccount.title'),
161 204
                 subtitle: i18n.t('screens.services.descriptions.insaAccount'),
162 205
                 image: ACCOUNT_IMAGE,
163
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.INSA_ACCOUNT, title: i18n.t('screens.insaAccount.title')}),
206
+                onPress: () => nav.navigate("website", {
207
+                    host: AvailableWebsites.websites.INSA_ACCOUNT,
208
+                    title: i18n.t('screens.insaAccount.title')
209
+                }),
164 210
             },
165 211
         ];
212
+        this.specialDataset = [
213
+            {
214
+                key: SERVICES_KEY.WASHERS,
215
+                title: i18n.t('screens.proxiwash.washers'),
216
+                subtitle: i18n.t('screens.proxiwash.title'), // TODO add description
217
+                image: WASHER_IMAGE,
218
+                onPress: () => nav.navigate("proxiwash"),
219
+                badgeFunction: (dashboard: fullDashboard) => dashboard.available_washers
220
+            },
221
+            {
222
+                key: SERVICES_KEY.DRYERS,
223
+                title: i18n.t('screens.proxiwash.dryers'),
224
+                subtitle: i18n.t('screens.proxiwash.title'), // TODO add description
225
+                image: DRYER_IMAGE,
226
+                onPress: () => nav.navigate("proxiwash"),
227
+                badgeFunction: (dashboard: fullDashboard) => dashboard.available_dryers
228
+            }
229
+        ]
166 230
     }
167 231
 
168 232
     /**
@@ -185,7 +249,7 @@ export default class ServicesManager {
185 249
      * @param sourceList The item list to use as source
186 250
      * @returns {[]}
187 251
      */
188
-    getStrippedList(idList: Array<string>, sourceList: cardList) {
252
+    getStrippedList(idList: Array<string>, sourceList: Array<ServiceItem>) {
189 253
         let newArray = [];
190 254
         for (let i = 0; i < sourceList.length; i++) {
191 255
             const item = sourceList[i];
@@ -196,34 +260,10 @@ export default class ServicesManager {
196 260
     }
197 261
 
198 262
     /**
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 263
      * Gets the list of amicale's services
224 264
      *
225 265
      * @param excludedItems Ids of items to exclude from the returned list
226
-     * @returns {cardList|*[]}
266
+     * @returns {Array<ServiceItem>}
227 267
      */
228 268
     getAmicaleServices(excludedItems?: Array<string>) {
229 269
         if (excludedItems != null)
@@ -236,7 +276,7 @@ export default class ServicesManager {
236 276
      * Gets the list of students' services
237 277
      *
238 278
      * @param excludedItems Ids of items to exclude from the returned list
239
-     * @returns {cardList|*[]}
279
+     * @returns {Array<ServiceItem>}
240 280
      */
241 281
     getStudentServices(excludedItems?: Array<string>) {
242 282
         if (excludedItems != null)
@@ -249,7 +289,7 @@ export default class ServicesManager {
249 289
      * Gets the list of INSA's services
250 290
      *
251 291
      * @param excludedItems Ids of items to exclude from the returned list
252
-     * @returns {cardList|*[]}
292
+     * @returns {Array<ServiceItem>}
253 293
      */
254 294
     getINSAServices(excludedItems?: Array<string>) {
255 295
         if (excludedItems != null)
@@ -258,4 +298,17 @@ export default class ServicesManager {
258 298
             return this.insaDataset;
259 299
     }
260 300
 
301
+    /**
302
+     * Gets the list of special services
303
+     *
304
+     * @param excludedItems Ids of items to exclude from the returned list
305
+     * @returns {Array<ServiceItem>}
306
+     */
307
+    getSpecialServices(excludedItems?: Array<string>) {
308
+        if (excludedItems != null)
309
+            return this.getStrippedList(excludedItems, this.specialDataset)
310
+        else
311
+            return this.specialDataset;
312
+    }
313
+
261 314
 }

+ 19
- 78
src/screens/Home/HomeScreen.js View File

@@ -20,9 +20,9 @@ import {View} from "react-native-animatable";
20 20
 import ConnectionManager from "../../managers/ConnectionManager";
21 21
 import LogoutDialog from "../../components/Amicale/LogoutDialog";
22 22
 import AsyncStorageManager from "../../managers/AsyncStorageManager";
23
-import AvailableWebsites from "../../constants/AvailableWebsites";
24 23
 import {MASCOT_STYLE} from "../../components/Mascot/Mascot";
25 24
 import MascotPopup from "../../components/Mascot/MascotPopup";
25
+import DashboardManager from "../../managers/DashboardManager";
26 26
 // import DATA from "../dashboard_data.json";
27 27
 
28 28
 
@@ -52,7 +52,7 @@ export type feedItem = {
52 52
     id: string,
53 53
 };
54 54
 
55
-type fullDashboard = {
55
+export type fullDashboard = {
56 56
     today_menu: Array<{ [key: string]: any }>,
57 57
     proximo_articles: number,
58 58
     available_dryers: number,
@@ -66,15 +66,6 @@ type dashboardItem = {
66 66
     content: Array<{ [key: string]: any }>
67 67
 };
68 68
 
69
-type dashboardSmallItem = {
70
-    id: string,
71
-    data: number,
72
-    icon: string,
73
-    color: string,
74
-    onPress: () => void,
75
-    isAvailable: boolean
76
-};
77
-
78 69
 export type event = {
79 70
     id: number,
80 71
     title: string,
@@ -113,11 +104,16 @@ class HomeScreen extends React.Component<Props, State> {
113 104
 
114 105
     fabRef: { current: null | AnimatedFAB };
115 106
     currentNewFeed: Array<feedItem>;
107
+    currentDashboard: fullDashboard | null;
108
+
109
+    dashboardManager: DashboardManager;
116 110
 
117 111
     constructor(props) {
118 112
         super(props);
119 113
         this.fabRef = React.createRef();
114
+        this.dashboardManager = new DashboardManager(this.props.navigation);
120 115
         this.currentNewFeed = [];
116
+        this.currentDashboard = null;
121 117
         this.isLoggedIn = ConnectionManager.getInstance().isLoggedIn();
122 118
         this.props.navigation.setOptions({
123 119
             headerRight: this.getHeaderButton,
@@ -207,22 +203,6 @@ class HomeScreen extends React.Component<Props, State> {
207 203
 
208 204
     hideDisconnectDialog = () => this.setState({dialogVisible: false});
209 205
 
210
-    onProxiwashClick = () => {
211
-        this.props.navigation.navigate("proxiwash");
212
-    };
213
-
214
-    onProximoClick = () => {
215
-        this.props.navigation.navigate("proximo");
216
-    };
217
-
218
-    onTutorInsaClick = () => {
219
-        this.props.navigation.navigate("website", {host: AvailableWebsites.websites.TUTOR_INSA, title: "Tutor'INSA"});
220
-    };
221
-
222
-    onMenuClick = () => {
223
-        this.props.navigation.navigate('self-menu');
224
-    };
225
-
226 206
     /**
227 207
      * Creates the dataset to be used in the FlatList
228 208
      *
@@ -232,9 +212,11 @@ class HomeScreen extends React.Component<Props, State> {
232 212
     createDataset = (fetchedData: rawDashboard) => {
233 213
         // fetchedData = DATA;
234 214
         let dashboardData;
235
-        if (fetchedData.news_feed != null) {
215
+        if (fetchedData.news_feed != null)
236 216
             this.currentNewFeed = fetchedData.news_feed.data;
237
-        }
217
+        if (fetchedData.dashboard != null)
218
+            this.currentDashboard = fetchedData.dashboard;
219
+
238 220
         if (fetchedData.dashboard != null)
239 221
             dashboardData = this.generateDashboardDataset(fetchedData.dashboard);
240 222
         else
@@ -264,48 +246,7 @@ class HomeScreen extends React.Component<Props, State> {
264 246
             {id: 'actions', content: []},
265 247
             {
266 248
                 id: 'top',
267
-                content: [
268
-                    {
269
-                        id: 'washers',
270
-                        data: dashboardData == null ? 0 : dashboardData.available_washers,
271
-                        icon: 'washing-machine',
272
-                        color: this.props.theme.colors.proxiwashColor,
273
-                        onPress: this.onProxiwashClick,
274
-                        isAvailable: dashboardData == null ? false : dashboardData.available_washers > 0
275
-                    },
276
-                    {
277
-                        id: 'dryers',
278
-                        data: dashboardData == null ? 0 : dashboardData.available_dryers,
279
-                        icon: 'tumble-dryer',
280
-                        color: this.props.theme.colors.proxiwashColor,
281
-                        onPress: this.onProxiwashClick,
282
-                        isAvailable: dashboardData == null ? false : dashboardData.available_dryers > 0
283
-                    },
284
-                    {
285
-                        id: 'available_tutorials',
286
-                        data: dashboardData == null ? 0 : dashboardData.available_tutorials,
287
-                        icon: 'school',
288
-                        color: this.props.theme.colors.tutorinsaColor,
289
-                        onPress: this.onTutorInsaClick,
290
-                        isAvailable: dashboardData == null ? false : dashboardData.available_tutorials > 0
291
-                    },
292
-                    {
293
-                        id: 'proximo_articles',
294
-                        data: dashboardData == null ? 0 : dashboardData.proximo_articles,
295
-                        icon: 'shopping',
296
-                        color: this.props.theme.colors.proximoColor,
297
-                        onPress: this.onProximoClick,
298
-                        isAvailable: dashboardData == null ? false : dashboardData.proximo_articles > 0
299
-                    },
300
-                    {
301
-                        id: 'today_menu',
302
-                        data: dashboardData == null ? [] : dashboardData.today_menu,
303
-                        icon: 'silverware-fork-knife',
304
-                        color: this.props.theme.colors.menuColor,
305
-                        onPress: this.onMenuClick,
306
-                        isAvailable: dashboardData == null ? false : dashboardData.today_menu.length > 0
307
-                    },
308
-                ]
249
+                content: this.dashboardManager.getCurrentDashboard(),
309 250
             },
310 251
             {
311 252
                 id: 'event',
@@ -491,14 +432,14 @@ class HomeScreen extends React.Component<Props, State> {
491 432
      * @param item
492 433
      * @returns {*}
493 434
      */
494
-    dashboardRowRenderItem = ({item}: { item: dashboardSmallItem }) => {
435
+    dashboardRowRenderItem = ({item}: { item: DashboardItem }) => {
495 436
         return (
496 437
             <SquareDashboardItem
497
-                color={item.color}
498
-                icon={item.icon}
499
-                clickAction={item.onPress}
500
-                isAvailable={item.isAvailable}
501
-                badgeNumber={item.data}
438
+                image={item.image}
439
+                onPress={item.onPress}
440
+                badgeCount={this.currentDashboard != null && item.badgeFunction != null
441
+                    ? item.badgeFunction(this.currentDashboard)
442
+                    : null}
502 443
             />
503 444
         );
504 445
     };
@@ -509,7 +450,7 @@ class HomeScreen extends React.Component<Props, State> {
509 450
      * @param content
510 451
      * @return {*}
511 452
      */
512
-    getDashboardRow(content: Array<dashboardSmallItem>) {
453
+    getDashboardRow(content: Array<DashboardItem>) {
513 454
         return (
514 455
             //$FlowFixMe
515 456
             <FlatList

+ 37
- 0
src/utils/Utils.js View File

@@ -0,0 +1,37 @@
1
+// @flow
2
+
3
+
4
+/**
5
+ * Gets a sublist of the given list with items of the given ids only
6
+ *
7
+ * The given list must have a field id or key
8
+ *
9
+ * @param idList The ids of items to find
10
+ * @param originalList The original list
11
+ * @returns {[]}
12
+ */
13
+export function getSublistWithIds(
14
+    idList: Array<string>,
15
+    originalList: Array<{ key: string, [key: string]: any }>
16
+): Array<{ key: string, [key: string]: any }> {
17
+    let subList = [];
18
+    for (let i = 0; i < subList.length; i++) {
19
+        subList.push(null);
20
+    }
21
+    let itemsAdded = 0;
22
+    for (let i = 0; i < originalList.length; i++) {
23
+        const item = originalList[i];
24
+        if (idList.includes(item.key)) {
25
+            subList[idList.indexOf(item.key)] = item;
26
+            itemsAdded++;
27
+            if (itemsAdded === idList.length)
28
+                break;
29
+        }
30
+    }
31
+    for (let i = 0; i < subList.length; i++) {
32
+        if (subList[i] == null)
33
+            subList.splice(i, 1);
34
+    }
35
+
36
+    return subList;
37
+}

Loading…
Cancel
Save