Browse Source

Fixed watchlist fetch + use modal instead of alert

keplyx 4 years ago
parent
commit
798617d881

+ 1
- 1
components/FeedItem.js View File

@@ -9,7 +9,7 @@ const ICON_AMICALE = require('../assets/amicale.png');
9 9
 function FeedItem(props) {
10 10
     const {colors} = props.theme;
11 11
     return (
12
-        <Card style={{margin: 5}}>
12
+        <Card style={{margin: 10}}>
13 13
             <Card.Title
14 14
                 title={props.title}
15 15
                 subtitle={props.subtitle}

+ 8
- 5
screens/About/AboutScreen.js View File

@@ -7,7 +7,7 @@ import appJson from '../../app';
7 7
 import AsyncStorageManager from "../../utils/AsyncStorageManager";
8 8
 import {Modalize} from "react-native-modalize";
9 9
 import ThemeManager from "../../utils/ThemeManager";
10
-import {Avatar, Card, Text, Title, List, Button} from 'react-native-paper';
10
+import {Avatar, Button, Card, List, Text, Title} from 'react-native-paper';
11 11
 
12 12
 const links = {
13 13
     appstore: 'https://apps.apple.com/us/app/campus-amicale-insat/id1477722148',
@@ -271,8 +271,8 @@ export default class AboutScreen extends React.Component<Props, State> {
271 271
                 return (
272 272
                     <List.Item
273 273
                         title={item.text}
274
-                        left={props => <List.Icon {...props} icon={item.icon} />}
275
-                        right={props => <List.Icon {...props} icon={'chevron-right'} />}
274
+                        left={props => <List.Icon {...props} icon={item.icon}/>}
275
+                        right={props => <List.Icon {...props} icon={'chevron-right'}/>}
276 276
                         onPress={item.onPressCallback}
277 277
                     />
278 278
                 );
@@ -280,7 +280,7 @@ export default class AboutScreen extends React.Component<Props, State> {
280 280
                 return (
281 281
                     <List.Item
282 282
                         title={item.text}
283
-                        left={props => <List.Icon {...props} icon={item.icon} />}
283
+                        left={props => <List.Icon {...props} icon={item.icon}/>}
284 284
                         onPress={item.onPressCallback}
285 285
                     />
286 286
                 );
@@ -311,7 +311,10 @@ export default class AboutScreen extends React.Component<Props, State> {
311 311
         return (
312 312
             <Modalize ref={this.modalRef}
313 313
                       adjustToContentHeight
314
-                      modalStyle={{backgroundColor: ThemeManager.getCurrentThemeVariables().surface}}>
314
+                      handlePosition={'inside'}
315
+                      modalStyle={{backgroundColor: ThemeManager.getCurrentThemeVariables().surface}}
316
+                      handleStyle={{backgroundColor: ThemeManager.getCurrentThemeVariables().text}}
317
+            >
315 318
                 <View style={{
316 319
                     flex: 1,
317 320
                     padding: 20

+ 74
- 22
screens/Proxiwash/ProxiwashScreen.js View File

@@ -7,10 +7,12 @@ import WebSectionList from "../../components/WebSectionList";
7 7
 import NotificationsManager from "../../utils/NotificationsManager";
8 8
 import AsyncStorageManager from "../../utils/AsyncStorageManager";
9 9
 import * as Expo from "expo";
10
-import {Card, Banner, Avatar} from 'react-native-paper';
10
+import {Avatar, Banner, Button, Card, Text} from 'react-native-paper';
11 11
 import HeaderButton from "../../components/HeaderButton";
12 12
 import ProxiwashListItem from "../../components/ProxiwashListItem";
13 13
 import ProxiwashConstants from "../../constants/ProxiwashConstants";
14
+import {Modalize} from "react-native-modalize";
15
+import ThemeManager from "../../utils/ThemeManager";
14 16
 
15 17
 const DATA_URL = "https://etud.insa-toulouse.fr/~amicale_app/washinsa/washinsa.json";
16 18
 
@@ -27,6 +29,7 @@ type Props = {
27 29
 type State = {
28 30
     refreshing: boolean,
29 31
     firstLoading: boolean,
32
+    modalCurrentDisplayItem: React.Node,
30 33
     machinesWatched: Array<string>,
31 34
     bannerVisible: boolean,
32 35
 };
@@ -38,6 +41,8 @@ type State = {
38 41
  */
39 42
 export default class ProxiwashScreen extends React.Component<Props, State> {
40 43
 
44
+    modalRef: { current: null | Modalize };
45
+
41 46
     onAboutPress: Function;
42 47
     getRenderItem: Function;
43 48
     getRenderSectionHeader: Function;
@@ -52,6 +57,7 @@ export default class ProxiwashScreen extends React.Component<Props, State> {
52 57
         fetchedData: {},
53 58
         // machinesWatched: JSON.parse(dataString),
54 59
         machinesWatched: [],
60
+        modalCurrentDisplayItem: null,
55 61
         bannerVisible: AsyncStorageManager.getInstance().preferences.proxiwashShowBanner.current === '1',
56 62
     };
57 63
 
@@ -60,6 +66,7 @@ export default class ProxiwashScreen extends React.Component<Props, State> {
60 66
      */
61 67
     constructor() {
62 68
         super();
69
+        this.modalRef = React.createRef();
63 70
         stateStrings[ProxiwashConstants.machineStates.TERMINE] = i18n.t('proxiwashScreen.states.finished');
64 71
         stateStrings[ProxiwashConstants.machineStates.DISPONIBLE] = i18n.t('proxiwashScreen.states.ready');
65 72
         stateStrings[ProxiwashConstants.machineStates["EN COURS"]] = i18n.t('proxiwashScreen.states.running');
@@ -238,29 +245,40 @@ export default class ProxiwashScreen extends React.Component<Props, State> {
238 245
         ];
239 246
     }
240 247
 
241
-    /**
242
-     * Show an alert fo a machine, allowing to enable/disable notifications if running
243
-     *
244
-     * @param title
245
-     * @param item
246
-     * @param isDryer
247
-     */
248
-    showAlert(title: string, item: Object, isDryer: boolean) {
249
-        let buttons = [{text: i18n.t("proxiwashScreen.modal.ok")}];
248
+    showModal(title: string, item: Object, isDryer: boolean) {
249
+        this.setState({
250
+            modalCurrentDisplayItem: this.getModalContent(title, item, isDryer)
251
+        });
252
+        if (this.modalRef.current) {
253
+            this.modalRef.current.open();
254
+        }
255
+    }
256
+
257
+    onSetupNotificationsPress(machineId: string) {
258
+        if (this.modalRef.current) {
259
+            this.modalRef.current.close();
260
+        }
261
+        this.setupNotifications(machineId)
262
+    }
263
+
264
+    getModalContent(title: string, item: Object, isDryer: boolean) {
265
+        let button = {
266
+            text: i18n.t("proxiwashScreen.modal.ok"),
267
+            icon: '',
268
+            onPress: undefined
269
+        };
250 270
         let message = modalStateStrings[ProxiwashConstants.machineStates[item.state]];
251
-        const onPress = this.setupNotifications.bind(this, item.number);
271
+        const onPress = this.onSetupNotificationsPress.bind(this, item.number);
252 272
         if (ProxiwashConstants.machineStates[item.state] === ProxiwashConstants.machineStates["EN COURS"]) {
253
-            buttons = [
273
+            button =
254 274
                 {
255 275
                     text: this.isMachineWatched(item.number) ?
256 276
                         i18n.t("proxiwashScreen.modal.disableNotifications") :
257 277
                         i18n.t("proxiwashScreen.modal.enableNotifications"),
278
+                    icon: '',
258 279
                     onPress: onPress
259
-                },
260
-                {
261
-                    text: i18n.t("proxiwashScreen.modal.cancel")
262 280
                 }
263
-            ];
281
+            ;
264 282
             message = i18n.t('proxiwashScreen.modal.running',
265 283
                 {
266 284
                     start: item.startTime,
@@ -273,13 +291,39 @@ export default class ProxiwashScreen extends React.Component<Props, State> {
273 291
             else
274 292
                 message += '\n' + i18n.t('proxiwashScreen.washersTariff');
275 293
         }
276
-        Alert.alert(
277
-            title,
278
-            message,
279
-            buttons
294
+        return (
295
+            <View style={{
296
+                flex: 1,
297
+                padding: 20
298
+            }}>
299
+                <Card.Title
300
+                    title={title}
301
+                    left={() => <Avatar.Icon
302
+                        icon={isDryer ? 'tumble-dryer' : 'washing-machine'}
303
+                        color={ThemeManager.getCurrentThemeVariables().text}
304
+                        style={{backgroundColor: 'transparent'}}/>}
305
+
306
+                />
307
+                <Card.Content>
308
+                    <Text>{message}</Text>
309
+                </Card.Content>
310
+
311
+                {button.onPress !== undefined ?
312
+                    <Card.Actions>
313
+                        <Button
314
+                            icon={button.icon}
315
+                            mode="contained"
316
+                            onPress={button.onPress}
317
+                            style={{marginLeft: 'auto', marginRight: 'auto'}}
318
+                        >
319
+                            {button.text}
320
+                        </Button>
321
+                    </Card.Actions> : null}
322
+            </View>
280 323
         );
281 324
     }
282 325
 
326
+
283 327
     onAboutPress() {
284 328
         this.props.navigation.navigate('ProxiwashAboutScreen');
285 329
     }
@@ -305,10 +349,18 @@ export default class ProxiwashScreen extends React.Component<Props, State> {
305 349
                     icon={() => <Avatar.Icon
306 350
                         icon={'information'}
307 351
                         size={40}
308
-                        />}
352
+                    />}
309 353
                 >
310 354
                     {i18n.t('proxiwashScreen.enableNotificationsTip')}
311 355
                 </Banner>
356
+                <Modalize ref={this.modalRef}
357
+                          adjustToContentHeight
358
+                          handlePosition={'inside'}
359
+                          modalStyle={{backgroundColor: ThemeManager.getCurrentThemeVariables().surface}}
360
+                          handleStyle={{backgroundColor: ThemeManager.getCurrentThemeVariables().text}}
361
+                >
362
+                    {this.state.modalCurrentDisplayItem}
363
+                </Modalize>
312 364
                 <WebSectionList
313 365
                     createDataset={this.createDataset}
314 366
                     navigation={nav}
@@ -374,7 +426,7 @@ export default class ProxiwashScreen extends React.Component<Props, State> {
374 426
         const isMachineRunning = ProxiwashConstants.machineStates[item.state] === ProxiwashConstants.machineStates["EN COURS"];
375 427
         const machineName = (section.title === i18n.t('proxiwashScreen.dryers') ? i18n.t('proxiwashScreen.dryer') : i18n.t('proxiwashScreen.washer')) + ' n°' + item.number;
376 428
         const isDryer = section.title === i18n.t('proxiwashScreen.dryers');
377
-        const onPress = this.showAlert.bind(this, machineName, item, isDryer);
429
+        const onPress = this.showModal.bind(this, machineName, item, isDryer);
378 430
         let width = item.donePercent !== '' ? (parseInt(item.donePercent)).toString() + '%' : 0;
379 431
         if (ProxiwashConstants.machineStates[item.state] === '0')
380 432
             width = '100%';

+ 4
- 1
utils/NotificationsManager.js View File

@@ -123,7 +123,10 @@ export default class NotificationsManager {
123 123
                     'Content-Type': 'application/json',
124 124
                 }),
125 125
                 body: JSON.stringify(data) // <-- Post parameters
126
-            });
126
+            }).then((response) => response.json())
127
+                .then((responseJson) => {
128
+                    callback(responseJson);
129
+                });
127 130
         }
128 131
     }
129 132
 

Loading…
Cancel
Save