Browse Source

Improved doc and typing

Arnaud Vergnet 3 years ago
parent
commit
869a8e5ec0

+ 40
- 8
src/components/Screens/WebViewScreen.js View File

41
         customPaddingFunction: null,
41
         customPaddingFunction: null,
42
     };
42
     };
43
 
43
 
44
-    webviewRef: Object;
44
+    webviewRef: { current: null | WebView };
45
 
45
 
46
     canGoBack: boolean;
46
     canGoBack: boolean;
47
 
47
 
52
     }
52
     }
53
 
53
 
54
     /**
54
     /**
55
-     * Creates refresh button after mounting
55
+     * Creates header buttons and listens to events after mounting
56
      */
56
      */
57
     componentDidMount() {
57
     componentDidMount() {
58
         this.props.navigation.setOptions({
58
         this.props.navigation.setOptions({
78
         );
78
         );
79
     }
79
     }
80
 
80
 
81
+    /**
82
+     * Goes back on the webview or on the navigation stack if we cannot go back anymore
83
+     *
84
+     * @returns {boolean}
85
+     */
81
     onBackButtonPressAndroid = () => {
86
     onBackButtonPressAndroid = () => {
82
         if (this.canGoBack) {
87
         if (this.canGoBack) {
83
             this.onGoBackClicked();
88
             this.onGoBackClicked();
87
     };
92
     };
88
 
93
 
89
     /**
94
     /**
90
-     * Gets a header refresh button
95
+     * Gets header refresh and open in browser buttons
91
      *
96
      *
92
      * @return {*}
97
      * @return {*}
93
      */
98
      */
106
         );
111
         );
107
     };
112
     };
108
 
113
 
114
+    /**
115
+     * Creates advanced header control buttons.
116
+     * These buttons allows the user to refresh, go back, go forward and open in the browser.
117
+     *
118
+     * @returns {*}
119
+     */
109
     getAdvancedButtons = () => {
120
     getAdvancedButtons = () => {
110
         return (
121
         return (
111
             <MaterialHeaderButtons>
122
             <MaterialHeaderButtons>
141
     /**
152
     /**
142
      * Callback to use when refresh button is clicked. Reloads the webview.
153
      * Callback to use when refresh button is clicked. Reloads the webview.
143
      */
154
      */
144
-    onRefreshClicked = () => this.webviewRef.current.reload();
145
-    onGoBackClicked = () => this.webviewRef.current.goBack();
146
-    onGoForwardClicked = () => this.webviewRef.current.goForward();
147
-
155
+    onRefreshClicked = () => {
156
+        if (this.webviewRef.current != null)
157
+            this.webviewRef.current.reload();
158
+    }
159
+    onGoBackClicked = () => {
160
+        if (this.webviewRef.current != null)
161
+            this.webviewRef.current.goBack();
162
+    }
163
+    onGoForwardClicked = () => {
164
+        if (this.webviewRef.current != null)
165
+            this.webviewRef.current.goForward();
166
+    }
148
     onOpenClicked = () => Linking.openURL(this.props.url);
167
     onOpenClicked = () => Linking.openURL(this.props.url);
149
 
168
 
169
+    /**
170
+     * Injects the given javascript string into the web page
171
+     *
172
+     * @param script The script to inject
173
+     */
150
     injectJavaScript = (script: string) => {
174
     injectJavaScript = (script: string) => {
151
-        this.webviewRef.current.injectJavaScript(script);
175
+        if (this.webviewRef.current != null)
176
+            this.webviewRef.current.injectJavaScript(script);
152
     }
177
     }
153
 
178
 
154
     /**
179
     /**
158
      */
183
      */
159
     getRenderLoading = () => <BasicLoadingScreen isAbsolute={true}/>;
184
     getRenderLoading = () => <BasicLoadingScreen isAbsolute={true}/>;
160
 
185
 
186
+    /**
187
+     * Gets the javascript needed to generate a padding on top of the page
188
+     * This adds padding to the body and runs the custom padding function given in props
189
+     *
190
+     * @param padding The padding to add in pixels
191
+     * @returns {string}
192
+     */
161
     getJavascriptPadding(padding: number) {
193
     getJavascriptPadding(padding: number) {
162
         const customPadding = this.props.customPaddingFunction != null ? this.props.customPaddingFunction(padding) : "";
194
         const customPadding = this.props.customPaddingFunction != null ? this.props.customPaddingFunction(padding) : "";
163
         return (
195
         return (

+ 7
- 1
src/screens/Other/FeedbackScreen.js View File

26
 
26
 
27
 class FeedbackScreen extends React.Component<Props> {
27
 class FeedbackScreen extends React.Component<Props> {
28
 
28
 
29
+    /**
30
+     * Gets link buttons
31
+     *
32
+     * @param isBug True if buttons should redirect to bug report methods
33
+     * @returns {*}
34
+     */
29
     getButtons(isBug: boolean) {
35
     getButtons(isBug: boolean) {
30
         return (
36
         return (
31
             <Card.Actions style={{
37
             <Card.Actions style={{
106
     }
112
     }
107
 }
113
 }
108
 
114
 
109
-export default withTheme(FeedbackScreen);
115
+export default withTheme(FeedbackScreen);

+ 5
- 2
src/screens/Other/SettingsScreen.js View File

31
 
31
 
32
     savedNotificationReminder: number;
32
     savedNotificationReminder: number;
33
 
33
 
34
+    /**
35
+     * Loads user preferences into state
36
+     */
34
     constructor() {
37
     constructor() {
35
         super();
38
         super();
36
         let notifReminder = AsyncStorageManager.getInstance().preferences.proxiwashNotifications.current;
39
         let notifReminder = AsyncStorageManager.getInstance().preferences.proxiwashNotifications.current;
49
     }
52
     }
50
 
53
 
51
     /**
54
     /**
52
-     * Unlocks debug mode
55
+     * Unlocks debug mode and saves its state to user preferences
53
      */
56
      */
54
     unlockDebugMode = () => {
57
     unlockDebugMode = () => {
55
         this.setState({isDebugUnlocked: true});
58
         this.setState({isDebugUnlocked: true});
227
                                 left={props => <List.Icon {...props} icon="bug-check"/>}
230
                                 left={props => <List.Icon {...props} icon="bug-check"/>}
228
                                 onPress={() => this.props.navigation.navigate("debug")}
231
                                 onPress={() => this.props.navigation.navigate("debug")}
229
                             />
232
                             />
230
-                        :null}
233
+                            : null}
231
                         <List.Item
234
                         <List.Item
232
                             title={i18n.t('screens.about')}
235
                             title={i18n.t('screens.about')}
233
                             description={i18n.t('aboutScreen.buttonDesc')}
236
                             description={i18n.t('aboutScreen.buttonDesc')}

+ 48
- 1
src/screens/Planex/GroupSelectionScreen.js View File

45
 const REPLACE_REGEX = /_/g;
45
 const REPLACE_REGEX = /_/g;
46
 
46
 
47
 /**
47
 /**
48
- * Class defining proximo's article list of a certain category.
48
+ * Class defining planex group selection screen.
49
  */
49
  */
50
 class GroupSelectionScreen extends React.Component<Props, State> {
50
 class GroupSelectionScreen extends React.Component<Props, State> {
51
 
51
 
106
         });
106
         });
107
     };
107
     };
108
 
108
 
109
+    /**
110
+     * Callback used when the user clicks on the favorite button
111
+     *
112
+     * @param item The item to add/remove from favorites
113
+     */
109
     onListFavoritePress = (item: group) => {
114
     onListFavoritePress = (item: group) => {
110
         this.updateGroupFavorites(item);
115
         this.updateGroupFavorites(item);
111
     };
116
     };
112
 
117
 
118
+    /**
119
+     * Checks if the given group is in the favorites list
120
+     *
121
+     * @param group The group to check
122
+     * @returns {boolean}
123
+     */
113
     isGroupInFavorites(group: group) {
124
     isGroupInFavorites(group: group) {
114
         let isFav = false;
125
         let isFav = false;
115
         for (let i = 0; i < this.state.favoriteGroups.length; i++) {
126
         for (let i = 0; i < this.state.favoriteGroups.length; i++) {
121
         return isFav;
132
         return isFav;
122
     }
133
     }
123
 
134
 
135
+    /**
136
+     * Removes the given group from the given array
137
+     *
138
+     * @param favorites The array containing favorites groups
139
+     * @param group The group to remove from the array
140
+     */
124
     removeGroupFromFavorites(favorites: Array<group>, group: group) {
141
     removeGroupFromFavorites(favorites: Array<group>, group: group) {
125
         for (let i = 0; i < favorites.length; i++) {
142
         for (let i = 0; i < favorites.length; i++) {
126
             if (group.id === favorites[i].id) {
143
             if (group.id === favorites[i].id) {
130
         }
147
         }
131
     }
148
     }
132
 
149
 
150
+    /**
151
+     * Adds the given group to the given array
152
+     *
153
+     * @param favorites The array containing favorites groups
154
+     * @param group The group to add to the array
155
+     */
133
     addGroupToFavorites(favorites: Array<group>, group: group) {
156
     addGroupToFavorites(favorites: Array<group>, group: group) {
134
         group.isFav = true;
157
         group.isFav = true;
135
         favorites.push(group);
158
         favorites.push(group);
136
         favorites.sort(sortName);
159
         favorites.sort(sortName);
137
     }
160
     }
138
 
161
 
162
+    /**
163
+     * Adds or removes the given group to the favorites list, depending on whether it is already in it or not.
164
+     * Favorites are then saved in user preferences
165
+     *
166
+     * @param group The group to add/remove to favorites
167
+     */
139
     updateGroupFavorites(group: group) {
168
     updateGroupFavorites(group: group) {
140
         let newFavorites = [...this.state.favoriteGroups]
169
         let newFavorites = [...this.state.favoriteGroups]
141
         if (this.isGroupInFavorites(group))
170
         if (this.isGroupInFavorites(group))
148
             JSON.stringify(newFavorites));
177
             JSON.stringify(newFavorites));
149
     }
178
     }
150
 
179
 
180
+    /**
181
+     * Checks whether to display the given group category, depending on user search query
182
+     *
183
+     * @param item The group category
184
+     * @returns {boolean}
185
+     */
151
     shouldDisplayAccordion(item: groupCategory) {
186
     shouldDisplayAccordion(item: groupCategory) {
152
         let shouldDisplay = false;
187
         let shouldDisplay = false;
153
         for (let i = 0; i < item.content.length; i++) {
188
         for (let i = 0; i < item.content.length; i++) {
181
             return null;
216
             return null;
182
     };
217
     };
183
 
218
 
219
+    /**
220
+     * Generates the dataset to be used in the FlatList.
221
+     * This improves formatting of group names, sorts alphabetically the categories, and adds favorites at the top.
222
+     *
223
+     * @param fetchedData The raw data fetched from the server
224
+     * @returns {[]}
225
+     */
184
     generateData(fetchedData: { [key: string]: groupCategory }) {
226
     generateData(fetchedData: { [key: string]: groupCategory }) {
185
         let data = [];
227
         let data = [];
186
         for (let key in fetchedData) {
228
         for (let key in fetchedData) {
192
         return data;
234
         return data;
193
     }
235
     }
194
 
236
 
237
+    /**
238
+     * Replaces underscore by spaces and sets the favorite state of every group in the given category
239
+     *
240
+     * @param item The category containing groups to format
241
+     */
195
     formatGroups(item: groupCategory) {
242
     formatGroups(item: groupCategory) {
196
         for (let i = 0; i < item.content.length; i++) {
243
         for (let i = 0; i < item.content.length; i++) {
197
             item.content[i].name = item.content[i].name.replace(REPLACE_REGEX, " ")
244
             item.content[i].name = item.content[i].name.replace(REPLACE_REGEX, " ")

+ 108
- 57
src/screens/Planex/PlanexScreen.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
 import * as React from 'react';
3
 import * as React from 'react';
4
+import type {CustomTheme} from "../../managers/ThemeManager";
4
 import ThemeManager from "../../managers/ThemeManager";
5
 import ThemeManager from "../../managers/ThemeManager";
5
 import WebViewScreen from "../../components/Screens/WebViewScreen";
6
 import WebViewScreen from "../../components/Screens/WebViewScreen";
6
 import {Avatar, Banner, withTheme} from "react-native-paper";
7
 import {Avatar, Banner, withTheme} from "react-native-paper";
14
 import AnimatedBottomBar from "../../components/Animations/AnimatedBottomBar";
15
 import AnimatedBottomBar from "../../components/Animations/AnimatedBottomBar";
15
 import {CommonActions} from "@react-navigation/native";
16
 import {CommonActions} from "@react-navigation/native";
16
 import ErrorView from "../../components/Screens/ErrorView";
17
 import ErrorView from "../../components/Screens/ErrorView";
18
+import {StackNavigationProp} from "@react-navigation/stack";
19
+import {Collapsible} from "react-navigation-collapsible";
20
+import type {group} from "./GroupSelectionScreen";
17
 
21
 
18
 type Props = {
22
 type Props = {
19
-    navigation: Object,
20
-    route: Object,
21
-    theme: Object,
22
-    collapsibleStack: Object,
23
+    navigation: StackNavigationProp,
24
+    route: { params: { group: group } },
25
+    theme: CustomTheme,
26
+    collapsibleStack: Collapsible,
23
 }
27
 }
24
 
28
 
25
 type State = {
29
 type State = {
27
     dialogVisible: boolean,
31
     dialogVisible: boolean,
28
     dialogTitle: string,
32
     dialogTitle: string,
29
     dialogMessage: string,
33
     dialogMessage: string,
30
-    currentGroup: Object,
34
+    currentGroup: group,
31
 }
35
 }
32
 
36
 
33
 
37
 
62
 //     removeAlpha($(this));
66
 //     removeAlpha($(this));
63
 // });
67
 // });
64
 
68
 
65
-// Watch for changes in the calendar and call the remove alpha function
69
+// Watch for changes in the calendar and call the remove alpha function to prevent invisible events
66
 const OBSERVE_MUTATIONS_INJECTED =
70
 const OBSERVE_MUTATIONS_INJECTED =
67
     'function removeAlpha(node) {\n' +
71
     'function removeAlpha(node) {\n' +
68
     '    let bg = node.css("background-color");\n' +
72
     '    let bg = node.css("background-color");\n' +
91
     '    removeAlpha($(this));\n' +
95
     '    removeAlpha($(this));\n' +
92
     '});';
96
     '});';
93
 
97
 
98
+// Overrides default settings to send a message to the webview when clicking on an event
94
 const FULL_CALENDAR_SETTINGS = `
99
 const FULL_CALENDAR_SETTINGS = `
95
 var calendar = $('#calendar').fullCalendar('getCalendar');
100
 var calendar = $('#calendar').fullCalendar('getCalendar');
96
 calendar.option({
101
 calendar.option({
105
   }
110
   }
106
 });`;
111
 });`;
107
 
112
 
108
-const EXEC_COMMAND = `
109
-function execCommand(event) {
110
-    alert(JSON.stringify(event));
111
-    var data = JSON.parse(event.data);
112
-    if (data.action === "setGroup")
113
-        displayAde(data.data);
114
-    else
115
-        $('#calendar').fullCalendar(data.action, data.data);
116
-};`
117
-
118
 const CUSTOM_CSS = "body>.container{padding-top:20px; padding-bottom: 50px}header,#entite,#groupe_visibility,#calendar .fc-left,#calendar .fc-right{display:none}.fc-toolbar .fc-center{width:100%}.fc-toolbar .fc-center>*{float:none;width:100%;margin:0}#entite{margin-bottom:5px!important}#entite,#groupe{width:calc(100% - 20px);margin:0 10px}#groupe_visibility{width:100%}#calendar .fc-agendaWeek-view .fc-content-skeleton .fc-title{font-size:.6rem}#calendar .fc-agendaWeek-view .fc-content-skeleton .fc-time{font-size:.5rem}#calendar .fc-month-view .fc-content-skeleton .fc-title{font-size:.6rem}#calendar .fc-month-view .fc-content-skeleton .fc-time{font-size:.7rem}.fc-axis{font-size:.8rem;width:15px!important}.fc-day-header{font-size:.8rem}.fc-unthemed td.fc-today{background:#be1522; opacity:0.4}";
113
 const CUSTOM_CSS = "body>.container{padding-top:20px; padding-bottom: 50px}header,#entite,#groupe_visibility,#calendar .fc-left,#calendar .fc-right{display:none}.fc-toolbar .fc-center{width:100%}.fc-toolbar .fc-center>*{float:none;width:100%;margin:0}#entite{margin-bottom:5px!important}#entite,#groupe{width:calc(100% - 20px);margin:0 10px}#groupe_visibility{width:100%}#calendar .fc-agendaWeek-view .fc-content-skeleton .fc-title{font-size:.6rem}#calendar .fc-agendaWeek-view .fc-content-skeleton .fc-time{font-size:.5rem}#calendar .fc-month-view .fc-content-skeleton .fc-title{font-size:.6rem}#calendar .fc-month-view .fc-content-skeleton .fc-time{font-size:.7rem}.fc-axis{font-size:.8rem;width:15px!important}.fc-day-header{font-size:.8rem}.fc-unthemed td.fc-today{background:#be1522; opacity:0.4}";
119
 const CUSTOM_CSS_DARK = "body{background-color:#121212}.fc-unthemed .fc-content,.fc-unthemed .fc-divider,.fc-unthemed .fc-list-heading td,.fc-unthemed .fc-list-view,.fc-unthemed .fc-popover,.fc-unthemed .fc-row,.fc-unthemed tbody,.fc-unthemed td,.fc-unthemed th,.fc-unthemed thead{border-color:#222}.fc-toolbar .fc-center>*,h2,table{color:#fff}.fc-event-container{color:#121212}.fc-event-container .fc-bg{opacity:0.2;background-color:#000}.fc-unthemed td.fc-today{background:#be1522; opacity:0.4}";
114
 const CUSTOM_CSS_DARK = "body{background-color:#121212}.fc-unthemed .fc-content,.fc-unthemed .fc-divider,.fc-unthemed .fc-list-heading td,.fc-unthemed .fc-list-view,.fc-unthemed .fc-popover,.fc-unthemed .fc-row,.fc-unthemed tbody,.fc-unthemed td,.fc-unthemed th,.fc-unthemed thead{border-color:#222}.fc-toolbar .fc-center>*,h2,table{color:#fff}.fc-event-container{color:#121212}.fc-event-container .fc-bg{opacity:0.2;background-color:#000}.fc-unthemed td.fc-today{background:#be1522; opacity:0.4}";
120
 
115
 
129
  */
124
  */
130
 class PlanexScreen extends React.Component<Props, State> {
125
 class PlanexScreen extends React.Component<Props, State> {
131
 
126
 
132
-    webScreenRef: Object;
133
-    barRef: Object;
127
+    webScreenRef: { current: null | WebViewScreen };
128
+    barRef: { current: null | AnimatedBottomBar };
134
 
129
 
135
     customInjectedJS: string;
130
     customInjectedJS: string;
136
 
131
 
144
 
139
 
145
         let currentGroup = AsyncStorageManager.getInstance().preferences.planexCurrentGroup.current;
140
         let currentGroup = AsyncStorageManager.getInstance().preferences.planexCurrentGroup.current;
146
         if (currentGroup === '')
141
         if (currentGroup === '')
147
-            currentGroup = {name: "SELECT GROUP", id: -1};
142
+            currentGroup = {name: "SELECT GROUP", id: -1, isFav: false};
148
         else {
143
         else {
149
             currentGroup = JSON.parse(currentGroup);
144
             currentGroup = JSON.parse(currentGroup);
150
             props.navigation.setOptions({title: currentGroup.name})
145
             props.navigation.setOptions({title: currentGroup.name})
159
         this.generateInjectedJS(currentGroup.id);
154
         this.generateInjectedJS(currentGroup.id);
160
     }
155
     }
161
 
156
 
157
+    /**
158
+     * Register for events and show the banner after 2 seconds
159
+     */
162
     componentDidMount() {
160
     componentDidMount() {
163
         this.props.navigation.addListener('focus', this.onScreenFocus);
161
         this.props.navigation.addListener('focus', this.onScreenFocus);
164
         setTimeout(this.onBannerTimeout, 2000);
162
         setTimeout(this.onBannerTimeout, 2000);
172
         })
170
         })
173
     }
171
     }
174
 
172
 
173
+    /**
174
+     * Callback used when closing the banner.
175
+     * This hides the banner and saves to preferences to prevent it from reopening
176
+     */
177
+    onHideBanner = () => {
178
+        this.setState({bannerVisible: false});
179
+        AsyncStorageManager.getInstance().savePref(
180
+            AsyncStorageManager.getInstance().preferences.planexShowBanner.key,
181
+            '0'
182
+        );
183
+    };
184
+
185
+
186
+    /**
187
+     * Callback used when the user clicks on the navigate to settings button.
188
+     * This will hide the banner and open the SettingsScreen
189
+     */
190
+    onGoToSettings = () => {
191
+        this.onHideBanner();
192
+        this.props.navigation.navigate('settings');
193
+    };
194
+
175
     onScreenFocus = () => {
195
     onScreenFocus = () => {
176
         this.handleNavigationParams();
196
         this.handleNavigationParams();
177
     };
197
     };
178
 
198
 
199
+    /**
200
+     * If navigations parameters contain a group, set it as selected
201
+     */
179
     handleNavigationParams = () => {
202
     handleNavigationParams = () => {
180
-        if (this.props.route.params !== undefined) {
203
+        if (this.props.route.params != null) {
181
             if (this.props.route.params.group !== undefined && this.props.route.params.group !== null) {
204
             if (this.props.route.params.group !== undefined && this.props.route.params.group !== null) {
182
                 // reset params to prevent infinite loop
205
                 // reset params to prevent infinite loop
183
                 this.selectNewGroup(this.props.route.params.group);
206
                 this.selectNewGroup(this.props.route.params.group);
186
         }
209
         }
187
     };
210
     };
188
 
211
 
189
-    selectNewGroup(group: Object) {
212
+    /**
213
+     * Sends the webpage a message with the new group to select and save it to preferences
214
+     *
215
+     * @param group The group object selected
216
+     */
217
+    selectNewGroup(group: group) {
190
         this.sendMessage('setGroup', group.id);
218
         this.sendMessage('setGroup', group.id);
191
         this.setState({currentGroup: group});
219
         this.setState({currentGroup: group});
192
         AsyncStorageManager.getInstance().savePref(
220
         AsyncStorageManager.getInstance().savePref(
193
             AsyncStorageManager.getInstance().preferences.planexCurrentGroup.key,
221
             AsyncStorageManager.getInstance().preferences.planexCurrentGroup.key,
194
-            JSON.stringify(group));
195
-        this.props.navigation.setOptions({title: group.name})
222
+            JSON.stringify(group)
223
+        );
224
+        this.props.navigation.setOptions({title: group.name});
196
         this.generateInjectedJS(group.id);
225
         this.generateInjectedJS(group.id);
197
     }
226
     }
198
 
227
 
228
+    /**
229
+     * Generates custom JavaScript to be injected into the webpage
230
+     *
231
+     * @param groupID The current group selected
232
+     */
199
     generateInjectedJS(groupID: number) {
233
     generateInjectedJS(groupID: number) {
200
         this.customInjectedJS = "$(document).ready(function() {"
234
         this.customInjectedJS = "$(document).ready(function() {"
201
             + OBSERVE_MUTATIONS_INJECTED
235
             + OBSERVE_MUTATIONS_INJECTED
207
         if (ThemeManager.getNightMode())
241
         if (ThemeManager.getNightMode())
208
             this.customInjectedJS += "$('head').append('<style>" + CUSTOM_CSS_DARK + "</style>');";
242
             this.customInjectedJS += "$('head').append('<style>" + CUSTOM_CSS_DARK + "</style>');";
209
 
243
 
210
-        this.customInjectedJS +=
211
-            'removeAlpha();'
212
-            + '});'
213
-            + EXEC_COMMAND
214
-            + 'true;'; // Prevents crash on ios
244
+        this.customInjectedJS += 'removeAlpha();});true;'; // Prevents crash on ios
215
     }
245
     }
216
 
246
 
247
+    /**
248
+     * Only update the screen if the dark theme changed
249
+     *
250
+     * @param nextProps
251
+     * @returns {boolean}
252
+     */
217
     shouldComponentUpdate(nextProps: Props): boolean {
253
     shouldComponentUpdate(nextProps: Props): boolean {
218
         if (nextProps.theme.dark !== this.props.theme.dark)
254
         if (nextProps.theme.dark !== this.props.theme.dark)
219
             this.generateInjectedJS(this.state.currentGroup.id);
255
             this.generateInjectedJS(this.state.currentGroup.id);
220
         return true;
256
         return true;
221
     }
257
     }
222
 
258
 
223
-    /**
224
-     * Callback used when closing the banner.
225
-     * This hides the banner and saves to preferences to prevent it from reopening
226
-     */
227
-    onHideBanner = () => {
228
-        this.setState({bannerVisible: false});
229
-        AsyncStorageManager.getInstance().savePref(
230
-            AsyncStorageManager.getInstance().preferences.planexShowBanner.key,
231
-            '0'
232
-        );
233
-    };
234
 
259
 
235
     /**
260
     /**
236
-     * Callback used when the used click on the navigate to settings button.
237
-     * This will hide the banner and open the SettingsScreen
261
+     * Sends a FullCalendar action to the web page inside the webview.
238
      *
262
      *
263
+     * @param action The action to perform, as described in the FullCalendar doc https://fullcalendar.io/docs/v3.
264
+     * Or "setGroup" with the group id as data to set the selected group
265
+     * @param data Data to pass to the action
239
      */
266
      */
240
-    onGoToSettings = () => {
241
-        this.onHideBanner();
242
-        this.props.navigation.navigate('settings');
243
-    };
244
-
245
     sendMessage = (action: string, data: any) => {
267
     sendMessage = (action: string, data: any) => {
246
         let command;
268
         let command;
247
         if (action === "setGroup")
269
         if (action === "setGroup")
248
             command = "displayAde(" + data + ")";
270
             command = "displayAde(" + data + ")";
249
         else
271
         else
250
             command = "$('#calendar').fullCalendar('" + action + "', '" + data + "')";
272
             command = "$('#calendar').fullCalendar('" + action + "', '" + data + "')";
251
-        this.webScreenRef.current.injectJavaScript(command + ';true;');
252
-    }
273
+        if (this.webScreenRef.current != null)
274
+            this.webScreenRef.current.injectJavaScript(command + ';true;'); // Injected javascript must end with true
275
+    };
276
+
277
+    /**
278
+     * Shows a dialog when the user clicks on an event.
279
+     *
280
+     * @param event
281
+     */
282
+    onMessage = (event: { nativeEvent: { data: string } }) => {
283
+        const data: { start: string, end: string, title: string, color: string } = JSON.parse(event.nativeEvent.data);
284
+        const startDate = dateToString(new Date(data.start), true);
285
+        const endDate = dateToString(new Date(data.end), true);
286
+        const startString = getTimeOnlyString(startDate);
287
+        const endString = getTimeOnlyString(endDate);
253
 
288
 
254
-    onMessage = (event: Object) => {
255
-        let data = JSON.parse(event.nativeEvent.data);
256
-        let startDate = dateToString(new Date(data.start), true);
257
-        let endDate = dateToString(new Date(data.end), true);
258
         let msg = DateManager.getInstance().getTranslatedDate(startDate) + "\n";
289
         let msg = DateManager.getInstance().getTranslatedDate(startDate) + "\n";
259
-        msg += getTimeOnlyString(startDate) + ' - ' + getTimeOnlyString(endDate);
290
+        if (startString != null && endString != null)
291
+            msg += startString + ' - ' + endDate;
260
         this.showDialog(data.title, msg)
292
         this.showDialog(data.title, msg)
261
     };
293
     };
262
 
294
 
295
+    /**
296
+     * Shows a simple dialog to the user.
297
+     *
298
+     * @param title The dialog's title
299
+     * @param message The message to show
300
+     */
263
     showDialog = (title: string, message: string) => {
301
     showDialog = (title: string, message: string) => {
264
         this.setState({
302
         this.setState({
265
             dialogVisible: true,
303
             dialogVisible: true,
268
         });
306
         });
269
     };
307
     };
270
 
308
 
309
+    /**
310
+     * Hides the dialog
311
+     */
271
     hideDialog = () => {
312
     hideDialog = () => {
272
         this.setState({
313
         this.setState({
273
             dialogVisible: false,
314
             dialogVisible: false,
274
         });
315
         });
275
     };
316
     };
276
 
317
 
277
-    onScroll = (event: Object) => {
278
-        this.barRef.current.onScroll(event);
318
+    /**
319
+     * Binds the onScroll event to the control bar for automatic hiding based on scroll direction and speed
320
+     *
321
+     * @param event
322
+     */
323
+    onScroll = (event: SyntheticEvent<EventTarget>) => {
324
+        if (this.barRef.current != null)
325
+            this.barRef.current.onScroll(event);
279
     };
326
     };
280
 
327
 
328
+    /**
329
+     * Gets the Webview, with an error view on top if no group is selected.
330
+     *
331
+     * @returns {*}
332
+     */
281
     getWebView() {
333
     getWebView() {
282
         const showWebview = this.state.currentGroup.id !== -1;
334
         const showWebview = this.state.currentGroup.id !== -1;
283
 
335
 
291
                         showRetryButton={false}
343
                         showRetryButton={false}
292
                     />
344
                     />
293
                     : null}
345
                     : null}
294
-
295
                 <WebViewScreen
346
                 <WebViewScreen
296
                     ref={this.webScreenRef}
347
                     ref={this.webScreenRef}
297
                     navigation={this.props.navigation}
348
                     navigation={this.props.navigation}
317
                     height: '100%',
368
                     height: '100%',
318
                     width: '100%',
369
                     width: '100%',
319
                 }}>
370
                 }}>
320
-                    {this.props.theme.dark // Force component theme update
371
+                    {this.props.theme.dark // Force component theme update by recreating it on theme change
321
                         ? this.getWebView()
372
                         ? this.getWebView()
322
                         : <View style={{height: '100%'}}>{this.getWebView()}</View>}
373
                         : <View style={{height: '100%'}}>{this.getWebView()}</View>}
323
                 </View>
374
                 </View>

+ 37
- 8
src/screens/Planning/PlanningDisplayScreen.js View File

12
 import CustomHTML from "../../components/Overrides/CustomHTML";
12
 import CustomHTML from "../../components/Overrides/CustomHTML";
13
 import CustomTabBar from "../../components/Tabbar/CustomTabBar";
13
 import CustomTabBar from "../../components/Tabbar/CustomTabBar";
14
 import i18n from 'i18n-js';
14
 import i18n from 'i18n-js';
15
+import {StackNavigationProp} from "@react-navigation/stack";
16
+import type {CustomTheme} from "../../managers/ThemeManager";
15
 
17
 
16
 type Props = {
18
 type Props = {
17
-    navigation: Object,
18
-    route: Object
19
+    navigation: StackNavigationProp,
20
+    route: { params: { data: Object, id: number, eventId: number } },
21
+    theme: CustomTheme
19
 };
22
 };
20
 
23
 
21
 type State = {
24
 type State = {
34
     eventId: number;
37
     eventId: number;
35
     errorCode: number;
38
     errorCode: number;
36
 
39
 
37
-    colors: Object;
38
-
40
+    /**
41
+     * Generates data depending on whether the screen was opened from the planning or from a link
42
+     *
43
+     * @param props
44
+     */
39
     constructor(props) {
45
     constructor(props) {
40
         super(props);
46
         super(props);
41
-        this.colors = props.theme.colors;
42
 
47
 
43
-        if (this.props.route.params.data !== undefined) {
48
+        if (this.props.route.params.data != null) {
44
             this.displayData = this.props.route.params.data;
49
             this.displayData = this.props.route.params.data;
45
             this.eventId = this.displayData.id;
50
             this.eventId = this.displayData.id;
46
             this.shouldFetchData = false;
51
             this.shouldFetchData = false;
61
         }
66
         }
62
     }
67
     }
63
 
68
 
69
+    /**
70
+     * Fetches data for the current event id from the API
71
+     */
64
     fetchData = () => {
72
     fetchData = () => {
65
         this.setState({loading: true});
73
         this.setState({loading: true});
66
         apiRequest(CLUB_INFO_PATH, 'POST', {id: this.eventId})
74
         apiRequest(CLUB_INFO_PATH, 'POST', {id: this.eventId})
68
             .catch(this.onFetchError);
76
             .catch(this.onFetchError);
69
     };
77
     };
70
 
78
 
79
+    /**
80
+     * Hides loading and saves fetched data
81
+     *
82
+     * @param data Received data
83
+     */
71
     onFetchSuccess = (data: Object) => {
84
     onFetchSuccess = (data: Object) => {
72
         this.displayData = data;
85
         this.displayData = data;
73
         this.setState({loading: false});
86
         this.setState({loading: false});
74
     };
87
     };
75
 
88
 
89
+    /**
90
+     * Hides loading and saves the error code
91
+     *
92
+     * @param error
93
+     */
76
     onFetchError = (error: number) => {
94
     onFetchError = (error: number) => {
77
         this.errorCode = error;
95
         this.errorCode = error;
78
         this.setState({loading: false});
96
         this.setState({loading: false});
79
     };
97
     };
80
 
98
 
99
+    /**
100
+     * Gets content to display
101
+     *
102
+     * @returns {*}
103
+     */
81
     getContent() {
104
     getContent() {
82
         let subtitle = getFormattedEventTime(
105
         let subtitle = getFormattedEventTime(
83
             this.displayData["date_begin"], this.displayData["date_end"]);
106
             this.displayData["date_begin"], this.displayData["date_end"]);
94
                     <View style={{marginLeft: 'auto', marginRight: 'auto'}}>
117
                     <View style={{marginLeft: 'auto', marginRight: 'auto'}}>
95
                         <ImageModal
118
                         <ImageModal
96
                             resizeMode="contain"
119
                             resizeMode="contain"
97
-                            imageBackgroundColor={this.colors.background}
120
+                            imageBackgroundColor={this.props.theme.colors.background}
98
                             style={{
121
                             style={{
99
                                 width: 300,
122
                                 width: 300,
100
                                 height: 300,
123
                                 height: 300,
114
         );
137
         );
115
     }
138
     }
116
 
139
 
140
+    /**
141
+     * Shows an error view and use a custom message if the event does not exist
142
+     *
143
+     * @returns {*}
144
+     */
117
     getErrorView() {
145
     getErrorView() {
118
         if (this.errorCode === ERROR_TYPE.BAD_INPUT)
146
         if (this.errorCode === ERROR_TYPE.BAD_INPUT)
119
-            return <ErrorView {...this.props} showRetryButton={false} message={i18n.t("planningScreen.invalidEvent")} icon={"calendar-remove"}/>;
147
+            return <ErrorView {...this.props} showRetryButton={false} message={i18n.t("planningScreen.invalidEvent")}
148
+                              icon={"calendar-remove"}/>;
120
         else
149
         else
121
             return <ErrorView {...this.props} errorCode={this.errorCode} onRefresh={this.fetchData}/>;
150
             return <ErrorView {...this.props} errorCode={this.errorCode} onRefresh={this.fetchData}/>;
122
     }
151
     }

+ 9
- 32
src/screens/Planning/PlanningScreen.js View File

14
 } from '../../utils/Planning';
14
 } from '../../utils/Planning';
15
 import {Avatar, Divider, List} from 'react-native-paper';
15
 import {Avatar, Divider, List} from 'react-native-paper';
16
 import CustomAgenda from "../../components/Overrides/CustomAgenda";
16
 import CustomAgenda from "../../components/Overrides/CustomAgenda";
17
+import {StackNavigationProp} from "@react-navigation/stack";
17
 
18
 
18
 LocaleConfig.locales['fr'] = {
19
 LocaleConfig.locales['fr'] = {
19
     monthNames: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'],
20
     monthNames: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'],
25
 
26
 
26
 
27
 
27
 type Props = {
28
 type Props = {
28
-    navigation: Object,
29
-    route: Object,
29
+    navigation: StackNavigationProp,
30
 }
30
 }
31
 
31
 
32
 type State = {
32
 type State = {
48
     lastRefresh: Date;
48
     lastRefresh: Date;
49
     minTimeBetweenRefresh = 60;
49
     minTimeBetweenRefresh = 60;
50
 
50
 
51
-    didFocusSubscription: Function;
52
-    willBlurSubscription: Function;
53
-
54
     state = {
51
     state = {
55
         refreshing: false,
52
         refreshing: false,
56
         agendaItems: {},
53
         agendaItems: {},
57
         calendarShowing: false,
54
         calendarShowing: false,
58
     };
55
     };
59
 
56
 
60
-    onRefresh: Function;
61
-    onCalendarToggled: Function;
62
-    getRenderItem: Function;
63
-    getRenderEmptyDate: Function;
64
-    onAgendaRef: Function;
65
-    onCalendarToggled: Function;
66
-    onBackButtonPressAndroid: Function;
67
     currentDate = getDateOnlyString(getCurrentDateString());
57
     currentDate = getDateOnlyString(getCurrentDateString());
68
 
58
 
69
     constructor(props: any) {
59
     constructor(props: any) {
71
         if (i18n.currentLocale().startsWith("fr")) {
61
         if (i18n.currentLocale().startsWith("fr")) {
72
             LocaleConfig.defaultLocale = 'fr';
62
             LocaleConfig.defaultLocale = 'fr';
73
         }
63
         }
74
-
75
-        // Create references for functions required in the render function
76
-        this.onRefresh = this.onRefresh.bind(this);
77
-        this.onCalendarToggled = this.onCalendarToggled.bind(this);
78
-        this.getRenderItem = this.getRenderItem.bind(this);
79
-        this.getRenderEmptyDate = this.getRenderEmptyDate.bind(this);
80
-        this.onAgendaRef = this.onAgendaRef.bind(this);
81
-        this.onCalendarToggled = this.onCalendarToggled.bind(this);
82
-        this.onBackButtonPressAndroid = this.onBackButtonPressAndroid.bind(this);
83
     }
64
     }
84
 
65
 
85
     /**
66
     /**
87
      */
68
      */
88
     componentDidMount() {
69
     componentDidMount() {
89
         this.onRefresh();
70
         this.onRefresh();
90
-        this.didFocusSubscription = this.props.navigation.addListener(
71
+        this.props.navigation.addListener(
91
             'focus',
72
             'focus',
92
             () =>
73
             () =>
93
                 BackHandler.addEventListener(
74
                 BackHandler.addEventListener(
95
                     this.onBackButtonPressAndroid
76
                     this.onBackButtonPressAndroid
96
                 )
77
                 )
97
         );
78
         );
98
-        this.willBlurSubscription = this.props.navigation.addListener(
79
+        this.props.navigation.addListener(
99
             'blur',
80
             'blur',
100
             () =>
81
             () =>
101
                 BackHandler.removeEventListener(
82
                 BackHandler.removeEventListener(
110
      *
91
      *
111
      * @return {boolean}
92
      * @return {boolean}
112
      */
93
      */
113
-    onBackButtonPressAndroid() {
94
+    onBackButtonPressAndroid = () => {
114
         if (this.state.calendarShowing) {
95
         if (this.state.calendarShowing) {
115
             this.agendaRef.chooseDay(this.agendaRef.state.selectedDay);
96
             this.agendaRef.chooseDay(this.agendaRef.state.selectedDay);
116
             return true;
97
             return true;
166
      *
147
      *
167
      * @param ref
148
      * @param ref
168
      */
149
      */
169
-    onAgendaRef(ref: Object) {
150
+    onAgendaRef = (ref: Object) => {
170
         this.agendaRef = ref;
151
         this.agendaRef = ref;
171
     }
152
     }
172
 
153
 
175
      *
156
      *
176
      * @param isCalendarOpened True is the calendar is already open, false otherwise
157
      * @param isCalendarOpened True is the calendar is already open, false otherwise
177
      */
158
      */
178
-    onCalendarToggled(isCalendarOpened: boolean) {
159
+    onCalendarToggled = (isCalendarOpened: boolean) => {
179
         this.setState({calendarShowing: isCalendarOpened});
160
         this.setState({calendarShowing: isCalendarOpened});
180
     }
161
     }
181
 
162
 
185
      * @param item The current event to render
166
      * @param item The current event to render
186
      * @return {*}
167
      * @return {*}
187
      */
168
      */
188
-    getRenderItem(item: eventObject) {
169
+    getRenderItem = (item: eventObject) => {
189
         const onPress = this.props.navigation.navigate.bind(this, 'planning-information', {data: item});
170
         const onPress = this.props.navigation.navigate.bind(this, 'planning-information', {data: item});
190
         if (item.logo !== null) {
171
         if (item.logo !== null) {
191
             return (
172
             return (
221
      *
202
      *
222
      * @return {*}
203
      * @return {*}
223
      */
204
      */
224
-    getRenderEmptyDate() {
225
-        return (
226
-            <Divider/>
227
-        );
228
-    }
205
+    getRenderEmptyDate = () => <Divider/>;
229
 
206
 
230
     render() {
207
     render() {
231
         return (
208
         return (

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

6
 import {Card, List, Paragraph, Text, Title} from 'react-native-paper';
6
 import {Card, List, Paragraph, Text, Title} from 'react-native-paper';
7
 import CustomTabBar from "../../components/Tabbar/CustomTabBar";
7
 import CustomTabBar from "../../components/Tabbar/CustomTabBar";
8
 
8
 
9
-type Props = {
10
-    navigation: Object,
11
-};
9
+type Props = {};
12
 
10
 
13
 const LOGO = "https://etud.insa-toulouse.fr/~amicale_app/images/Proxiwash.png";
11
 const LOGO = "https://etud.insa-toulouse.fr/~amicale_app/images/Proxiwash.png";
14
 
12
 

+ 2
- 1
src/screens/Services/Proximo/ProximoAboutScreen.js View File

5
 import i18n from "i18n-js";
5
 import i18n from "i18n-js";
6
 import {Card, List, Paragraph, Text} from 'react-native-paper';
6
 import {Card, List, Paragraph, Text} from 'react-native-paper';
7
 import CustomTabBar from "../../../components/Tabbar/CustomTabBar";
7
 import CustomTabBar from "../../../components/Tabbar/CustomTabBar";
8
+import {StackNavigationProp} from "@react-navigation/stack";
8
 
9
 
9
 type Props = {
10
 type Props = {
10
-    navigation: Object,
11
+    navigation: StackNavigationProp,
11
 };
12
 };
12
 
13
 
13
 const LOGO = "https://etud.insa-toulouse.fr/~amicale_app/images/Proximo.png";
14
 const LOGO = "https://etud.insa-toulouse.fr/~amicale_app/images/Proximo.png";

+ 7
- 4
src/screens/Services/Proximo/ProximoListScreen.js View File

9
 import ProximoListItem from "../../../components/Lists/Proximo/ProximoListItem";
9
 import ProximoListItem from "../../../components/Lists/Proximo/ProximoListItem";
10
 import MaterialHeaderButtons, {Item} from "../../../components/Overrides/CustomHeaderButton";
10
 import MaterialHeaderButtons, {Item} from "../../../components/Overrides/CustomHeaderButton";
11
 import {withCollapsible} from "../../../utils/withCollapsible";
11
 import {withCollapsible} from "../../../utils/withCollapsible";
12
+import {StackNavigationProp} from "@react-navigation/stack";
13
+import type {CustomTheme} from "../../../managers/ThemeManager";
14
+import {Collapsible} from "react-navigation-collapsible";
12
 
15
 
13
 function sortPrice(a, b) {
16
 function sortPrice(a, b) {
14
     return a.price - b.price;
17
     return a.price - b.price;
37
 const LIST_ITEM_HEIGHT = 84;
40
 const LIST_ITEM_HEIGHT = 84;
38
 
41
 
39
 type Props = {
42
 type Props = {
40
-    navigation: Object,
41
-    route: Object,
42
-    theme: Object,
43
-    collapsibleStack: Object,
43
+    navigation: StackNavigationProp,
44
+    route: { params: { data: { data: Object }, shouldFocusSearchBar: boolean } },
45
+    theme: CustomTheme,
46
+    collapsibleStack: Collapsible,
44
 }
47
 }
45
 
48
 
46
 type State = {
49
 type State = {

+ 10
- 24
src/screens/Services/Proximo/ProximoMainScreen.js View File

6
 import WebSectionList from "../../../components/Screens/WebSectionList";
6
 import WebSectionList from "../../../components/Screens/WebSectionList";
7
 import {List, withTheme} from 'react-native-paper';
7
 import {List, withTheme} from 'react-native-paper';
8
 import MaterialHeaderButtons, {Item} from "../../../components/Overrides/CustomHeaderButton";
8
 import MaterialHeaderButtons, {Item} from "../../../components/Overrides/CustomHeaderButton";
9
+import {StackNavigationProp} from "@react-navigation/stack";
10
+import type {CustomTheme} from "../../../managers/ThemeManager";
9
 
11
 
10
 const DATA_URL = "https://etud.insa-toulouse.fr/~proximo/data/stock-v2.json";
12
 const DATA_URL = "https://etud.insa-toulouse.fr/~proximo/data/stock-v2.json";
11
 const LIST_ITEM_HEIGHT = 84;
13
 const LIST_ITEM_HEIGHT = 84;
12
 
14
 
13
 type Props = {
15
 type Props = {
14
-    navigation: Object,
15
-    route: Object,
16
+    navigation: StackNavigationProp,
17
+    theme: CustomTheme,
16
 }
18
 }
17
 
19
 
18
 type State = {
20
 type State = {
27
 
29
 
28
     articles: Object;
30
     articles: Object;
29
 
31
 
30
-    onPressSearchBtn: Function;
31
-    onPressAboutBtn: Function;
32
-    getRenderItem: Function;
33
-    createDataset: Function;
34
-
35
-    colors: Object;
36
-
37
-    constructor(props) {
38
-        super(props);
39
-        this.onPressSearchBtn = this.onPressSearchBtn.bind(this);
40
-        this.onPressAboutBtn = this.onPressAboutBtn.bind(this);
41
-        this.getRenderItem = this.getRenderItem.bind(this);
42
-        this.createDataset = this.createDataset.bind(this);
43
-        this.colors = props.theme.colors;
44
-    }
45
-
46
     /**
32
     /**
47
      * Function used to sort items in the list.
33
      * Function used to sort items in the list.
48
      * Makes the All category stick to the top and sorts the others by name ascending
34
      * Makes the All category stick to the top and sorts the others by name ascending
83
      * Callback used when the search button is pressed.
69
      * Callback used when the search button is pressed.
84
      * This will open a new ProximoListScreen with all items displayed
70
      * This will open a new ProximoListScreen with all items displayed
85
      */
71
      */
86
-    onPressSearchBtn() {
72
+    onPressSearchBtn = () => {
87
         let searchScreenData = {
73
         let searchScreenData = {
88
             shouldFocusSearchBar: true,
74
             shouldFocusSearchBar: true,
89
             data: {
75
             data: {
97
             },
83
             },
98
         };
84
         };
99
         this.props.navigation.navigate('proximo-list', searchScreenData);
85
         this.props.navigation.navigate('proximo-list', searchScreenData);
100
-    }
86
+    };
101
 
87
 
102
     /**
88
     /**
103
      * Callback used when the about button is pressed.
89
      * Callback used when the about button is pressed.
104
      * This will open the ProximoAboutScreen
90
      * This will open the ProximoAboutScreen
105
      */
91
      */
106
-    onPressAboutBtn() {
92
+    onPressAboutBtn = () => {
107
         this.props.navigation.navigate('proximo-about');
93
         this.props.navigation.navigate('proximo-about');
108
     }
94
     }
109
 
95
 
134
      * @param fetchedData
120
      * @param fetchedData
135
      * @return {*}
121
      * @return {*}
136
      * */
122
      * */
137
-    createDataset(fetchedData: Object) {
123
+    createDataset = (fetchedData: Object) => {
138
         return [
124
         return [
139
             {
125
             {
140
                 title: '',
126
                 title: '',
202
      * @param item The category to render
188
      * @param item The category to render
203
      * @return {*}
189
      * @return {*}
204
      */
190
      */
205
-    getRenderItem({item}: Object) {
191
+    getRenderItem = ({item}: Object) => {
206
         let dataToSend = {
192
         let dataToSend = {
207
             shouldFocusSearchBar: false,
193
             shouldFocusSearchBar: false,
208
             data: item,
194
             data: item,
218
                     left={props => <List.Icon
204
                     left={props => <List.Icon
219
                         {...props}
205
                         {...props}
220
                         icon={item.type.icon}
206
                         icon={item.type.icon}
221
-                        color={this.colors.primary}/>}
207
+                        color={this.props.theme.colors.primary}/>}
222
                     right={props => <List.Icon {...props} icon={'chevron-right'}/>}
208
                     right={props => <List.Icon {...props} icon={'chevron-right'}/>}
223
                     style={{
209
                     style={{
224
                         height: LIST_ITEM_HEIGHT,
210
                         height: LIST_ITEM_HEIGHT,

+ 34
- 15
src/screens/Services/ServicesScreen.js View File

12
 import i18n from 'i18n-js';
12
 import i18n from 'i18n-js';
13
 import MaterialHeaderButtons, {Item} from "../../components/Overrides/CustomHeaderButton";
13
 import MaterialHeaderButtons, {Item} from "../../components/Overrides/CustomHeaderButton";
14
 import ConnectionManager from "../../managers/ConnectionManager";
14
 import ConnectionManager from "../../managers/ConnectionManager";
15
+import {StackNavigationProp} from "@react-navigation/stack";
15
 
16
 
16
 type Props = {
17
 type Props = {
17
-    navigation: Object,
18
-    route: Object,
18
+    navigation: StackNavigationProp,
19
     collapsibleStack: Collapsible,
19
     collapsibleStack: Collapsible,
20
     theme: CustomTheme,
20
     theme: CustomTheme,
21
 }
21
 }
22
 
22
 
23
+export type listItem = {
24
+    title: string,
25
+    description: string,
26
+    image: string | number,
27
+    shouldLogin: boolean,
28
+    content: cardList,
29
+}
30
+
23
 const CLUBS_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Clubs.png";
31
 const CLUBS_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Clubs.png";
24
 const PROFILE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ProfilAmicaliste.png";
32
 const PROFILE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ProfilAmicaliste.png";
25
 const VOTE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Vote.png";
33
 const VOTE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Vote.png";
36
 const EMAIL_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Bluemind.png";
44
 const EMAIL_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Bluemind.png";
37
 const ENT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ENT.png";
45
 const ENT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ENT.png";
38
 
46
 
39
-export type listItem = {
40
-    title: string,
41
-    description: string,
42
-    image: string | number,
43
-    shouldLogin: boolean,
44
-    content: cardList,
45
-}
46
-
47
-type State = {}
48
-
49
-class ServicesScreen extends React.Component<Props, State> {
47
+class ServicesScreen extends React.Component<Props> {
50
 
48
 
51
     amicaleDataset: cardList;
49
     amicaleDataset: cardList;
52
     studentsDataset: cardList;
50
     studentsDataset: cardList;
179
 
177
 
180
     onAboutPress = () => this.props.navigation.navigate('amicale-contact');
178
     onAboutPress = () => this.props.navigation.navigate('amicale-contact');
181
 
179
 
182
-    getAvatar(props, source: string | number) {
180
+    /**
181
+     * Gets the list title image for the list.
182
+     *
183
+     * If the source is a string, we are using an icon.
184
+     * If the source is a number, we are using an internal image.
185
+     *
186
+     * @param props Props to pass to the component
187
+     * @param source The source image to display. Can be a string for icons or a number for local images
188
+     * @returns {*}
189
+     */
190
+    getListTitleImage(props, source: string | number) {
183
         if (typeof source === "number")
191
         if (typeof source === "number")
184
             return <Avatar.Image
192
             return <Avatar.Image
185
                 {...props}
193
                 {...props}
197
             />
205
             />
198
     }
206
     }
199
 
207
 
208
+    /**
209
+     * Redirects to the given route or to the login screen if user is not logged in.
210
+     *
211
+     * @param route The route to navigate to
212
+     */
200
     onAmicaleServicePress(route: string) {
213
     onAmicaleServicePress(route: string) {
201
         if (ConnectionManager.getInstance().isLoggedIn())
214
         if (ConnectionManager.getInstance().isLoggedIn())
202
             this.props.navigation.navigate(route);
215
             this.props.navigation.navigate(route);
204
             this.props.navigation.navigate("login", {nextScreen: route});
217
             this.props.navigation.navigate("login", {nextScreen: route});
205
     }
218
     }
206
 
219
 
220
+    /**
221
+     * A list item showing a list of available services for the current category
222
+     *
223
+     * @param item
224
+     * @returns {*}
225
+     */
207
     renderItem = ({item}: { item: listItem }) => {
226
     renderItem = ({item}: { item: listItem }) => {
208
         return (
227
         return (
209
             <TouchableRipple
228
             <TouchableRipple
216
                 <View>
235
                 <View>
217
                     <Card.Title
236
                     <Card.Title
218
                         title={item.title}
237
                         title={item.title}
219
-                        left={(props) => this.getAvatar(props, item.image)}
238
+                        left={(props) => this.getListTitleImage(props, item.image)}
220
                         right={(props) => <List.Icon {...props} icon="chevron-right"/>}
239
                         right={(props) => <List.Icon {...props} icon="chevron-right"/>}
221
                     />
240
                     />
222
                     <CardList
241
                     <CardList

+ 6
- 2
src/screens/Services/ServicesSectionScreen.js View File

7
 import {Collapsible} from "react-navigation-collapsible";
7
 import {Collapsible} from "react-navigation-collapsible";
8
 import {CommonActions} from "@react-navigation/native";
8
 import {CommonActions} from "@react-navigation/native";
9
 import type {listItem} from "./ServicesScreen";
9
 import type {listItem} from "./ServicesScreen";
10
+import {StackNavigationProp} from "@react-navigation/stack";
10
 
11
 
11
 type Props = {
12
 type Props = {
12
-    navigation: Object,
13
-    route: Object,
13
+    navigation: StackNavigationProp,
14
+    route: { params: { data: listItem | null } },
14
     collapsibleStack: Collapsible,
15
     collapsibleStack: Collapsible,
15
 }
16
 }
16
 
17
 
23
         this.handleNavigationParams();
24
         this.handleNavigationParams();
24
     }
25
     }
25
 
26
 
27
+    /**
28
+     * Recover the list to display from navigation parameters
29
+     */
26
     handleNavigationParams() {
30
     handleNavigationParams() {
27
         if (this.props.route.params != null) {
31
         if (this.props.route.params != null) {
28
             if (this.props.route.params.data != null) {
32
             if (this.props.route.params.data != null) {

+ 1
- 1
src/utils/WebData.js View File

32
  * @param params The params to use for this request
32
  * @param params The params to use for this request
33
  * @returns {Promise<R>}
33
  * @returns {Promise<R>}
34
  */
34
  */
35
-export async function apiRequest(path: string, method: string, params: ?{ [key: string]: string }) {
35
+export async function apiRequest(path: string, method: string, params: ?{ [key: string]: string | number }) {
36
     if (params === undefined || params === null)
36
     if (params === undefined || params === null)
37
         params = {};
37
         params = {};
38
 
38
 

Loading…
Cancel
Save