Browse Source

Changed fb data url to use etud, changed proxiwash display to use a tab system

keplyx 4 years ago
parent
commit
5bda2825c5

+ 2
- 0
components/CustomHeader.js View File

@@ -11,6 +11,7 @@ type Props = {
11 11
     rightMenu: React.Node,
12 12
     title: string,
13 13
     navigation: Object,
14
+    hasTabs: boolean,
14 15
 };
15 16
 
16 17
 /**
@@ -26,6 +27,7 @@ export default class CustomHeader extends React.Component<Props> {
26 27
     static defaultProps = {
27 28
         backButton: false,
28 29
         rightMenu: <Right/>,
30
+        hasTabs: false,
29 31
     };
30 32
 
31 33
     render() {

+ 67
- 30
components/FetchedDataSectionList.js View File

@@ -2,9 +2,9 @@
2 2
 
3 3
 import * as React from 'react';
4 4
 import WebDataManager from "../utils/WebDataManager";
5
-import {Container, Content, H2} from "native-base";
5
+import {Container, Content, Tab, TabHeading, Tabs, Text} from "native-base";
6 6
 import CustomHeader from "./CustomHeader";
7
-import {SectionList, RefreshControl, View} from "react-native";
7
+import {RefreshControl, SectionList, View} from "react-native";
8 8
 
9 9
 type Props = {
10 10
     navigation: Object,
@@ -14,12 +14,12 @@ type State = {
14 14
     refreshing: boolean,
15 15
     firstLoading: boolean,
16 16
     fetchedData: Object,
17
-    machinesWatched : Array<Object>
17
+    machinesWatched: Array<Object>
18 18
 };
19 19
 
20 20
 export default class FetchedDataSectionList extends React.Component<Props, State> {
21 21
 
22
-    webDataManager : WebDataManager;
22
+    webDataManager: WebDataManager;
23 23
 
24 24
     constructor() {
25 25
         super();
@@ -30,7 +30,7 @@ export default class FetchedDataSectionList extends React.Component<Props, State
30 30
         refreshing: false,
31 31
         firstLoading: true,
32 32
         fetchedData: {},
33
-        machinesWatched : [],
33
+        machinesWatched: [],
34 34
     };
35 35
 
36 36
     getFetchUrl() {
@@ -41,7 +41,7 @@ export default class FetchedDataSectionList extends React.Component<Props, State
41 41
         return "Header";
42 42
     }
43 43
 
44
-    getUpdateToastTranslations () {
44
+    getUpdateToastTranslations() {
45 45
         return ["whoa", "nah"];
46 46
     }
47 47
 
@@ -64,12 +64,12 @@ export default class FetchedDataSectionList extends React.Component<Props, State
64 64
         });
65 65
     };
66 66
 
67
-    getRenderItem(item: Object, section : Object, data : Object) {
68
-        return <View />;
67
+    getRenderItem(item: Object, section: Object, data: Object) {
68
+        return <View/>;
69 69
     }
70 70
 
71 71
     getRenderSectionHeader(title: String) {
72
-        return <View />;
72
+        return <View/>;
73 73
     }
74 74
 
75 75
     /**
@@ -77,7 +77,7 @@ export default class FetchedDataSectionList extends React.Component<Props, State
77 77
      * @param fetchedData {Object}
78 78
      * @return {Array}
79 79
      */
80
-    createDataset(fetchedData : Object) : Array<Object> {
80
+    createDataset(fetchedData: Object): Array<Object> {
81 81
         return [];
82 82
     }
83 83
 
@@ -86,35 +86,72 @@ export default class FetchedDataSectionList extends React.Component<Props, State
86 86
      * @param item {Object}
87 87
      * @return {*}
88 88
      */
89
-    getKeyExtractor(item : Object) {
89
+    getKeyExtractor(item: Object) {
90 90
         return item.id;
91 91
     }
92 92
 
93
+    hasTabs() {
94
+        return false;
95
+    }
96
+
97
+    getSectionList(dataset: Array<Object>) {
98
+        return (
99
+            <SectionList
100
+                sections={dataset}
101
+                keyExtractor={(item) => this.getKeyExtractor(item)}
102
+                refreshControl={
103
+                    <RefreshControl
104
+                        refreshing={this.state.refreshing}
105
+                        onRefresh={this._onRefresh}
106
+                    />
107
+                }
108
+                renderSectionHeader={({section: {title}}) =>
109
+                    this.getRenderSectionHeader(title)
110
+                }
111
+                renderItem={({item, section}) =>
112
+                    this.getRenderItem(item, section, dataset)
113
+                }
114
+                style={{minHeight: 300, width: '100%'}}
115
+            />
116
+        );
117
+    }
118
+
119
+    getTabbedView(dataset: Array<Object>) {
120
+        let tabbedView = [];
121
+        for (let i = 0; i < dataset.length; i++) {
122
+            tabbedView.push(
123
+                <Tab heading={<TabHeading><Text>{dataset[i].title}</Text></TabHeading>}>
124
+                    <Content padder>
125
+                        {this.getSectionList(
126
+                            [
127
+                                {
128
+                                    title: dataset[i].title,
129
+                                    data: dataset[i].data,
130
+                                    extraData: dataset[i].extraData,
131
+                                }
132
+                            ]
133
+                        )}
134
+                    </Content>
135
+                </Tab>);
136
+        }
137
+        return tabbedView;
138
+    }
139
+
93 140
     render() {
94 141
         const nav = this.props.navigation;
95 142
         const dataset = this.createDataset(this.state.fetchedData);
96 143
         return (
97 144
             <Container>
98 145
                 <CustomHeader navigation={nav} title={this.getHeaderTranslation()}/>
99
-                <Content padder>
100
-                    <SectionList
101
-                        sections={dataset}
102
-                        keyExtractor={(item) => this.getKeyExtractor(item)}
103
-                        refreshControl={
104
-                            <RefreshControl
105
-                                refreshing={this.state.refreshing}
106
-                                onRefresh={this._onRefresh}
107
-                            />
108
-                        }
109
-                        renderSectionHeader={({section: {title}}) =>
110
-                            this.getRenderSectionHeader(title)
111
-                        }
112
-                        renderItem={({item, section}) =>
113
-                            this.getRenderItem(item, section, dataset)
114
-                        }
115
-                        style={{minHeight: 300, width: '100%'}}
116
-                    />
117
-                </Content>
146
+                {this.hasTabs() ?
147
+                    <Tabs>
148
+                        {this.getTabbedView(dataset)}
149
+                    </Tabs>
150
+                    :
151
+                    <Content padder>
152
+                        {this.getSectionList(dataset)}
153
+                    </Content>
154
+                }
118 155
             </Container>
119 156
         );
120 157
     }

+ 3
- 2
screens/HomeScreen.js View File

@@ -9,7 +9,8 @@ import FetchedDataSectionList from "../components/FetchedDataSectionList";
9 9
 
10 10
 const ICON_AMICALE = require('../assets/amicale.png');
11 11
 const NAME_AMICALE = 'Amicale INSA Toulouse';
12
-const FB_URL = "https://graph.facebook.com/v3.3/amicale.deseleves/posts?fields=message%2Cfull_picture%2Ccreated_time%2Cpermalink_url&&date_format=U&access_token=EAAGliUs4Ei8BAGwHmg7SNnosoEDMuDhP3i5lYOGrIGzZBNeMeGzGhpUigJt167cKXEIM0GiurSgaC0PS4Xg2GBzOVNiZCfr8u48VVB15a9YbOsuhjBqhHAMb2sz6ibwOuDhHSvwRZCUpBZCjmAW12e7RjWJp0jvyNoYYvIQbfaLWi3Nk2mBc";
12
+const FB_URL = "https://etud.insa-toulouse.fr/~vergnet/appli-amicale/facebook_data.json";
13
+
13 14
 
14 15
 /**
15 16
  * Opens a link in the device's browser
@@ -33,7 +34,7 @@ export default class HomeScreen extends FetchedDataSectionList {
33 34
     }
34 35
 
35 36
     getKeyExtractor(item : Object) {
36
-        return item.id;
37
+        return item !== undefined ? item.id : undefined;
37 38
     }
38 39
 
39 40
     createDataset(fetchedData : Object) {

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

@@ -36,7 +36,7 @@ export default class ProximoMainScreen extends FetchedDataSectionList {
36 36
     }
37 37
 
38 38
     getKeyExtractor(item: Object) {
39
-        return item.type;
39
+        return item !== undefined ? item.type : undefined;
40 40
     }
41 41
 
42 42
     createDataset(fetchedData: Object) {

+ 10
- 6
screens/ProxiwashScreen.js View File

@@ -78,7 +78,7 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
78 78
     }
79 79
 
80 80
     getKeyExtractor(item: Object) {
81
-        return item.number;
81
+        return item !== undefined ? item.number : undefined;
82 82
     }
83 83
 
84 84
     /**
@@ -204,6 +204,10 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
204 204
         ];
205 205
     }
206 206
 
207
+    hasTabs(): boolean {
208
+        return true;
209
+    }
210
+
207 211
     /**
208 212
      * Get list item to be rendered
209 213
      *
@@ -233,12 +237,12 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
233 237
                         backgroundColor: ThemeManager.getInstance().getCurrentThemeVariables().containerBgColor
234 238
                     }}/>
235 239
                     <Left>
236
-                        <CustomMaterialIcon icon={section.title === data[0].title ? 'tumble-dryer' : 'washing-machine'}
240
+                        <CustomMaterialIcon icon={section.title === i18n.t('proxiwashScreen.dryers') ? 'tumble-dryer' : 'washing-machine'}
237 241
                                             fontSize={30}
238 242
                         />
239 243
                         <Body>
240 244
                             <Text>
241
-                                {section.title === data[0].title ? i18n.t('proxiwashScreen.dryer') : i18n.t('proxiwashScreen.washer')} n°{item.number}
245
+                                {section.title === i18n.t('proxiwashScreen.dryers') ? i18n.t('proxiwashScreen.dryer') : i18n.t('proxiwashScreen.washer')} n°{item.number}
242 246
                             </Text>
243 247
                             <Text note>
244 248
                                 {item.startTime !== '' ? item.startTime + '/' + item.endTime : ''}
@@ -280,7 +284,7 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
280 284
             </Card>);
281 285
     }
282 286
 
283
-    getRenderSectionHeader(title: String) {
284
-        return <H2 style={{textAlign: 'center', paddingVertical: 10}}>{title}</H2>;
285
-    }
287
+    // getRenderSectionHeader(title: String) {
288
+    //     return <H2 style={{textAlign: 'center', paddingVertical: 10}}>{title}</H2>;
289
+    // }
286 290
 }

Loading…
Cancel
Save