|
@@ -30,7 +30,6 @@ import type {ServiceItemType} from '../../managers/ServicesManager';
|
30
|
30
|
import {getDisplayEvent, getFutureEvents} from '../../utils/Home';
|
31
|
31
|
// import DATA from "../dashboard_data.json";
|
32
|
32
|
|
33
|
|
-const NAME_AMICALE = 'Amicale INSA Toulouse';
|
34
|
33
|
const DATA_URL =
|
35
|
34
|
'https://etud.insa-toulouse.fr/~amicale_app/v2/dashboard/dashboard_data.json';
|
36
|
35
|
const FEED_ITEM_HEIGHT = 500;
|
|
@@ -40,11 +39,14 @@ const SECTIONS_ID = ['dashboard', 'news_feed'];
|
40
|
39
|
const REFRESH_TIME = 1000 * 20; // Refresh every 20 seconds
|
41
|
40
|
|
42
|
41
|
export type FeedItemType = {
|
43
|
|
- full_picture: string,
|
44
|
|
- message: string,
|
45
|
|
- permalink_url: string,
|
46
|
|
- created_time: number,
|
47
|
42
|
id: string,
|
|
43
|
+ message: string,
|
|
44
|
+ url: string,
|
|
45
|
+ image: string | null,
|
|
46
|
+ video: string | null,
|
|
47
|
+ link: string | null,
|
|
48
|
+ time: number,
|
|
49
|
+ page_id: string,
|
48
|
50
|
};
|
49
|
51
|
|
50
|
52
|
export type EventType = {
|
|
@@ -68,10 +70,10 @@ export type FullDashboardType = {
|
68
|
70
|
available_tutorials: number,
|
69
|
71
|
};
|
70
|
72
|
|
|
73
|
+type RawNewsFeedType = {[key: string]: Array<FeedItemType>};
|
|
74
|
+
|
71
|
75
|
type RawDashboardType = {
|
72
|
|
- news_feed: {
|
73
|
|
- data: Array<FeedItemType>,
|
74
|
|
- },
|
|
76
|
+ news_feed: RawNewsFeedType,
|
75
|
77
|
dashboard: FullDashboardType,
|
76
|
78
|
};
|
77
|
79
|
|
|
@@ -89,6 +91,9 @@ type StateType = {
|
89
|
91
|
* Class defining the app's home screen
|
90
|
92
|
*/
|
91
|
93
|
class HomeScreen extends React.Component<PropsType, StateType> {
|
|
94
|
+ static sortFeedTime = (a: FeedItemType, b: FeedItemType): number =>
|
|
95
|
+ b.time - a.time;
|
|
96
|
+
|
92
|
97
|
isLoggedIn: boolean | null;
|
93
|
98
|
|
94
|
99
|
fabRef: {current: null | AnimatedFAB};
|
|
@@ -122,17 +127,6 @@ class HomeScreen extends React.Component<PropsType, StateType> {
|
122
|
127
|
}
|
123
|
128
|
|
124
|
129
|
/**
|
125
|
|
- * Converts a dateString using Unix Timestamp to a formatted date
|
126
|
|
- *
|
127
|
|
- * @param dateString {string} The Unix Timestamp representation of a date
|
128
|
|
- * @return {string} The formatted output date
|
129
|
|
- */
|
130
|
|
- static getFormattedDate(dateString: number): string {
|
131
|
|
- const date = new Date(dateString * 1000);
|
132
|
|
- return date.toLocaleString();
|
133
|
|
- }
|
134
|
|
-
|
135
|
|
- /**
|
136
|
130
|
* Updates login state and navigation parameters on screen focus
|
137
|
131
|
*/
|
138
|
132
|
onScreenFocus = () => {
|
|
@@ -285,8 +279,6 @@ class HomeScreen extends React.Component<PropsType, StateType> {
|
285
|
279
|
<FeedItem
|
286
|
280
|
navigation={props.navigation}
|
287
|
281
|
item={item}
|
288
|
|
- title={NAME_AMICALE}
|
289
|
|
- subtitle={HomeScreen.getFormattedDate(item.created_time)}
|
290
|
282
|
height={FEED_ITEM_HEIGHT}
|
291
|
283
|
/>
|
292
|
284
|
);
|
|
@@ -415,7 +407,7 @@ class HomeScreen extends React.Component<PropsType, StateType> {
|
415
|
407
|
// fetchedData = DATA;
|
416
|
408
|
if (fetchedData != null) {
|
417
|
409
|
if (fetchedData.news_feed != null)
|
418
|
|
- this.currentNewFeed = fetchedData.news_feed.data;
|
|
410
|
+ this.currentNewFeed = this.generateNewsFeed(fetchedData.news_feed);
|
419
|
411
|
if (fetchedData.dashboard != null)
|
420
|
412
|
this.currentDashboard = fetchedData.dashboard;
|
421
|
413
|
}
|
|
@@ -458,6 +450,16 @@ class HomeScreen extends React.Component<PropsType, StateType> {
|
458
|
450
|
});
|
459
|
451
|
};
|
460
|
452
|
|
|
453
|
+ generateNewsFeed(rawFeed: RawNewsFeedType): Array<FeedItemType> {
|
|
454
|
+ const finalFeed = [];
|
|
455
|
+ Object.keys(rawFeed).forEach((key: string) => {
|
|
456
|
+ const category: Array<FeedItemType> | null = rawFeed[key];
|
|
457
|
+ if (category != null && category.length > 0) finalFeed.push(...category);
|
|
458
|
+ });
|
|
459
|
+ finalFeed.sort(HomeScreen.sortFeedTime);
|
|
460
|
+ return finalFeed;
|
|
461
|
+ }
|
|
462
|
+
|
461
|
463
|
render(): React.Node {
|
462
|
464
|
const {props, state} = this;
|
463
|
465
|
return (
|