Browse Source

Show proxiwash message in header if available

Arnaud Vergnet 2 years ago
parent
commit
3b2776542a

+ 8
- 0
locales/en.json View File

@@ -55,6 +55,10 @@
55 55
       "tips": "Tips",
56 56
       "numAvailable": "available",
57 57
       "numAvailablePlural": "available",
58
+      "errors": {
59
+        "title": "Proxiwash message",
60
+        "button": "More info"
61
+      },
58 62
       "washinsa": {
59 63
         "title": "INSA laundromat",
60 64
         "subtitle": "Your favorite laundromat!!",
@@ -93,6 +97,10 @@
93 97
         "unknown": "UNKNOWN"
94 98
       },
95 99
       "notifications": {
100
+        "channel": {
101
+          "title": "Laundry reminders",
102
+          "description": "Get reminders for watched washers/dryers"
103
+        },
96 104
         "machineFinishedTitle": "Laundry Ready",
97 105
         "machineFinishedBody": "Machine n°{{number}} is finished and your laundry is ready for pickup",
98 106
         "machineRunningTitle": "Laundry running: {{time}} minutes left",

+ 8
- 0
locales/fr.json View File

@@ -55,6 +55,10 @@
55 55
       "tips": "Conseils",
56 56
       "numAvailable": "disponible",
57 57
       "numAvailablePlural": "disponibles",
58
+      "errors": {
59
+        "title": "Message laverie",
60
+        "button": "En savoir plus"
61
+      },
58 62
       "washinsa": {
59 63
         "title": "Laverie INSA",
60 64
         "subtitle": "Ta laverie préférée !!",
@@ -93,6 +97,10 @@
93 97
         "unknown": "INCONNU"
94 98
       },
95 99
       "notifications": {
100
+        "channel": {
101
+          "title": "Rappels laverie",
102
+          "description": "Recevoir des rappels pour les machines demandées"
103
+        },
96 104
         "machineFinishedTitle": "Linge prêt",
97 105
         "machineFinishedBody": "La machine n°{{number}} est terminée et ton linge est prêt à être récupéré",
98 106
         "machineRunningTitle": "Machine en cours: {{time}} minutes restantes",

+ 0
- 64
src/components/Lists/Proximo/ProximoListHeader.tsx View File

@@ -1,64 +0,0 @@
1
-import React from 'react';
2
-import { StyleSheet } from 'react-native';
3
-import { Avatar, Button, Card, Text } from 'react-native-paper';
4
-import TimeAgo from 'react-native-timeago';
5
-import i18n from 'i18n-js';
6
-import { useNavigation } from '@react-navigation/core';
7
-import { MainRoutes } from '../../../navigation/MainNavigator';
8
-import ProxiwashConstants from '../../../constants/ProxiwashConstants';
9
-
10
-let moment = require('moment'); //load moment module to set local language
11
-require('moment/locale/fr'); // import moment local language file during the application build
12
-moment.locale('fr');
13
-
14
-type Props = {
15
-  date?: Date;
16
-  selectedWash: 'tripodeB' | 'washinsa';
17
-};
18
-
19
-const styles = StyleSheet.create({
20
-  card: {
21
-    marginHorizontal: 5,
22
-  },
23
-  actions: {
24
-    justifyContent: 'center',
25
-  },
26
-});
27
-
28
-function ProximoListHeader(props: Props) {
29
-  const navigation = useNavigation();
30
-  const { date, selectedWash } = props;
31
-  let title = i18n.t('screens.proxiwash.washinsa.title');
32
-  let icon = ProxiwashConstants.washinsa.icon;
33
-  if (selectedWash === 'tripodeB') {
34
-    title = i18n.t('screens.proxiwash.tripodeB.title');
35
-    icon = ProxiwashConstants.tripodeB.icon;
36
-  }
37
-  return (
38
-    <Card style={styles.card}>
39
-      <Card.Title
40
-        title={title}
41
-        subtitle={
42
-          date ? (
43
-            <Text>
44
-              {i18n.t('screens.proxiwash.updated')}
45
-              <TimeAgo time={date} interval={2000} />
46
-            </Text>
47
-          ) : null
48
-        }
49
-        left={(iconProps) => <Avatar.Icon icon={icon} size={iconProps.size} />}
50
-      />
51
-      <Card.Actions style={styles.actions}>
52
-        <Button
53
-          mode={'contained'}
54
-          onPress={() => navigation.navigate(MainRoutes.Settings)}
55
-          icon={'swap-horizontal'}
56
-        >
57
-          {i18n.t('screens.proxiwash.switch')}
58
-        </Button>
59
-      </Card.Actions>
60
-    </Card>
61
-  );
62
-}
63
-
64
-export default ProximoListHeader;

+ 129
- 0
src/components/Lists/Proxiwash/ProxiwashListHeader.tsx View File

@@ -0,0 +1,129 @@
1
+import React from 'react';
2
+import { Linking, StyleSheet } from 'react-native';
3
+import {
4
+  Avatar,
5
+  Button,
6
+  Card,
7
+  Paragraph,
8
+  Text,
9
+  useTheme,
10
+} from 'react-native-paper';
11
+import TimeAgo from 'react-native-timeago';
12
+import i18n from 'i18n-js';
13
+import { useNavigation } from '@react-navigation/core';
14
+import { MainRoutes } from '../../../navigation/MainNavigator';
15
+import ProxiwashConstants from '../../../constants/ProxiwashConstants';
16
+import { ProxiwashInfoType } from '../../../screens/Proxiwash/ProxiwashScreen';
17
+import * as Animatable from 'react-native-animatable';
18
+
19
+let moment = require('moment'); //load moment module to set local language
20
+require('moment/locale/fr'); // import moment local language file during the application build
21
+moment.locale('fr');
22
+
23
+type Props = {
24
+  date?: Date;
25
+  selectedWash: 'tripodeB' | 'washinsa';
26
+  info?: ProxiwashInfoType;
27
+};
28
+
29
+const styles = StyleSheet.create({
30
+  card: {
31
+    marginHorizontal: 5,
32
+  },
33
+  messageCard: {
34
+    marginTop: 50,
35
+    marginBottom: 10,
36
+  },
37
+  actions: {
38
+    justifyContent: 'center',
39
+  },
40
+});
41
+
42
+function ProxiwashListHeader(props: Props) {
43
+  const navigation = useNavigation();
44
+  const theme = useTheme();
45
+  const { date, selectedWash } = props;
46
+  let title = i18n.t('screens.proxiwash.washinsa.title');
47
+  let icon = ProxiwashConstants.washinsa.icon;
48
+  if (selectedWash === 'tripodeB') {
49
+    title = i18n.t('screens.proxiwash.tripodeB.title');
50
+    icon = ProxiwashConstants.tripodeB.icon;
51
+  }
52
+  const message = props.info?.message;
53
+  return (
54
+    <>
55
+      <Card style={styles.card}>
56
+        <Card.Title
57
+          title={title}
58
+          subtitle={
59
+            date ? (
60
+              <Text>
61
+                {i18n.t('screens.proxiwash.updated')}
62
+                <TimeAgo time={date} interval={2000} />
63
+              </Text>
64
+            ) : null
65
+          }
66
+          left={(iconProps) => (
67
+            <Avatar.Icon icon={icon} size={iconProps.size} />
68
+          )}
69
+        />
70
+        <Card.Actions style={styles.actions}>
71
+          <Button
72
+            mode={'contained'}
73
+            onPress={() => navigation.navigate(MainRoutes.Settings)}
74
+            icon={'swap-horizontal'}
75
+          >
76
+            {i18n.t('screens.proxiwash.switch')}
77
+          </Button>
78
+        </Card.Actions>
79
+      </Card>
80
+      {message ? (
81
+        <Card
82
+          style={{
83
+            ...styles.card,
84
+            ...styles.messageCard,
85
+          }}
86
+        >
87
+          <Animatable.View
88
+            useNativeDriver={false}
89
+            animation={'flash'}
90
+            iterationCount={'infinite'}
91
+            duration={2000}
92
+          >
93
+            <Card.Title
94
+              title={i18n.t('screens.proxiwash.errors.title')}
95
+              titleStyle={{
96
+                color: theme.colors.primary,
97
+              }}
98
+              left={(iconProps) => (
99
+                <Avatar.Icon icon={'alert'} size={iconProps.size} />
100
+              )}
101
+            />
102
+          </Animatable.View>
103
+          <Card.Content>
104
+            <Paragraph
105
+              style={{
106
+                color: theme.colors.warning,
107
+              }}
108
+            >
109
+              {message}
110
+            </Paragraph>
111
+          </Card.Content>
112
+          <Card.Actions style={styles.actions}>
113
+            <Button
114
+              mode={'contained'}
115
+              onPress={() =>
116
+                Linking.openURL(ProxiwashConstants[selectedWash].webPageUrl)
117
+              }
118
+              icon={'open-in-new'}
119
+            >
120
+              {i18n.t('screens.proxiwash.errors.button')}
121
+            </Button>
122
+          </Card.Actions>
123
+        </Card>
124
+      ) : null}
125
+    </>
126
+  );
127
+}
128
+
129
+export default ProxiwashListHeader;

+ 12
- 2
src/screens/Proxiwash/ProxiwashScreen.tsx View File

@@ -52,7 +52,7 @@ import GENERAL_STYLES from '../../constants/Styles';
52 52
 import { readData } from '../../utils/WebData';
53 53
 import { useNavigation } from '@react-navigation/core';
54 54
 import { setupMachineNotification } from '../../utils/Notifications';
55
-import ProximoListHeader from '../../components/Lists/Proximo/ProximoListHeader';
55
+import ProxiwashListHeader from '../../components/Lists/Proxiwash/ProxiwashListHeader';
56 56
 import {
57 57
   getPreferenceNumber,
58 58
   getPreferenceObject,
@@ -76,7 +76,13 @@ export type ProxiwashMachineType = {
76 76
   program: string;
77 77
 };
78 78
 
79
+export type ProxiwashInfoType = {
80
+  message: string;
81
+  last_checked: number;
82
+};
83
+
79 84
 type FetchedDataType = {
85
+  info: ProxiwashInfoType;
80 86
   dryers: Array<ProxiwashMachineType>;
81 87
   washers: Array<ProxiwashMachineType>;
82 88
 };
@@ -444,7 +450,11 @@ function ProxiwashScreen() {
444 450
   ) => {
445 451
     if (data) {
446 452
       return (
447
-        <ProximoListHeader date={lastRefreshDate} selectedWash={selectedWash} />
453
+        <ProxiwashListHeader
454
+          date={lastRefreshDate}
455
+          selectedWash={selectedWash}
456
+          info={data?.info}
457
+        />
448 458
       );
449 459
     } else {
450 460
       return null;

Loading…
Cancel
Save