Browse Source

Improved doc

Arnaud Vergnet 4 years ago
parent
commit
fac9d8208e

+ 59
- 8
screens/HomeScreen.js View File

@@ -56,6 +56,7 @@ class HomeScreen extends React.Component<Props> {
56 56
 
57 57
     /**
58 58
      * Converts a dateString using Unix Timestamp to a formatted date
59
+     *
59 60
      * @param dateString {string} The Unix Timestamp representation of a date
60 61
      * @return {string} The formatted output date
61 62
      */
@@ -80,10 +81,22 @@ class HomeScreen extends React.Component<Props> {
80 81
         this.props.navigation.navigate('SelfMenuScreen');
81 82
     }
82 83
 
84
+    /**
85
+     * Extract a key for the given item
86
+     *
87
+     * @param item The item to extract the key from
88
+     * @return {*} The extracted key
89
+     */
83 90
     getKeyExtractor(item: Object) {
84 91
         return item !== undefined ? item.id : undefined;
85 92
     }
86 93
 
94
+    /**
95
+     * Creates the dataset to be used in the FlatList
96
+     *
97
+     * @param fetchedData
98
+     * @return {*}
99
+     */
87 100
     createDataset(fetchedData: Object) {
88 101
         // fetchedData = DATA;
89 102
         let newsData = [];
@@ -110,6 +123,12 @@ class HomeScreen extends React.Component<Props> {
110 123
         ];
111 124
     }
112 125
 
126
+    /**
127
+     * Generates the dataset associated to the dashboard to be displayed in the FlatList as a section
128
+     *
129
+     * @param dashboardData
130
+     * @return {*}
131
+     */
113 132
     generateDashboardDataset(dashboardData: Object) {
114 133
         let dataset = [
115 134
 
@@ -145,6 +164,12 @@ class HomeScreen extends React.Component<Props> {
145 164
         return dataset
146 165
     }
147 166
 
167
+    /**
168
+     * Gets a dashboard item
169
+     *
170
+     * @param item The item to display
171
+     * @return {*}
172
+     */
148 173
     getDashboardItem(item: Object) {
149 174
         let content = item['content'];
150 175
         if (item['id'] === 'event')
@@ -154,7 +179,7 @@ class HomeScreen extends React.Component<Props> {
154 179
     }
155 180
 
156 181
     /**
157
-     * Get the time limit depending on the current day:
182
+     * Gets the time limit depending on the current day:
158 183
      * 17:30 for every day of the week except for thursday 11:30
159 184
      * 00:00 on weekends
160 185
      */
@@ -170,7 +195,8 @@ class HomeScreen extends React.Component<Props> {
170 195
     }
171 196
 
172 197
     /**
173
-     * Get the duration (in milliseconds) of an event
198
+     * Gets the duration (in milliseconds) of an event
199
+     *
174 200
      * @param event {Object}
175 201
      * @return {number} The number of milliseconds
176 202
      */
@@ -184,7 +210,7 @@ class HomeScreen extends React.Component<Props> {
184 210
     }
185 211
 
186 212
     /**
187
-     * Get events starting after the limit
213
+     * Gets events starting after the limit
188 214
      *
189 215
      * @param events
190 216
      * @param limit
@@ -202,8 +228,9 @@ class HomeScreen extends React.Component<Props> {
202 228
     }
203 229
 
204 230
     /**
205
-     * Get the event with the longest duration in the given array.
231
+     * Gets the event with the longest duration in the given array.
206 232
      * If all events have the same duration, return the first in the array.
233
+     *
207 234
      * @param events
208 235
      */
209 236
     getLongestEvent(events: Array<Object>): Object {
@@ -220,7 +247,7 @@ class HomeScreen extends React.Component<Props> {
220 247
     }
221 248
 
222 249
     /**
223
-     * Get events that have not yet ended/started
250
+     * Gets events that have not yet ended/started
224 251
      *
225 252
      * @param events
226 253
      */
@@ -243,7 +270,7 @@ class HomeScreen extends React.Component<Props> {
243 270
     }
244 271
 
245 272
     /**
246
-     *
273
+     * Gets the event to display in the preview
247 274
      *
248 275
      * @param events
249 276
      * @return {Object}
@@ -266,7 +293,13 @@ class HomeScreen extends React.Component<Props> {
266 293
         return displayEvent;
267 294
     }
268 295
 
269
-
296
+    /**
297
+     * Gets the event render item.
298
+     * If a preview is available, it will be rendered inside
299
+     *
300
+     * @param content
301
+     * @return {*}
302
+     */
270 303
     getDashboardEventItem(content: Array<Object>) {
271 304
         let icon = 'calendar-range';
272 305
         let title = i18n.t('homeScreen.dashboard.todayEventsTitle');
@@ -310,7 +343,12 @@ class HomeScreen extends React.Component<Props> {
310 343
         );
311 344
     }
312 345
 
313
-
346
+    /**
347
+     * Gets a classic dashboard item.
348
+     *
349
+     * @param content
350
+     * @return {*}
351
+     */
314 352
     getDashboardMiddleItem(content: Array<Object>) {
315 353
         let proxiwashData = content[0]['data'];
316 354
         let tutorinsaData = content[1]['data'];
@@ -367,6 +405,12 @@ class HomeScreen extends React.Component<Props> {
367 405
         WebBrowser.openBrowserAsync(link);
368 406
     }
369 407
 
408
+    /**
409
+     * Gets a render item for the given feed object
410
+     *
411
+     * @param item The feed item to display
412
+     * @return {*}
413
+     */
370 414
     getFeedItem(item: Object) {
371 415
         const onImagePress = this.openLink.bind(this, item.full_picture);
372 416
         const onOutLinkPress = this.openLink.bind(this, item.permalink_url);
@@ -382,6 +426,13 @@ class HomeScreen extends React.Component<Props> {
382 426
         );
383 427
     }
384 428
 
429
+    /**
430
+     * Gets a FlatList render item
431
+     *
432
+     * @param item The item to display
433
+     * @param section The current section
434
+     * @return {*}
435
+     */
385 436
     getRenderItem({item, section}: Object) {
386 437
         return (section['id'] === SECTIONS_ID[0] ?
387 438
             this.getDashboardItem(item) : this.getFeedItem(item));

+ 1
- 1
screens/Planning/PlanningDisplayScreen.js View File

@@ -18,7 +18,7 @@ function openWebLink(event, link) {
18 18
 }
19 19
 
20 20
 /**
21
- * Class defining an about screen. This screen shows the user information about the app and it's author.
21
+ * Class defining a planning event information page.
22 22
  */
23 23
 class PlanningDisplayScreen extends React.Component<Props> {
24 24
 

+ 37
- 2
screens/Planning/PlanningScreen.js View File

@@ -78,6 +78,9 @@ export default class PlanningScreen extends React.Component<Props, State> {
78 78
         this.onBackButtonPressAndroid = this.onBackButtonPressAndroid.bind(this);
79 79
     }
80 80
 
81
+    /**
82
+     * Captures focus and blur events to hook on android back button
83
+     */
81 84
     componentDidMount() {
82 85
         this.onRefresh();
83 86
         this.didFocusSubscription = this.props.navigation.addListener(
@@ -98,6 +101,11 @@ export default class PlanningScreen extends React.Component<Props, State> {
98 101
         );
99 102
     }
100 103
 
104
+    /**
105
+     * Overrides default android back button behaviour to close the calendar if it was open.
106
+     *
107
+     * @return {boolean}
108
+     */
101 109
     onBackButtonPressAndroid() {
102 110
         if (this.state.calendarShowing) {
103 111
             this.agendaRef.chooseDay(this.agendaRef.state.selectedDay);
@@ -107,6 +115,13 @@ export default class PlanningScreen extends React.Component<Props, State> {
107 115
         }
108 116
     };
109 117
 
118
+    /**
119
+     * Function used to check if a row has changed
120
+     *
121
+     * @param r1
122
+     * @param r2
123
+     * @return {boolean}
124
+     */
110 125
     rowHasChanged(r1: Object, r2: Object) {
111 126
         return false;
112 127
         // if (r1 !== undefined && r2 !== undefined)
@@ -115,8 +130,7 @@ export default class PlanningScreen extends React.Component<Props, State> {
115 130
     }
116 131
 
117 132
     /**
118
-     * Refresh data and show a toast if any error occurred
119
-     * @private
133
+     * Refreshes data and shows an animation while doing it
120 134
      */
121 135
     onRefresh = () => {
122 136
         let canRefresh;
@@ -143,14 +157,30 @@ export default class PlanningScreen extends React.Component<Props, State> {
143 157
         }
144 158
     };
145 159
 
160
+    /**
161
+     * Callback used when receiving the agenda ref
162
+     *
163
+     * @param ref
164
+     */
146 165
     onAgendaRef(ref: Object) {
147 166
         this.agendaRef = ref;
148 167
     }
149 168
 
169
+    /**
170
+     * Callback used when a button is pressed to toggle the calendar
171
+     *
172
+     * @param isCalendarOpened True is the calendar is already open, false otherwise
173
+     */
150 174
     onCalendarToggled(isCalendarOpened: boolean) {
151 175
         this.setState({calendarShowing: isCalendarOpened});
152 176
     }
153 177
 
178
+    /**
179
+     * Gets an event render item
180
+     *
181
+     * @param item The current event to render
182
+     * @return {*}
183
+     */
154 184
     getRenderItem(item: eventObject) {
155 185
         const onPress = this.props.navigation.navigate.bind(this, 'PlanningDisplayScreen', {data: item});
156 186
         if (item.logo !== null) {
@@ -182,6 +212,11 @@ export default class PlanningScreen extends React.Component<Props, State> {
182 212
         }
183 213
     }
184 214
 
215
+    /**
216
+     * Gets an empty render item for an empty date
217
+     *
218
+     * @return {*}
219
+     */
185 220
     getRenderEmptyDate() {
186 221
         return (
187 222
             <Divider/>

+ 1
- 1
screens/Proximo/ProximoAboutScreen.js View File

@@ -10,7 +10,7 @@ type Props = {
10 10
 };
11 11
 
12 12
 /**
13
- * Class defining an about screen. This screen shows the user information about the app and it's author.
13
+ * Class defining the proximo about screen.
14 14
  */
15 15
 export default class ProximoAboutScreen extends React.Component<Props> {
16 16
 

+ 99
- 38
screens/Proximo/ProximoListScreen.js View File

@@ -1,7 +1,7 @@
1 1
 // @flow
2 2
 
3 3
 import * as React from 'react';
4
-import {Platform, Image, ScrollView, View} from "react-native";
4
+import {Image, Platform, ScrollView, View} from "react-native";
5 5
 import i18n from "i18n-js";
6 6
 import CustomModal from "../../components/CustomModal";
7 7
 import {Avatar, IconButton, List, RadioButton, Searchbar, Subheading, Text, Title, withTheme} from "react-native-paper";
@@ -77,10 +77,10 @@ class ProximoListScreen extends React.Component<Props, State> {
77 77
 
78 78
 
79 79
     /**
80
-     * Set the sort mode from state when components are ready
80
+     * Creates the header content
81 81
      */
82 82
     componentDidMount() {
83
-        const button = this.getSortMenu.bind(this);
83
+        const button = this.getSortMenuButton.bind(this);
84 84
         const title = this.getSearchBar.bind(this);
85 85
         this.props.navigation.setOptions({
86 86
             headerRight: button,
@@ -93,7 +93,50 @@ class ProximoListScreen extends React.Component<Props, State> {
93 93
     }
94 94
 
95 95
     /**
96
-     * Set the current sort mode.
96
+     * Gets the header search bar
97
+     *
98
+     * @return {*}
99
+     */
100
+    getSearchBar() {
101
+        return (
102
+            <Searchbar
103
+                placeholder={i18n.t('proximoScreen.search')}
104
+                onChangeText={this.onSearchStringChange}
105
+            />
106
+        );
107
+    }
108
+
109
+    /**
110
+     * Gets the sort menu header button
111
+     *
112
+     * @return {*}
113
+     */
114
+    getSortMenuButton() {
115
+        return (
116
+            <IconButton
117
+                icon="sort"
118
+                color={this.colors.text}
119
+                size={26}
120
+                onPress={this.onSortMenuPress}
121
+            />
122
+        );
123
+    }
124
+
125
+    /**
126
+     * Callback used when clicking on the sort menu button.
127
+     * It will open the modal to show a sort selection
128
+     */
129
+    onSortMenuPress() {
130
+        this.setState({
131
+            modalCurrentDisplayItem: this.getModalSortMenu()
132
+        });
133
+        if (this.modalRef) {
134
+            this.modalRef.open();
135
+        }
136
+    }
137
+
138
+    /**
139
+     * Sets the current sort mode.
97 140
      *
98 141
      * @param mode The number representing the mode
99 142
      */
@@ -121,19 +164,10 @@ class ProximoListScreen extends React.Component<Props, State> {
121 164
         }
122 165
     }
123 166
 
124
-    getSearchBar() {
125
-        return (
126
-            <Searchbar
127
-                placeholder={i18n.t('proximoScreen.search')}
128
-                onChangeText={this.onSearchStringChange}
129
-            />
130
-        );
131
-    }
132
-
133 167
     /**
134
-     * get color depending on quantity available
168
+     * Gets a color depending on the quantity available
135 169
      *
136
-     * @param availableStock
170
+     * @param availableStock The quantity available
137 171
      * @return
138 172
      */
139 173
     getStockColor(availableStock: number) {
@@ -147,13 +181,21 @@ class ProximoListScreen extends React.Component<Props, State> {
147 181
         return color;
148 182
     }
149 183
 
150
-    sanitizeString(str: string) {
184
+    /**
185
+     * Sanitizes the given string to improve search performance
186
+     *
187
+     * @param str The string to sanitize
188
+     * @return {string} The sanitized string
189
+     */
190
+    sanitizeString(str: string): string {
151 191
         return str.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
152 192
     }
153 193
 
154 194
     /**
155
-     * Returns only the articles whose name contains str. Case and accents insensitive.
156
-     * @param str
195
+     * Returns only articles whose name contains the given string.
196
+     * Case and accents insensitive.
197
+     *
198
+     * @param str The string used to filter article names
157 199
      * @returns {[]}
158 200
      */
159 201
     filterData(str: string) {
@@ -169,12 +211,23 @@ class ProximoListScreen extends React.Component<Props, State> {
169 211
         return filteredData;
170 212
     }
171 213
 
214
+    /**
215
+     * Callback used when the search changes
216
+     *
217
+     * @param str The new search string
218
+     */
172 219
     onSearchStringChange(str: string) {
173 220
         this.setState({
174 221
             currentlyDisplayedData: this.filterData(str)
175 222
         })
176 223
     }
177 224
 
225
+    /**
226
+     * Gets the modal content depending on the given article
227
+     *
228
+     * @param item The article to display
229
+     * @return {*}
230
+     */
178 231
     getModalItemContent(item: Object) {
179 232
         return (
180 233
             <View style={{
@@ -206,6 +259,11 @@ class ProximoListScreen extends React.Component<Props, State> {
206 259
         );
207 260
     }
208 261
 
262
+    /**
263
+     * Gets the modal content to display a sort menu
264
+     *
265
+     * @return {*}
266
+     */
209 267
     getModalSortMenu() {
210 268
         return (
211 269
             <View style={{
@@ -254,6 +312,12 @@ class ProximoListScreen extends React.Component<Props, State> {
254 312
         );
255 313
     }
256 314
 
315
+    /**
316
+     * Callback used when clicking an article in the list.
317
+     * It opens the modal to show detailed information about the article
318
+     *
319
+     * @param item The article pressed
320
+     */
257 321
     onListItemPress(item: Object) {
258 322
         this.setState({
259 323
             modalCurrentDisplayItem: this.getModalItemContent(item)
@@ -263,26 +327,12 @@ class ProximoListScreen extends React.Component<Props, State> {
263 327
         }
264 328
     }
265 329
 
266
-    onSortMenuPress() {
267
-        this.setState({
268
-            modalCurrentDisplayItem: this.getModalSortMenu()
269
-        });
270
-        if (this.modalRef) {
271
-            this.modalRef.open();
272
-        }
273
-    }
274
-
275
-    getSortMenu() {
276
-        return (
277
-            <IconButton
278
-                icon="sort"
279
-                color={this.colors.text}
280
-                size={26}
281
-                onPress={this.onSortMenuPress}
282
-            />
283
-        );
284
-    }
285
-
330
+    /**
331
+     * Gets a render item for the given article
332
+     *
333
+     * @param item The article to render
334
+     * @return {*}
335
+     */
286 336
     renderItem({item}: Object) {
287 337
         const onPress = this.onListItemPress.bind(this, item);
288 338
         return (
@@ -301,10 +351,21 @@ class ProximoListScreen extends React.Component<Props, State> {
301 351
         );
302 352
     }
303 353
 
354
+    /**
355
+     * Extracts a key for the given article
356
+     *
357
+     * @param item The article to extract the key from
358
+     * @return {*} The extracted key
359
+     */
304 360
     keyExtractor(item: Object) {
305 361
         return item.name + item.code;
306 362
     }
307 363
 
364
+    /**
365
+     * Callback used when receiving the modal ref
366
+     *
367
+     * @param ref
368
+     */
308 369
     onModalRef(ref: Object) {
309 370
         this.modalRef = ref;
310 371
     }

+ 76
- 36
screens/Proximo/ProximoMainScreen.js View File

@@ -18,8 +18,8 @@ type State = {
18 18
 }
19 19
 
20 20
 /**
21
- * Class defining the main proximo screen. This screen shows the different categories of articles
22
- * offered by proximo.
21
+ * Class defining the main proximo screen.
22
+ * This screen shows the different categories of articles offered by proximo.
23 23
  */
24 24
 class ProximoMainScreen extends React.Component<Props, State> {
25 25
 
@@ -41,6 +41,14 @@ class ProximoMainScreen extends React.Component<Props, State> {
41 41
         this.colors = props.theme.colors;
42 42
     }
43 43
 
44
+    /**
45
+     * Function used to sort items in the list.
46
+     * Makes the All category stick to the top and sorts the others by name ascending
47
+     *
48
+     * @param a
49
+     * @param b
50
+     * @return {number}
51
+     */
44 52
     static sortFinalData(a: Object, b: Object) {
45 53
         let str1 = a.type.name.toLowerCase();
46 54
         let str2 = b.type.name.toLowerCase();
@@ -59,17 +67,76 @@ class ProximoMainScreen extends React.Component<Props, State> {
59 67
         return 0;
60 68
     }
61 69
 
70
+    /**
71
+     * Creates header button
72
+     */
62 73
     componentDidMount() {
63
-        const rightButton = this.getRightButton.bind(this);
74
+        const rightButton = this.getHeaderButtons.bind(this);
64 75
         this.props.navigation.setOptions({
65 76
             headerRight: rightButton,
66 77
         });
67 78
     }
68 79
 
80
+    /**
81
+     * Callback used when the search button is pressed.
82
+     * This will open a new ProximoListScreen with all items displayed
83
+     */
84
+    onPressSearchBtn() {
85
+        let searchScreenData = {
86
+            shouldFocusSearchBar: true,
87
+            data: {
88
+                type: {
89
+                    id: "0",
90
+                    name: i18n.t('proximoScreen.all'),
91
+                    icon: 'star'
92
+                },
93
+                data: this.articles !== undefined ?
94
+                    this.getAvailableArticles(this.articles, undefined) : []
95
+            },
96
+        };
97
+        this.props.navigation.navigate('ProximoListScreen', searchScreenData);
98
+    }
99
+
100
+    /**
101
+     * Callback used when the about button is pressed.
102
+     * This will open the ProximoAboutScreen
103
+     */
104
+    onPressAboutBtn() {
105
+        this.props.navigation.navigate('ProximoAboutScreen');
106
+    }
107
+
108
+    /**
109
+     * Gets the header buttons
110
+     * @return {*}
111
+     */
112
+    getHeaderButtons() {
113
+        return (
114
+            <View
115
+                style={{
116
+                    flexDirection: 'row',
117
+                }}>
118
+                <HeaderButton icon={'magnify'} onPress={this.onPressSearchBtn}/>
119
+                <HeaderButton icon={'information'} onPress={this.onPressAboutBtn}/>
120
+            </View>
121
+        );
122
+    }
123
+
124
+    /**
125
+     * Extracts a key for the given category
126
+     *
127
+     * @param item The category to extract the key from
128
+     * @return {*} The extracted key
129
+     */
69 130
     getKeyExtractor(item: Object) {
70 131
         return item !== undefined ? item.type['id'] : undefined;
71 132
     }
72 133
 
134
+    /**
135
+     * Creates the dataset to be used in the FlatList
136
+     *
137
+     * @param fetchedData
138
+     * @return {*}
139
+     * */
73 140
     createDataset(fetchedData: Object) {
74 141
         return [
75 142
             {
@@ -133,39 +200,12 @@ class ProximoMainScreen extends React.Component<Props, State> {
133 200
         return availableArticles;
134 201
     }
135 202
 
136
-    onPressSearchBtn() {
137
-        let searchScreenData = {
138
-            shouldFocusSearchBar: true,
139
-            data: {
140
-                type: {
141
-                    id: "0",
142
-                    name: i18n.t('proximoScreen.all'),
143
-                    icon: 'star'
144
-                },
145
-                data: this.articles !== undefined ?
146
-                    this.getAvailableArticles(this.articles, undefined) : []
147
-            },
148
-        };
149
-        this.props.navigation.navigate('ProximoListScreen', searchScreenData);
150
-    }
151
-
152
-    onPressAboutBtn() {
153
-        this.props.navigation.navigate('ProximoAboutScreen');
154
-    }
155
-
156
-    getRightButton() {
157
-        return (
158
-            <View
159
-                style={{
160
-                    flexDirection: 'row',
161
-                }}>
162
-                <HeaderButton icon={'magnify'} onPress={this.onPressSearchBtn}/>
163
-                <HeaderButton icon={'information'} onPress={this.onPressAboutBtn}/>
164
-            </View>
165
-        );
166
-    }
167
-
168
-
203
+    /**
204
+     * Gets the given category render item
205
+     *
206
+     * @param item The category to render
207
+     * @return {*}
208
+     */
169 209
     getRenderItem({item}: Object) {
170 210
         let dataToSend = {
171 211
             shouldFocusSearchBar: false,

+ 1
- 1
screens/Proxiwash/ProxiwashAboutScreen.js View File

@@ -10,7 +10,7 @@ type Props = {
10 10
 };
11 11
 
12 12
 /**
13
- * Class defining an about screen. This screen shows the user information about the app and it's author.
13
+ * Class defining the proxiwash about screen.
14 14
  */
15 15
 export default class ProxiwashAboutScreen extends React.Component<Props> {
16 16
 

+ 83
- 27
screens/Proxiwash/ProxiwashScreen.js View File

@@ -58,7 +58,6 @@ class ProxiwashScreen extends React.Component<Props, State> {
58 58
         refreshing: false,
59 59
         firstLoading: true,
60 60
         fetchedData: {},
61
-        // machinesWatched: JSON.parse(dataString),
62 61
         machinesWatched: [],
63 62
         modalCurrentDisplayItem: null,
64 63
         bannerVisible: AsyncStorageManager.getInstance().preferences.proxiwashShowBanner.current === '1',
@@ -97,6 +96,10 @@ class ProxiwashScreen extends React.Component<Props, State> {
97 96
         this.colors = props.theme.colors;
98 97
     }
99 98
 
99
+    /**
100
+     * Callback used when closing the banner.
101
+     * This hides the banner and saves to preferences to prevent it from reopening
102
+     */
100 103
     onHideBanner() {
101 104
         this.setState({bannerVisible: false});
102 105
         AsyncStorageManager.getInstance().savePref(
@@ -109,7 +112,7 @@ class ProxiwashScreen extends React.Component<Props, State> {
109 112
      * Setup notification channel for android and add listeners to detect notifications fired
110 113
      */
111 114
     componentDidMount() {
112
-        const rightButton = this.getRightButton.bind(this);
115
+        const rightButton = this.getAboutButton.bind(this);
113 116
         this.props.navigation.setOptions({
114 117
             headerRight: rightButton,
115 118
         });
@@ -134,16 +137,35 @@ class ProxiwashScreen extends React.Component<Props, State> {
134 137
         }
135 138
     }
136 139
 
137
-    getDryersKeyExtractor(item: Object) {
138
-        return item !== undefined ? "dryer" + item.number : undefined;
140
+    /**
141
+     * Callback used when pressing the about button.
142
+     * This will open the ProxiwashAboutScreen.
143
+     */
144
+    onAboutPress() {
145
+        this.props.navigation.navigate('ProxiwashAboutScreen');
139 146
     }
140 147
 
141
-    getWashersKeyExtractor(item: Object) {
142
-        return item !== undefined ? "washer" + item.number : undefined;
148
+    /**
149
+     * Gets the about header button
150
+     *
151
+     * @return {*}
152
+     */
153
+    getAboutButton() {
154
+        return <HeaderButton icon={'information'} onPress={this.onAboutPress}/>;
143 155
     }
144 156
 
145 157
     /**
146
-     * Setup notifications for the machine with the given ID.
158
+     * Extracts the key for the given item
159
+     *
160
+     * @param item The item to extract the key from
161
+     * @return {*} The extracted key
162
+     */
163
+    getKeyExtractor(item: Object) {
164
+        return item !== undefined ? item.number : undefined;
165
+    }
166
+
167
+    /**
168
+     * Setups notifications for the machine with the given ID.
147 169
      * One notification will be sent at the end of the program.
148 170
      * Another will be send a few minutes before the end, based on the value of reminderNotifTime
149 171
      *
@@ -162,6 +184,9 @@ class ProxiwashScreen extends React.Component<Props, State> {
162 184
         }
163 185
     }
164 186
 
187
+    /**
188
+     * Shows a warning telling the user notifications are disabled for the app
189
+     */
165 190
     showNotificationsDisabledWarning() {
166 191
         Alert.alert(
167 192
             i18n.t("proxiwashScreen.modal.notificationErrorTitle"),
@@ -170,7 +195,7 @@ class ProxiwashScreen extends React.Component<Props, State> {
170 195
     }
171 196
 
172 197
     /**
173
-     * Stop scheduled notifications for the machine of the given ID.
198
+     * Stops scheduled notifications for the machine of the given ID.
174 199
      * This will also remove the notification if it was already shown.
175 200
      *
176 201
      * @param machineId The machine's ID
@@ -187,7 +212,7 @@ class ProxiwashScreen extends React.Component<Props, State> {
187 212
     }
188 213
 
189 214
     /**
190
-     * Add the given notifications associated to a machine ID to the watchlist, and save the array to the preferences
215
+     * Adds the given notifications associated to a machine ID to the watchlist, and saves the array to the preferences
191 216
      *
192 217
      * @param machineId
193 218
      */
@@ -198,7 +223,7 @@ class ProxiwashScreen extends React.Component<Props, State> {
198 223
     }
199 224
 
200 225
     /**
201
-     * remove the given index from the watchlist array and save it to preferences
226
+     * Removes the given index from the watchlist array and saves it to preferences
202 227
      *
203 228
      * @param index
204 229
      */
@@ -209,14 +234,12 @@ class ProxiwashScreen extends React.Component<Props, State> {
209 234
     }
210 235
 
211 236
     /**
212
-     * Set the given data as the watchlist and save it to preferences
237
+     * Sets the given data as the watchlist
213 238
      *
214 239
      * @param data
215 240
      */
216 241
     updateNotificationState(data: Array<Object>) {
217 242
         this.setState({machinesWatched: data});
218
-        // let prefKey = AsyncStorageManager.getInstance().preferences.proxiwashWatchedMachines.key;
219
-        // AsyncStorageManager.getInstance().savePref(prefKey, JSON.stringify(data));
220 243
     }
221 244
 
222 245
     /**
@@ -229,6 +252,12 @@ class ProxiwashScreen extends React.Component<Props, State> {
229 252
         return this.state.machinesWatched.indexOf(machineID) !== -1;
230 253
     }
231 254
 
255
+    /**
256
+     * Creates the dataset to be used by the flatlist
257
+     *
258
+     * @param fetchedData
259
+     * @return {*}
260
+     */
232 261
     createDataset(fetchedData: Object) {
233 262
         let data = fetchedData;
234 263
         if (AprilFoolsManager.getInstance().isAprilFoolsEnabled()) {
@@ -244,18 +273,25 @@ class ProxiwashScreen extends React.Component<Props, State> {
244 273
                 icon: 'tumble-dryer',
245 274
                 data: data.dryers === undefined ? [] : data.dryers,
246 275
                 extraData: this.state,
247
-                keyExtractor: this.getDryersKeyExtractor
276
+                keyExtractor: this.getKeyExtractor
248 277
             },
249 278
             {
250 279
                 title: i18n.t('proxiwashScreen.washers'),
251 280
                 icon: 'washing-machine',
252 281
                 data: data.washers === undefined ? [] : data.washers,
253 282
                 extraData: this.state,
254
-                keyExtractor: this.getWashersKeyExtractor
283
+                keyExtractor: this.getKeyExtractor
255 284
             },
256 285
         ];
257 286
     }
258 287
 
288
+    /**
289
+     * Shows a modal for the given item
290
+     *
291
+     * @param title The title to use
292
+     * @param item The item to display information for in the modal
293
+     * @param isDryer True if the given item is a dryer
294
+     */
259 295
     showModal(title: string, item: Object, isDryer: boolean) {
260 296
         this.setState({
261 297
             modalCurrentDisplayItem: this.getModalContent(title, item, isDryer)
@@ -265,6 +301,11 @@ class ProxiwashScreen extends React.Component<Props, State> {
265 301
         }
266 302
     }
267 303
 
304
+    /**
305
+     * Callback used when the user clicks on enable notifications for a machine
306
+     *
307
+     * @param machineId The machine's id to set notifications for
308
+     */
268 309
     onSetupNotificationsPress(machineId: string) {
269 310
         if (this.modalRef) {
270 311
             this.modalRef.close();
@@ -272,6 +313,15 @@ class ProxiwashScreen extends React.Component<Props, State> {
272 313
         this.setupNotifications(machineId)
273 314
     }
274 315
 
316
+    /**
317
+     * Generates the modal content.
318
+     * This shows information for the given machine.
319
+     *
320
+     * @param title The title to use
321
+     * @param item The item to display information for in the modal
322
+     * @param isDryer True if the given item is a dryer
323
+     * @return {*}
324
+     */
275 325
     getModalContent(title: string, item: Object, isDryer: boolean) {
276 326
         let button = {
277 327
             text: i18n.t("proxiwashScreen.modal.ok"),
@@ -334,20 +384,21 @@ class ProxiwashScreen extends React.Component<Props, State> {
334 384
         );
335 385
     }
336 386
 
337
-    onAboutPress() {
338
-        this.props.navigation.navigate('ProxiwashAboutScreen');
339
-    }
340
-
341
-    getRightButton() {
342
-        return (
343
-            <HeaderButton icon={'information'} onPress={this.onAboutPress}/>
344
-        );
345
-    }
346
-
387
+    /**
388
+     * Callback used when receiving modal ref
389
+     *
390
+     * @param ref
391
+     */
347 392
     onModalRef(ref: Object) {
348 393
         this.modalRef = ref;
349 394
     }
350 395
 
396
+    /**
397
+     * Gets the number of machines available
398
+     *
399
+     * @param isDryer True if we are only checking for dryer, false for washers
400
+     * @return {number} The number of machines available
401
+     */
351 402
     getMachineAvailableNumber(isDryer: boolean) {
352 403
         let data;
353 404
         if (isDryer)
@@ -362,6 +413,12 @@ class ProxiwashScreen extends React.Component<Props, State> {
362 413
         return count;
363 414
     }
364 415
 
416
+    /**
417
+     * Gets the section render item
418
+     *
419
+     * @param section The section to render
420
+     * @return {*}
421
+     */
365 422
     getRenderSectionHeader({section}: Object) {
366 423
         const isDryer = section.title === i18n.t('proxiwashScreen.dryers');
367 424
         const nbAvailable = this.getMachineAvailableNumber(isDryer);
@@ -401,7 +458,7 @@ class ProxiwashScreen extends React.Component<Props, State> {
401 458
     }
402 459
 
403 460
     /**
404
-     * Get list item to be rendered
461
+     * Gets the list item to be rendered
405 462
      *
406 463
      * @param item The object containing the item's FetchedData
407 464
      * @param section The object describing the current SectionList section
@@ -467,7 +524,6 @@ class ProxiwashScreen extends React.Component<Props, State> {
467 524
                     refreshOnFocus={true}
468 525
                     updateData={this.state.machinesWatched.length}/>
469 526
             </View>
470
-
471 527
         );
472 528
     }
473 529
 }

+ 30
- 1
screens/SelfMenuScreen.js View File

@@ -15,7 +15,6 @@ type Props = {
15 15
 
16 16
 /**
17 17
  * Class defining the app's menu screen.
18
- * This screen fetches data from etud to render the RU menu
19 18
  */
20 19
 class SelfMenuScreen extends React.Component<Props> {
21 20
 
@@ -33,10 +32,22 @@ class SelfMenuScreen extends React.Component<Props> {
33 32
         this.colors = props.theme.colors;
34 33
     }
35 34
 
35
+    /**
36
+     * Extract a key for the given item
37
+     *
38
+     * @param item The item to extract the key from
39
+     * @return {*} The extracted key
40
+     */
36 41
     getKeyExtractor(item: Object) {
37 42
         return item !== undefined ? item['name'] : undefined;
38 43
     }
39 44
 
45
+    /**
46
+     * Creates the dataset to be used in the FlatList
47
+     *
48
+     * @param fetchedData
49
+     * @return {[]}
50
+     */
40 51
     createDataset(fetchedData: Object) {
41 52
         let result = [];
42 53
         // Prevent crash by giving a default value when fetchedData is empty (not yet available)
@@ -66,6 +77,12 @@ class SelfMenuScreen extends React.Component<Props> {
66 77
         return result
67 78
     }
68 79
 
80
+    /**
81
+     * Gets the render section header
82
+     *
83
+     * @param section The section to render the header from
84
+     * @return {*}
85
+     */
69 86
     getRenderSectionHeader({section}: Object) {
70 87
         return (
71 88
             <Card style={{
@@ -92,6 +109,12 @@ class SelfMenuScreen extends React.Component<Props> {
92 109
         );
93 110
     }
94 111
 
112
+    /**
113
+     * Gets a FlatList render item
114
+     *
115
+     * @param item The item to render
116
+     * @return {*}
117
+     */
95 118
     getRenderItem({item}: Object) {
96 119
         return (
97 120
             <Card style={{
@@ -128,6 +151,12 @@ class SelfMenuScreen extends React.Component<Props> {
128 151
         );
129 152
     }
130 153
 
154
+    /**
155
+     * Formats the given string to make sure it starts with a capital letter
156
+     *
157
+     * @param name The string to format
158
+     * @return {string} The formatted string
159
+     */
131 160
     formatName(name: String) {
132 161
         return name.charAt(0) + name.substr(1).toLowerCase();
133 162
     }

+ 14
- 15
screens/SettingsScreen.js View File

@@ -27,7 +27,7 @@ export default class SettingsScreen extends React.Component<Props, State> {
27 27
     state = {
28 28
         nightMode: ThemeManager.getNightMode(),
29 29
         nightModeFollowSystem: AsyncStorageManager.getInstance().preferences.nightModeFollowSystem.current === '1' &&
30
-        Appearance.getColorScheme() !== 'no-preference',
30
+            Appearance.getColorScheme() !== 'no-preference',
31 31
         proxiwashNotifPickerSelected: AsyncStorageManager.getInstance().preferences.proxiwashNotifications.current,
32 32
         startScreenPickerSelected: AsyncStorageManager.getInstance().preferences.defaultStartScreen.current,
33 33
     };
@@ -46,7 +46,7 @@ export default class SettingsScreen extends React.Component<Props, State> {
46 46
     }
47 47
 
48 48
     /**
49
-     * Save the value for the proxiwash reminder notification time
49
+     * Saves the value for the proxiwash reminder notification time
50 50
      *
51 51
      * @param value The value to store
52 52
      */
@@ -65,7 +65,7 @@ export default class SettingsScreen extends React.Component<Props, State> {
65 65
     }
66 66
 
67 67
     /**
68
-     * Save the value for the proxiwash reminder notification time
68
+     * Saves the value for the proxiwash reminder notification time
69 69
      *
70 70
      * @param value The value to store
71 71
      */
@@ -118,7 +118,7 @@ export default class SettingsScreen extends React.Component<Props, State> {
118 118
     }
119 119
 
120 120
     /**
121
-     * Toggle night mode and save it to preferences
121
+     * Toggles night mode and saves it to preferences
122 122
      */
123 123
     onToggleNightMode() {
124 124
         ThemeManager.getInstance().setNightMode(!this.state.nightMode);
@@ -138,7 +138,7 @@ export default class SettingsScreen extends React.Component<Props, State> {
138 138
     }
139 139
 
140 140
     /**
141
-     * Get a list item using a checkbox control
141
+     * Gets a list item using a checkbox control
142 142
      *
143 143
      * @param onPressCallback The callback when the checkbox state changes
144 144
      * @param icon The icon name to display on the list item
@@ -178,15 +178,15 @@ export default class SettingsScreen extends React.Component<Props, State> {
178 178
                         ) : null}
179 179
                         {
180 180
                             Appearance.getColorScheme() === 'no-preference' || !this.state.nightModeFollowSystem ?
181
-                            this.getToggleItem(
182
-                                this.onToggleNightMode,
183
-                                'theme-light-dark',
184
-                                i18n.t('settingsScreen.nightMode'),
185
-                                this.state.nightMode ?
186
-                                    i18n.t('settingsScreen.nightModeSubOn') :
187
-                                    i18n.t('settingsScreen.nightModeSubOff'),
188
-                                this.state.nightMode
189
-                            ) : null
181
+                                this.getToggleItem(
182
+                                    this.onToggleNightMode,
183
+                                    'theme-light-dark',
184
+                                    i18n.t('settingsScreen.nightMode'),
185
+                                    this.state.nightMode ?
186
+                                        i18n.t('settingsScreen.nightModeSubOn') :
187
+                                        i18n.t('settingsScreen.nightModeSubOff'),
188
+                                    this.state.nightMode
189
+                                ) : null
190 190
                         }
191 191
                         <List.Accordion
192 192
                             title={i18n.t('settingsScreen.startScreen')}
@@ -209,7 +209,6 @@ export default class SettingsScreen extends React.Component<Props, State> {
209 209
                         </List.Accordion>
210 210
                     </List.Section>
211 211
                 </Card>
212
-
213 212
             </ScrollView>
214 213
         );
215 214
     }

+ 5
- 3
screens/Websites/AvailableRoomScreen.js View File

@@ -14,14 +14,16 @@ const PC_URL = 'http://planex.insa-toulouse.fr/sallesInfo.php';
14 14
 const CUSTOM_CSS_GENERAL = 'https://etud.insa-toulouse.fr/~amicale_app/custom_css/rooms/customMobile.css';
15 15
 
16 16
 /**
17
- * Class defining the app's planex screen.
18
- * This screen uses a webview to render the planex page
17
+ * Class defining the app's available rooms screen.
18
+ * This screen uses a webview to render the page
19 19
  */
20 20
 export default class AvailableRoomScreen extends React.Component<Props> {
21 21
 
22 22
     customInjectedJS: string;
23
-    customBibInjectedJS: string;
24 23
 
24
+    /**
25
+     * Defines custom injected JavaScript to improve the page display on mobile
26
+     */
25 27
     constructor() {
26 28
         super();
27 29
         this.customInjectedJS =

+ 5
- 2
screens/Websites/BibScreen.js View File

@@ -13,14 +13,17 @@ const CUSTOM_CSS_GENERAL = 'https://etud.insa-toulouse.fr/~amicale_app/custom_cs
13 13
 const CUSTOM_CSS_Bib = 'https://etud.insa-toulouse.fr/~amicale_app/custom_css/rooms/customBibMobile.css';
14 14
 
15 15
 /**
16
- * Class defining the app's planex screen.
17
- * This screen uses a webview to render the planex page
16
+ * Class defining the app's Bib screen.
17
+ * This screen uses a webview to render the page
18 18
  */
19 19
 export default class AvailableRoomScreen extends React.Component<Props> {
20 20
 
21 21
     customInjectedJS: string;
22 22
     customBibInjectedJS: string;
23 23
 
24
+    /**
25
+     * Defines custom injected JavaScript to improve the page display on mobile
26
+     */
24 27
     constructor() {
25 28
         super();
26 29
         this.customInjectedJS =

+ 20
- 9
screens/Websites/PlanexScreen.js View File

@@ -80,15 +80,23 @@ const OBSERVE_MUTATIONS_INJECTED =
80 80
     '    removeAlpha($(this));\n' +
81 81
     '});';
82 82
 /**
83
- * Class defining the app's planex screen.
84
- * This screen uses a webview to render the planex page
83
+ * Class defining the app's Planex screen.
84
+ * This screen uses a webview to render the page
85 85
  */
86 86
 export default class PlanexScreen extends React.Component<Props, State> {
87 87
 
88 88
     customInjectedJS: string;
89 89
     onHideBanner: Function;
90 90
     onGoToSettings: Function;
91
+    state = {
92
+        bannerVisible:
93
+            AsyncStorageManager.getInstance().preferences.planexShowBanner.current === '1' &&
94
+            AsyncStorageManager.getInstance().preferences.defaultStartScreen.current !== 'Planex',
95
+    };
91 96
 
97
+    /**
98
+     * Defines custom injected JavaScript to improve the page display on mobile
99
+     */
92 100
     constructor() {
93 101
         super();
94 102
         this.customInjectedJS =
@@ -102,17 +110,15 @@ export default class PlanexScreen extends React.Component<Props, State> {
102 110
 
103 111
         this.customInjectedJS +=
104 112
             'removeAlpha();' +
105
-            '});true;'; // Prevent crash on ios
113
+            '});true;'; // Prevents crash on ios
106 114
         this.onHideBanner = this.onHideBanner.bind(this);
107 115
         this.onGoToSettings = this.onGoToSettings.bind(this);
108 116
     }
109 117
 
110
-    state = {
111
-        bannerVisible:
112
-            AsyncStorageManager.getInstance().preferences.planexShowBanner.current === '1' &&
113
-            AsyncStorageManager.getInstance().preferences.defaultStartScreen.current !== 'Planex',
114
-    };
115
-
118
+    /**
119
+     * Callback used when closing the banner.
120
+     * This hides the banner and saves to preferences to prevent it from reopening
121
+     */
116 122
     onHideBanner() {
117 123
         this.setState({bannerVisible: false});
118 124
         AsyncStorageManager.getInstance().savePref(
@@ -121,6 +127,11 @@ export default class PlanexScreen extends React.Component<Props, State> {
121 127
         );
122 128
     }
123 129
 
130
+    /**
131
+     * Callback used when the used click on the navigate to settings button.
132
+     * This will hide the banner and open the SettingsScreen
133
+     *
134
+     */
124 135
     onGoToSettings() {
125 136
         this.onHideBanner();
126 137
         this.props.navigation.navigate('SettingsScreen');

+ 0
- 5
utils/AsyncStorageManager.js View File

@@ -39,11 +39,6 @@ export default class AsyncStorageManager {
39 39
             default: '5',
40 40
             current: '',
41 41
         },
42
-        proxiwashWatchedMachines: {
43
-            key: 'proxiwashWatchedMachines',
44
-            default: '[]',
45
-            current: '',
46
-        },
47 42
         nightModeFollowSystem: {
48 43
             key: 'nightModeFollowSystem',
49 44
             default: '1',

Loading…
Cancel
Save