|
@@ -1,18 +1,33 @@
|
1
|
1
|
// @flow
|
2
|
2
|
|
3
|
3
|
import * as React from 'react';
|
4
|
|
-import {Button, H3, Text} from 'native-base';
|
|
4
|
+import {Content, H1, H2, H3, Text} from 'native-base';
|
5
|
5
|
import i18n from "i18n-js";
|
6
|
|
-import {View, Platform} from "react-native";
|
7
|
|
-import CustomMaterialIcon from "../components/CustomMaterialIcon";
|
|
6
|
+import {View, Image} from "react-native";
|
8
|
7
|
import ThemeManager from "../utils/ThemeManager";
|
9
|
8
|
import {Linking} from "expo";
|
10
|
9
|
import BaseContainer from "../components/BaseContainer";
|
|
10
|
+import {Agenda} from 'react-native-calendars';
|
|
11
|
+import HTML from 'react-native-render-html';
|
|
12
|
+import Touchable from 'react-native-platform-touchable';
|
|
13
|
+import Modalize from 'react-native-modalize';
|
|
14
|
+import WebDataManager from "../utils/WebDataManager";
|
|
15
|
+
|
11
|
16
|
|
12
|
17
|
type Props = {
|
13
|
18
|
navigation: Object,
|
14
|
19
|
}
|
15
|
20
|
|
|
21
|
+type State = {
|
|
22
|
+ modalCurrentDisplayItem: Object,
|
|
23
|
+ refreshing: boolean,
|
|
24
|
+ agendaItems: Object,
|
|
25
|
+};
|
|
26
|
+
|
|
27
|
+const FETCH_URL = "https://amicale-insat.fr/event/json/list";
|
|
28
|
+
|
|
29
|
+const AGENDA_MONTH_SPAN = 6;
|
|
30
|
+
|
16
|
31
|
/**
|
17
|
32
|
* Opens a link in the device's browser
|
18
|
33
|
* @param link The link to open
|
|
@@ -24,67 +39,286 @@ function openWebLink(link) {
|
24
|
39
|
/**
|
25
|
40
|
* Class defining the app's planning screen
|
26
|
41
|
*/
|
27
|
|
-export default class PlanningScreen extends React.Component<Props> {
|
|
42
|
+export default class PlanningScreen extends React.Component<Props, State> {
|
28
|
43
|
|
|
44
|
+ modalRef: { current: null | Modalize };
|
|
45
|
+ webDataManager: WebDataManager;
|
29
|
46
|
|
30
|
|
- render() {
|
31
|
|
- const nav = this.props.navigation;
|
|
47
|
+ constructor(props: any) {
|
|
48
|
+ super(props);
|
|
49
|
+ this.modalRef = React.createRef();
|
|
50
|
+ this.webDataManager = new WebDataManager(FETCH_URL);
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ componentDidMount() {
|
|
54
|
+ this._onRefresh();
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ state = {
|
|
58
|
+ modalCurrentDisplayItem: {},
|
|
59
|
+ refreshing: false,
|
|
60
|
+ agendaItems: {}
|
|
61
|
+ };
|
|
62
|
+
|
|
63
|
+ getCurrentDate() {
|
|
64
|
+ let today = new Date();
|
|
65
|
+ return this.getFormattedDate(today);
|
|
66
|
+ }
|
|
67
|
+
|
|
68
|
+ getFormattedDate(date: Date) {
|
|
69
|
+ let dd = String(date.getDate()).padStart(2, '0');
|
|
70
|
+ let mm = String(date.getMonth() + 1).padStart(2, '0'); //January is 0!
|
|
71
|
+ let yyyy = date.getFullYear();
|
|
72
|
+ return yyyy + '-' + mm + '-' + dd;
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ generateEmptyCalendar() {
|
|
76
|
+ let end = new Date(new Date().setMonth(new Date().getMonth() + AGENDA_MONTH_SPAN + 1));
|
|
77
|
+ let daysOfYear = {};
|
|
78
|
+ for (let d = new Date(2019, 8, 1); d <= end; d.setDate(d.getDate() + 1)) {
|
|
79
|
+ daysOfYear[this.getFormattedDate(new Date(d))] = []
|
|
80
|
+ }
|
|
81
|
+ return daysOfYear;
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ getModalContent() {
|
32
|
85
|
return (
|
33
|
|
- <BaseContainer navigation={nav} headerTitle={i18n.t('screens.planning')}>
|
34
|
|
- <View style={{
|
35
|
|
- flexGrow: 1,
|
36
|
|
- justifyContent: 'center',
|
37
|
|
- alignItems: 'center',
|
|
86
|
+ <View style={{
|
|
87
|
+ flex: 1,
|
|
88
|
+ padding: 20
|
|
89
|
+ }}>
|
|
90
|
+ <H1 style={{
|
|
91
|
+ marginTop: 20,
|
|
92
|
+ }}>
|
|
93
|
+ {this.state.modalCurrentDisplayItem.title}
|
|
94
|
+ </H1>
|
|
95
|
+ <H3 style={{
|
|
96
|
+ marginTop: 10,
|
|
97
|
+ color: ThemeManager.getCurrentThemeVariables().listNoteColor
|
38
|
98
|
}}>
|
39
|
|
- { Platform.OS === 'android' ?
|
40
|
|
- <View
|
41
|
|
- style={{
|
42
|
|
- justifyContent: 'center',
|
43
|
|
- alignItems: 'center',
|
44
|
|
- }}>
|
45
|
|
- <View style={{
|
46
|
|
- justifyContent: 'center',
|
47
|
|
- alignItems: 'center',
|
48
|
|
- width: '100%',
|
49
|
|
- height: 100,
|
50
|
|
- marginBottom: 20
|
51
|
|
- }}>
|
52
|
|
- <CustomMaterialIcon
|
53
|
|
- icon={'forklift'}
|
54
|
|
- fontSize={100}
|
55
|
|
- width={100}
|
56
|
|
- color={ThemeManager.getCurrentThemeVariables().fetchedDataSectionListErrorText}/>
|
57
|
|
- </View>
|
58
|
|
-
|
59
|
|
- <H3 style={{
|
60
|
|
- textAlign: 'center',
|
61
|
|
- marginRight: 20,
|
62
|
|
- marginLeft: 20,
|
63
|
|
- color: ThemeManager.getCurrentThemeVariables().fetchedDataSectionListErrorText
|
64
|
|
- }}>
|
65
|
|
- {i18n.t('planningScreen.wipTitle')}
|
66
|
|
- </H3>
|
67
|
|
- <Text style={{
|
68
|
|
- textAlign: 'center',
|
69
|
|
- color: ThemeManager.getCurrentThemeVariables().fetchedDataSectionListErrorText
|
70
|
|
- }}>
|
71
|
|
- {i18n.t('planningScreen.wipSubtitle')}
|
72
|
|
- </Text>
|
|
99
|
+ {this.getFormattedTime(this.state.modalCurrentDisplayItem)}
|
|
100
|
+ </H3>
|
|
101
|
+ <Content>
|
|
102
|
+ {this.state.modalCurrentDisplayItem.logo !== null ?
|
|
103
|
+ <View style={{width: '100%', height: 200, marginTop: 20, marginBottom: 20}}>
|
|
104
|
+ <Image style={{flex: 1, resizeMode: "contain"}}
|
|
105
|
+ source={{uri: this.state.modalCurrentDisplayItem.logo}}/>
|
73
|
106
|
</View>
|
74
|
|
- :
|
75
|
|
- <View/>
|
76
|
|
-
|
77
|
|
- }
|
|
107
|
+ : <View/>}
|
78
|
108
|
|
|
109
|
+ {this.state.modalCurrentDisplayItem.description !== null ?
|
|
110
|
+ // Surround description with div to allow text styling if the description is not html
|
|
111
|
+ <HTML html={"<div>" + this.state.modalCurrentDisplayItem.description + "</div>"}
|
|
112
|
+ tagsStyles={{
|
|
113
|
+ p: {color: ThemeManager.getCurrentThemeVariables().textColor},
|
|
114
|
+ div: {color: ThemeManager.getCurrentThemeVariables().textColor}
|
|
115
|
+ }}/>
|
|
116
|
+ : <View/>}
|
|
117
|
+ </Content>
|
|
118
|
+ </View>
|
|
119
|
+ );
|
|
120
|
+ }
|
79
|
121
|
|
|
122
|
+ showItemDetails(item: Object) {
|
|
123
|
+ this.setState({
|
|
124
|
+ modalCurrentDisplayItem: item
|
|
125
|
+ });
|
|
126
|
+ if (this.modalRef.current) {
|
|
127
|
+ this.modalRef.current.open();
|
|
128
|
+ }
|
|
129
|
+ }
|
80
|
130
|
|
81
|
|
- <Button block style={{marginTop: 20, marginRight: 10, marginLeft: 10}}
|
82
|
|
- onPress={() => openWebLink('https://www.facebook.com/groups/2054302624595234/')}>
|
83
|
|
- <Text>Clubs et Evenements</Text>
|
84
|
|
- </Button>
|
|
131
|
+ getRenderItem(item: Object) {
|
|
132
|
+ return (
|
|
133
|
+ <Touchable
|
|
134
|
+ style={{
|
|
135
|
+ backgroundColor: ThemeManager.getCurrentThemeVariables().containerBgColor,
|
|
136
|
+ borderRadius: 10,
|
|
137
|
+ marginRight: 10,
|
|
138
|
+ marginTop: 17,
|
|
139
|
+ }}
|
|
140
|
+ onPress={() => this.showItemDetails(item)}>
|
|
141
|
+ <View style={{
|
|
142
|
+ padding: 10,
|
|
143
|
+ flex: 1,
|
|
144
|
+ flexDirection: 'row'
|
|
145
|
+ }}>
|
|
146
|
+ <View style={{width: '70%'}}>
|
|
147
|
+ <Text style={{
|
|
148
|
+ color: ThemeManager.getCurrentThemeVariables().listNoteColor,
|
|
149
|
+ marginTop: 5,
|
|
150
|
+ marginBottom: 10
|
|
151
|
+ }}>
|
|
152
|
+ {this.getFormattedTime(item)}
|
|
153
|
+ </Text>
|
|
154
|
+ <H3 style={{marginBottom: 10}}>{item.title}</H3>
|
|
155
|
+ </View>
|
|
156
|
+ <View style={{
|
|
157
|
+ width: '30%',
|
|
158
|
+ height: 80
|
|
159
|
+ }}>
|
|
160
|
+ {item.logo !== null ?
|
|
161
|
+ <Image source={{uri: item.logo}}
|
|
162
|
+ style={{
|
|
163
|
+ flex: 1,
|
|
164
|
+ resizeMode: "contain"
|
|
165
|
+ }}/>
|
|
166
|
+ : <View/>}
|
|
167
|
+ </View>
|
85
|
168
|
</View>
|
|
169
|
+ </Touchable>
|
|
170
|
+ );
|
|
171
|
+ }
|
|
172
|
+
|
|
173
|
+ getRenderEmptyDate() {
|
|
174
|
+ return (
|
|
175
|
+ <View style={{
|
|
176
|
+ padding: 10,
|
|
177
|
+ flex: 1,
|
|
178
|
+ }}>
|
|
179
|
+ <View style={{
|
|
180
|
+ width: '100%',
|
|
181
|
+ height: 1,
|
|
182
|
+ backgroundColor: ThemeManager.getCurrentThemeVariables().agendaEmptyLine,
|
|
183
|
+ marginTop: 'auto',
|
|
184
|
+ marginBottom: 'auto',
|
|
185
|
+ }}/>
|
|
186
|
+ </View>
|
|
187
|
+ );
|
|
188
|
+ }
|
|
189
|
+
|
|
190
|
+ rowHasChanged(r1: Object, r2: Object) {
|
|
191
|
+ if (r1 !== undefined && r2 !== undefined)
|
|
192
|
+ return r1.title !== r2.title;
|
|
193
|
+ else return !(r1 === undefined && r2 === undefined);
|
|
194
|
+ }
|
|
195
|
+
|
|
196
|
+ /**
|
|
197
|
+ * Refresh data and show a toast if any error occurred
|
|
198
|
+ * @private
|
|
199
|
+ */
|
|
200
|
+ _onRefresh = () => {
|
|
201
|
+ this.setState({refreshing: true});
|
|
202
|
+ this.webDataManager.readData()
|
|
203
|
+ .then((fetchedData) => {
|
|
204
|
+ this.setState({
|
|
205
|
+ refreshing: false,
|
|
206
|
+ });
|
|
207
|
+ this.generateEventAgenda(fetchedData);
|
|
208
|
+ })
|
|
209
|
+ .catch((err) => {
|
|
210
|
+ this.setState({
|
|
211
|
+ refreshing: false,
|
|
212
|
+ });
|
|
213
|
+ console.log(err);
|
|
214
|
+ });
|
|
215
|
+ };
|
|
216
|
+
|
|
217
|
+ generateEventAgenda(eventList: Array<Object>) {
|
|
218
|
+ let agendaItems = this.generateEmptyCalendar();
|
|
219
|
+ for (let i = 0; i < eventList.length; i++) {
|
|
220
|
+ if (agendaItems[this.getEventStartDate(eventList[i])] !== undefined)
|
|
221
|
+ agendaItems[this.getEventStartDate(eventList[i])].push(eventList[i]);
|
|
222
|
+ }
|
|
223
|
+ this.setState({agendaItems: agendaItems})
|
|
224
|
+ }
|
|
225
|
+
|
|
226
|
+ getEventStartDate(event: Object) {
|
|
227
|
+ return event.date_begin.split(" ")[0];
|
|
228
|
+ }
|
|
229
|
+
|
|
230
|
+ getEventStartTime(event: Object) {
|
|
231
|
+ if (event !== undefined && Object.keys(event).length > 0 && event.date_begin !== null)
|
|
232
|
+ return this.formatTime(event.date_begin.split(" ")[1]);
|
|
233
|
+ else
|
|
234
|
+ return "";
|
|
235
|
+ }
|
|
236
|
+
|
|
237
|
+ getEventEndTime(event: Object) {
|
|
238
|
+ if (event !== undefined && Object.keys(event).length > 0 && event.date_end !== null)
|
|
239
|
+ return this.formatTime(event.date_end.split(" ")[1]);
|
|
240
|
+ else
|
|
241
|
+ return "";
|
|
242
|
+ }
|
|
243
|
+
|
|
244
|
+ getFormattedTime(event: Object) {
|
|
245
|
+ if (this.getEventEndTime(event) !== "")
|
|
246
|
+ return this.getEventStartTime(event) + " - " + this.getEventEndTime(event)
|
|
247
|
+ else
|
|
248
|
+ return this.getEventStartTime(event);
|
|
249
|
+ }
|
|
250
|
+
|
|
251
|
+ formatTime(time: string) {
|
|
252
|
+ let array = time.split(':');
|
|
253
|
+ return array[0] + ':' + array[1];
|
|
254
|
+ }
|
|
255
|
+
|
|
256
|
+ render() {
|
|
257
|
+ const nav = this.props.navigation;
|
|
258
|
+ return (
|
|
259
|
+ <BaseContainer navigation={nav} headerTitle={i18n.t('screens.planning')}>
|
|
260
|
+ <Modalize ref={this.modalRef}
|
|
261
|
+ modalStyle={{
|
|
262
|
+ backgroundColor: ThemeManager.getCurrentThemeVariables().containerBgColor,
|
|
263
|
+ }}>
|
|
264
|
+ {this.getModalContent()}
|
|
265
|
+ </Modalize>
|
|
266
|
+ <Agenda
|
|
267
|
+ // the list of items that have to be displayed in agenda. If you want to render item as empty date
|
|
268
|
+ // the value of date key kas to be an empty array []. If there exists no value for date key it is
|
|
269
|
+ // considered that the date in question is not yet loaded
|
|
270
|
+ items={this.state.agendaItems}
|
|
271
|
+ // initially selected day
|
|
272
|
+ selected={this.getCurrentDate()}
|
|
273
|
+ // Minimum date that can be selected, dates before minDate will be grayed out. Default = undefined
|
|
274
|
+ minDate={"2019-09-01"}
|
|
275
|
+ // Max amount of months allowed to scroll to the past. Default = 50
|
|
276
|
+ pastScrollRange={1}
|
|
277
|
+ // Max amount of months allowed to scroll to the future. Default = 50
|
|
278
|
+ futureScrollRange={AGENDA_MONTH_SPAN}
|
|
279
|
+ // If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. Make sure to also set the refreshing prop correctly.
|
|
280
|
+ onRefresh={() => this._onRefresh()}
|
|
281
|
+ // Set this true while waiting for new data from a refresh
|
|
282
|
+ refreshing={this.state.refreshing}
|
|
283
|
+ renderItem={(item) => this.getRenderItem(item)}
|
|
284
|
+ renderEmptyDate={() => this.getRenderEmptyDate()}
|
|
285
|
+ rowHasChanged={() => this.rowHasChanged()}
|
|
286
|
+ // agenda theme
|
|
287
|
+ theme={{
|
|
288
|
+ backgroundColor: ThemeManager.getCurrentThemeVariables().agendaBackgroundColor,
|
|
289
|
+ calendarBackground: ThemeManager.getCurrentThemeVariables().containerBgColor,
|
|
290
|
+ textSectionTitleColor: ThemeManager.getCurrentThemeVariables().listNoteColor,
|
|
291
|
+ selectedDayBackgroundColor: ThemeManager.getCurrentThemeVariables().brandPrimary,
|
|
292
|
+ selectedDayTextColor: '#ffffff',
|
|
293
|
+ todayTextColor: ThemeManager.getCurrentThemeVariables().brandPrimary,
|
|
294
|
+ dayTextColor: ThemeManager.getCurrentThemeVariables().textColor,
|
|
295
|
+ textDisabledColor: ThemeManager.getCurrentThemeVariables().textDisabledColor,
|
|
296
|
+ dotColor: ThemeManager.getCurrentThemeVariables().brandPrimary,
|
|
297
|
+ selectedDotColor: '#ffffff',
|
|
298
|
+ arrowColor: 'orange',
|
|
299
|
+ monthTextColor: ThemeManager.getCurrentThemeVariables().brandPrimary,
|
|
300
|
+ indicatorColor: ThemeManager.getCurrentThemeVariables().brandPrimary,
|
|
301
|
+ textDayFontWeight: '300',
|
|
302
|
+ textMonthFontWeight: 'bold',
|
|
303
|
+ textDayHeaderFontWeight: '300',
|
|
304
|
+ textDayFontSize: 16,
|
|
305
|
+ textMonthFontSize: 16,
|
|
306
|
+ textDayHeaderFontSize: 16,
|
|
307
|
+ agendaDayTextColor: ThemeManager.getCurrentThemeVariables().listNoteColor,
|
|
308
|
+ agendaDayNumColor: ThemeManager.getCurrentThemeVariables().listNoteColor,
|
|
309
|
+ agendaTodayColor: ThemeManager.getCurrentThemeVariables().brandPrimary,
|
|
310
|
+ agendaKnobColor: ThemeManager.getCurrentThemeVariables().brandPrimary,
|
|
311
|
+ // Fix for days hiding behind knob
|
|
312
|
+ 'stylesheet.calendar.header': {
|
|
313
|
+ week: {
|
|
314
|
+ marginTop: 0,
|
|
315
|
+ flexDirection: 'row',
|
|
316
|
+ justifyContent: 'space-between'
|
|
317
|
+ }
|
|
318
|
+ }
|
|
319
|
+ }}
|
|
320
|
+ />
|
86
|
321
|
</BaseContainer>
|
87
|
322
|
);
|
88
|
323
|
}
|
89
|
324
|
}
|
90
|
|
-
|