2019-06-29 13:37:21 +02:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import * as React from 'react';
|
2020-03-09 22:02:09 +01:00
|
|
|
import {View} from 'react-native';
|
2019-06-25 22:20:24 +02:00
|
|
|
import i18n from "i18n-js";
|
2020-03-09 19:00:12 +01:00
|
|
|
import DashboardItem from "../components/EventDashboardItem";
|
2020-03-05 19:54:56 +01:00
|
|
|
import WebSectionList from "../components/WebSectionList";
|
2020-03-09 23:15:13 +01:00
|
|
|
import {Text, withTheme} from 'react-native-paper';
|
2020-03-07 11:49:32 +01:00
|
|
|
import FeedItem from "../components/FeedItem";
|
|
|
|
import SquareDashboardItem from "../components/SquareDashboardItem";
|
2020-03-09 19:00:12 +01:00
|
|
|
import PreviewEventDashboardItem from "../components/PreviewEventDashboardItem";
|
2020-03-30 15:28:08 +02:00
|
|
|
import {stringToDate} from "../utils/Planning";
|
2020-03-30 17:39:59 +02:00
|
|
|
import {openBrowser} from "../utils/WebBrowser";
|
2019-11-07 17:58:02 +01:00
|
|
|
// import DATA from "../dashboard_data.json";
|
2019-10-08 19:16:42 +02:00
|
|
|
|
2019-07-25 17:52:16 +02:00
|
|
|
|
2019-07-26 14:14:01 +02:00
|
|
|
const NAME_AMICALE = 'Amicale INSA Toulouse';
|
2020-02-23 17:21:34 +01:00
|
|
|
const DATA_URL = "https://etud.insa-toulouse.fr/~amicale_app/dashboard/dashboard_data.json";
|
2019-10-06 10:54:01 +02:00
|
|
|
|
|
|
|
const SECTIONS_ID = [
|
|
|
|
'dashboard',
|
|
|
|
'news_feed'
|
|
|
|
];
|
2019-07-28 12:40:35 +02:00
|
|
|
|
2019-10-16 16:57:37 +02:00
|
|
|
const REFRESH_TIME = 1000 * 20; // Refresh every 20 seconds
|
2019-10-09 19:58:22 +02:00
|
|
|
|
2020-03-05 19:54:56 +01:00
|
|
|
type Props = {
|
|
|
|
navigation: Object,
|
2020-03-09 23:15:13 +01:00
|
|
|
theme: Object,
|
2019-07-25 17:52:16 +02:00
|
|
|
}
|
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
|
|
|
* Class defining the app's home screen
|
|
|
|
*/
|
2020-03-09 23:15:13 +01:00
|
|
|
class HomeScreen extends React.Component<Props> {
|
2019-07-25 17:52:16 +02:00
|
|
|
|
2020-02-23 18:15:30 +01:00
|
|
|
onProxiwashClick: Function;
|
|
|
|
onTutorInsaClick: Function;
|
|
|
|
onMenuClick: Function;
|
|
|
|
onProximoClick: Function;
|
2020-03-05 19:54:56 +01:00
|
|
|
getRenderItem: Function;
|
|
|
|
createDataset: Function;
|
2020-02-23 18:15:30 +01:00
|
|
|
|
2020-03-14 15:58:57 +01:00
|
|
|
colors: Object;
|
2020-03-09 23:15:13 +01:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2020-02-23 18:15:30 +01:00
|
|
|
this.onProxiwashClick = this.onProxiwashClick.bind(this);
|
|
|
|
this.onTutorInsaClick = this.onTutorInsaClick.bind(this);
|
|
|
|
this.onMenuClick = this.onMenuClick.bind(this);
|
|
|
|
this.onProximoClick = this.onProximoClick.bind(this);
|
2020-03-05 19:54:56 +01:00
|
|
|
this.getRenderItem = this.getRenderItem.bind(this);
|
|
|
|
this.createDataset = this.createDataset.bind(this);
|
2020-03-09 23:15:13 +01:00
|
|
|
this.colors = props.theme.colors;
|
2020-03-05 19:54:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a dateString using Unix Timestamp to a formatted date
|
2020-03-29 15:59:25 +02:00
|
|
|
*
|
2020-03-05 19:54:56 +01:00
|
|
|
* @param dateString {string} The Unix Timestamp representation of a date
|
|
|
|
* @return {string} The formatted output date
|
|
|
|
*/
|
|
|
|
static getFormattedDate(dateString: string) {
|
|
|
|
let date = new Date(Number.parseInt(dateString) * 1000);
|
|
|
|
return date.toLocaleString();
|
2020-02-23 18:15:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onProxiwashClick() {
|
|
|
|
this.props.navigation.navigate('Proxiwash');
|
|
|
|
}
|
|
|
|
|
|
|
|
onTutorInsaClick() {
|
2020-03-30 17:39:59 +02:00
|
|
|
openBrowser("https://www.etud.insa-toulouse.fr/~tutorinsa/", this.colors.primary);
|
2020-02-23 18:15:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onProximoClick() {
|
|
|
|
this.props.navigation.navigate('Proximo');
|
|
|
|
}
|
|
|
|
|
|
|
|
onMenuClick() {
|
|
|
|
this.props.navigation.navigate('SelfMenuScreen');
|
2019-07-30 20:40:17 +02:00
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Extract a key for the given item
|
|
|
|
*
|
|
|
|
* @param item The item to extract the key from
|
|
|
|
* @return {*} The extracted key
|
|
|
|
*/
|
2019-07-30 13:59:28 +02:00
|
|
|
getKeyExtractor(item: Object) {
|
2019-07-28 12:40:35 +02:00
|
|
|
return item !== undefined ? item.id : undefined;
|
2019-07-25 17:52:16 +02:00
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Creates the dataset to be used in the FlatList
|
|
|
|
*
|
|
|
|
* @param fetchedData
|
|
|
|
* @return {*}
|
|
|
|
*/
|
2019-07-30 13:59:28 +02:00
|
|
|
createDataset(fetchedData: Object) {
|
2019-11-07 17:58:02 +01:00
|
|
|
// fetchedData = DATA;
|
2019-10-06 10:54:01 +02:00
|
|
|
let newsData = [];
|
|
|
|
let dashboardData = [];
|
|
|
|
if (fetchedData['news_feed'] !== undefined)
|
|
|
|
newsData = fetchedData['news_feed']['data'];
|
|
|
|
if (fetchedData['dashboard'] !== undefined)
|
|
|
|
dashboardData = this.generateDashboardDataset(fetchedData['dashboard']);
|
2019-07-26 14:14:01 +02:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
title: '',
|
2019-10-06 10:54:01 +02:00
|
|
|
data: dashboardData,
|
|
|
|
extraData: super.state,
|
|
|
|
keyExtractor: this.getKeyExtractor,
|
|
|
|
id: SECTIONS_ID[0]
|
|
|
|
},
|
|
|
|
{
|
2019-10-06 12:30:29 +02:00
|
|
|
title: i18n.t('homeScreen.newsFeed'),
|
2019-10-06 10:54:01 +02:00
|
|
|
data: newsData,
|
2019-07-31 14:22:36 +02:00
|
|
|
extraData: super.state,
|
2019-10-06 10:54:01 +02:00
|
|
|
keyExtractor: this.getKeyExtractor,
|
|
|
|
id: SECTIONS_ID[1]
|
2019-07-25 17:52:16 +02:00
|
|
|
}
|
2019-07-26 14:14:01 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Generates the dataset associated to the dashboard to be displayed in the FlatList as a section
|
|
|
|
*
|
|
|
|
* @param dashboardData
|
|
|
|
* @return {*}
|
|
|
|
*/
|
2019-10-06 10:54:01 +02:00
|
|
|
generateDashboardDataset(dashboardData: Object) {
|
2019-10-08 19:16:42 +02:00
|
|
|
let dataset = [
|
2020-03-09 22:02:09 +01:00
|
|
|
|
2019-10-08 19:16:42 +02:00
|
|
|
{
|
|
|
|
id: 'middle',
|
2020-03-09 22:02:09 +01:00
|
|
|
content: []
|
2019-10-08 19:16:42 +02:00
|
|
|
},
|
|
|
|
{
|
2020-03-09 22:02:09 +01:00
|
|
|
id: 'event',
|
|
|
|
content: undefined
|
2019-10-08 19:16:42 +02:00
|
|
|
},
|
|
|
|
];
|
2019-10-06 10:54:01 +02:00
|
|
|
for (let [key, value] of Object.entries(dashboardData)) {
|
2019-10-08 19:16:42 +02:00
|
|
|
switch (key) {
|
|
|
|
case 'today_events':
|
2020-03-09 22:02:09 +01:00
|
|
|
dataset[1]['content'] = value;
|
2019-10-08 19:16:42 +02:00
|
|
|
break;
|
2019-11-07 17:36:20 +01:00
|
|
|
case 'available_machines':
|
2020-03-09 22:02:09 +01:00
|
|
|
dataset[0]['content'][0] = {id: key, data: value};
|
2019-10-08 19:16:42 +02:00
|
|
|
break;
|
2019-11-07 17:36:20 +01:00
|
|
|
case 'available_tutorials':
|
2020-03-09 22:02:09 +01:00
|
|
|
dataset[0]['content'][1] = {id: key, data: value};
|
2019-10-08 19:16:42 +02:00
|
|
|
break;
|
2019-11-07 17:36:20 +01:00
|
|
|
case 'proximo_articles':
|
2020-03-09 22:02:09 +01:00
|
|
|
dataset[0]['content'][2] = {id: key, data: value};
|
2019-10-08 19:16:42 +02:00
|
|
|
break;
|
2019-11-07 17:36:20 +01:00
|
|
|
case 'today_menu':
|
2020-03-09 22:02:09 +01:00
|
|
|
dataset[0]['content'][3] = {id: key, data: value};
|
2019-11-07 17:36:20 +01:00
|
|
|
break;
|
|
|
|
|
2019-10-08 19:16:42 +02:00
|
|
|
}
|
2019-10-06 10:54:01 +02:00
|
|
|
}
|
|
|
|
return dataset
|
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Gets a dashboard item
|
|
|
|
*
|
|
|
|
* @param item The item to display
|
|
|
|
* @return {*}
|
|
|
|
*/
|
2019-10-08 19:16:42 +02:00
|
|
|
getDashboardItem(item: Object) {
|
|
|
|
let content = item['content'];
|
2019-11-07 17:36:20 +01:00
|
|
|
if (item['id'] === 'event')
|
2019-11-07 11:46:01 +01:00
|
|
|
return this.getDashboardEventItem(content);
|
2019-10-08 19:16:42 +02:00
|
|
|
else if (item['id'] === 'middle')
|
|
|
|
return this.getDashboardMiddleItem(content);
|
|
|
|
}
|
|
|
|
|
2019-10-09 19:58:22 +02:00
|
|
|
/**
|
2020-03-29 15:59:25 +02:00
|
|
|
* Gets the time limit depending on the current day:
|
2019-10-09 19:58:22 +02:00
|
|
|
* 17:30 for every day of the week except for thursday 11:30
|
|
|
|
* 00:00 on weekends
|
|
|
|
*/
|
|
|
|
getTodayEventTimeLimit() {
|
|
|
|
let now = new Date();
|
|
|
|
if (now.getDay() === 4) // Thursday
|
|
|
|
now.setHours(11, 30, 0);
|
|
|
|
else if (now.getDay() === 6 || now.getDay() === 0) // Weekend
|
|
|
|
now.setHours(0, 0, 0);
|
|
|
|
else
|
|
|
|
now.setHours(17, 30, 0);
|
|
|
|
return now;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-29 15:59:25 +02:00
|
|
|
* Gets the duration (in milliseconds) of an event
|
|
|
|
*
|
2019-10-09 19:58:22 +02:00
|
|
|
* @param event {Object}
|
|
|
|
* @return {number} The number of milliseconds
|
|
|
|
*/
|
|
|
|
getEventDuration(event: Object): number {
|
2020-03-30 15:28:08 +02:00
|
|
|
let start = stringToDate(event['date_begin']);
|
|
|
|
let end = stringToDate(event['date_end']);
|
2019-10-09 19:58:22 +02:00
|
|
|
let duration = 0;
|
|
|
|
if (start !== undefined && start !== null && end !== undefined && end !== null)
|
|
|
|
duration = end - start;
|
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-29 15:59:25 +02:00
|
|
|
* Gets events starting after the limit
|
2019-10-09 19:58:22 +02:00
|
|
|
*
|
|
|
|
* @param events
|
|
|
|
* @param limit
|
|
|
|
* @return {Array<Object>}
|
|
|
|
*/
|
|
|
|
getEventsAfterLimit(events: Object, limit: Date): Array<Object> {
|
|
|
|
let validEvents = [];
|
|
|
|
for (let event of events) {
|
2020-03-30 15:28:08 +02:00
|
|
|
let startDate = stringToDate(event['date_begin']);
|
2019-10-09 19:58:22 +02:00
|
|
|
if (startDate !== undefined && startDate !== null && startDate >= limit) {
|
|
|
|
validEvents.push(event);
|
2019-10-08 19:16:42 +02:00
|
|
|
}
|
|
|
|
}
|
2019-10-09 19:58:22 +02:00
|
|
|
return validEvents;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-29 15:59:25 +02:00
|
|
|
* Gets the event with the longest duration in the given array.
|
2019-10-09 19:58:22 +02:00
|
|
|
* If all events have the same duration, return the first in the array.
|
2020-03-29 15:59:25 +02:00
|
|
|
*
|
2019-10-09 19:58:22 +02:00
|
|
|
* @param events
|
|
|
|
*/
|
|
|
|
getLongestEvent(events: Array<Object>): Object {
|
|
|
|
let longestEvent = events[0];
|
|
|
|
let longestTime = 0;
|
|
|
|
for (let event of events) {
|
|
|
|
let time = this.getEventDuration(event);
|
|
|
|
if (time > longestTime) {
|
|
|
|
longestTime = time;
|
|
|
|
longestEvent = event;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return longestEvent;
|
2019-10-08 19:16:42 +02:00
|
|
|
}
|
|
|
|
|
2019-10-09 19:58:22 +02:00
|
|
|
/**
|
2020-03-29 15:59:25 +02:00
|
|
|
* Gets events that have not yet ended/started
|
2019-10-09 19:58:22 +02:00
|
|
|
*
|
|
|
|
* @param events
|
|
|
|
*/
|
|
|
|
getFutureEvents(events: Array<Object>): Array<Object> {
|
|
|
|
let validEvents = [];
|
|
|
|
let now = new Date();
|
|
|
|
for (let event of events) {
|
2020-03-30 15:28:08 +02:00
|
|
|
let startDate = stringToDate(event['date_begin']);
|
|
|
|
let endDate = stringToDate(event['date_end']);
|
2019-10-09 19:58:22 +02:00
|
|
|
if (startDate !== undefined && startDate !== null) {
|
|
|
|
if (startDate > now)
|
|
|
|
validEvents.push(event);
|
|
|
|
else if (endDate !== undefined && endDate !== null) {
|
2019-10-09 20:03:33 +02:00
|
|
|
if (endDate > now || endDate < startDate) // Display event if it ends the following day
|
2019-10-09 19:58:22 +02:00
|
|
|
validEvents.push(event);
|
|
|
|
}
|
|
|
|
}
|
2019-10-06 10:54:01 +02:00
|
|
|
}
|
2019-10-09 19:58:22 +02:00
|
|
|
return validEvents;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-29 15:59:25 +02:00
|
|
|
* Gets the event to display in the preview
|
2019-10-09 19:58:22 +02:00
|
|
|
*
|
|
|
|
* @param events
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
getDisplayEvent(events: Array<Object>): Object {
|
|
|
|
let displayEvent = undefined;
|
|
|
|
if (events.length > 1) {
|
|
|
|
let eventsAfterLimit = this.getEventsAfterLimit(events, this.getTodayEventTimeLimit());
|
|
|
|
if (eventsAfterLimit.length > 0) {
|
|
|
|
if (eventsAfterLimit.length === 1)
|
|
|
|
displayEvent = eventsAfterLimit[0];
|
|
|
|
else
|
|
|
|
displayEvent = this.getLongestEvent(events);
|
|
|
|
} else {
|
|
|
|
displayEvent = this.getLongestEvent(events);
|
|
|
|
}
|
|
|
|
} else if (events.length === 1) {
|
|
|
|
displayEvent = events[0];
|
2019-10-06 10:54:01 +02:00
|
|
|
}
|
2019-10-09 19:58:22 +02:00
|
|
|
return displayEvent;
|
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Gets the event render item.
|
|
|
|
* If a preview is available, it will be rendered inside
|
|
|
|
*
|
|
|
|
* @param content
|
|
|
|
* @return {*}
|
|
|
|
*/
|
2019-11-07 11:46:01 +01:00
|
|
|
getDashboardEventItem(content: Array<Object>) {
|
2019-10-08 19:16:42 +02:00
|
|
|
let icon = 'calendar-range';
|
|
|
|
let title = i18n.t('homeScreen.dashboard.todayEventsTitle');
|
2020-01-31 16:51:43 +01:00
|
|
|
let subtitle;
|
2019-10-09 19:58:22 +02:00
|
|
|
let futureEvents = this.getFutureEvents(content);
|
2019-11-01 06:49:57 +01:00
|
|
|
let isAvailable = futureEvents.length > 0;
|
2019-10-08 19:16:42 +02:00
|
|
|
if (isAvailable) {
|
|
|
|
subtitle =
|
|
|
|
<Text>
|
2019-10-09 19:58:22 +02:00
|
|
|
<Text style={{fontWeight: "bold"}}>{futureEvents.length}</Text>
|
|
|
|
<Text>
|
|
|
|
{
|
|
|
|
futureEvents.length > 1 ?
|
|
|
|
i18n.t('homeScreen.dashboard.todayEventsSubtitlePlural') :
|
|
|
|
i18n.t('homeScreen.dashboard.todayEventsSubtitle')
|
|
|
|
}
|
|
|
|
</Text>
|
2019-10-08 19:16:42 +02:00
|
|
|
</Text>;
|
|
|
|
} else
|
|
|
|
subtitle = i18n.t('homeScreen.dashboard.todayEventsSubtitleNA');
|
|
|
|
|
2019-10-09 19:58:22 +02:00
|
|
|
let displayEvent = this.getDisplayEvent(futureEvents);
|
2020-03-09 19:00:12 +01:00
|
|
|
const clickContainerAction = () => this.props.navigation.navigate('Planning');
|
2020-03-09 22:02:09 +01:00
|
|
|
const clickPreviewAction = () => this.props.navigation.navigate('PlanningDisplayScreen', {data: displayEvent});
|
|
|
|
|
2019-10-08 19:16:42 +02:00
|
|
|
return (
|
2019-11-07 11:46:01 +01:00
|
|
|
<DashboardItem
|
2020-03-09 19:00:12 +01:00
|
|
|
{...this.props}
|
2019-11-07 11:46:01 +01:00
|
|
|
subtitle={subtitle}
|
|
|
|
icon={icon}
|
2020-03-09 19:00:12 +01:00
|
|
|
clickAction={clickContainerAction}
|
2019-11-07 11:46:01 +01:00
|
|
|
title={title}
|
|
|
|
isAvailable={isAvailable}
|
2020-03-09 19:00:12 +01:00
|
|
|
>
|
|
|
|
<PreviewEventDashboardItem
|
|
|
|
{...this.props}
|
|
|
|
event={displayEvent}
|
|
|
|
clickAction={clickPreviewAction}
|
|
|
|
/>
|
|
|
|
</DashboardItem>
|
2019-10-08 19:16:42 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Gets a classic dashboard item.
|
|
|
|
*
|
|
|
|
* @param content
|
|
|
|
* @return {*}
|
|
|
|
*/
|
2019-11-07 17:36:20 +01:00
|
|
|
getDashboardMiddleItem(content: Array<Object>) {
|
|
|
|
let proxiwashData = content[0]['data'];
|
|
|
|
let tutorinsaData = content[1]['data'];
|
2020-03-09 22:02:09 +01:00
|
|
|
let proximoData = content[2]['data'];
|
|
|
|
let menuData = content[3]['data'];
|
2019-10-08 19:16:42 +02:00
|
|
|
return (
|
2019-11-07 17:36:20 +01:00
|
|
|
<View style={{
|
2020-03-09 22:02:09 +01:00
|
|
|
flex: 1,
|
2019-11-07 17:36:20 +01:00
|
|
|
flexDirection: 'row',
|
2020-03-09 22:02:09 +01:00
|
|
|
justifyContent: 'center',
|
|
|
|
flexWrap: 'wrap',
|
|
|
|
margin: 10,
|
2019-11-07 17:36:20 +01:00
|
|
|
}}>
|
2020-03-07 11:49:32 +01:00
|
|
|
<SquareDashboardItem
|
2020-03-09 23:15:13 +01:00
|
|
|
color={this.colors.proxiwashColor}
|
2020-03-09 22:02:09 +01:00
|
|
|
icon={'washing-machine'}
|
|
|
|
clickAction={this.onProxiwashClick}
|
|
|
|
isAvailable={parseInt(proxiwashData['washers']) > 0}
|
|
|
|
badgeNumber={proxiwashData['washers']}
|
|
|
|
/>
|
|
|
|
<SquareDashboardItem
|
2020-03-09 23:15:13 +01:00
|
|
|
color={this.colors.proxiwashColor}
|
2020-03-09 22:02:09 +01:00
|
|
|
icon={'tumble-dryer'}
|
2020-02-23 18:15:30 +01:00
|
|
|
clickAction={this.onProxiwashClick}
|
2020-03-09 22:02:09 +01:00
|
|
|
isAvailable={parseInt(proxiwashData['dryers']) > 0}
|
|
|
|
badgeNumber={proxiwashData['dryers']}
|
|
|
|
/>
|
2020-03-07 11:49:32 +01:00
|
|
|
<SquareDashboardItem
|
2020-03-09 23:15:13 +01:00
|
|
|
color={this.colors.tutorinsaColor}
|
2020-03-09 22:02:09 +01:00
|
|
|
icon={'school'}
|
2020-02-23 18:15:30 +01:00
|
|
|
clickAction={this.onTutorInsaClick}
|
2020-03-09 22:02:09 +01:00
|
|
|
isAvailable={tutorinsaData > 0}
|
|
|
|
badgeNumber={tutorinsaData}
|
|
|
|
/>
|
|
|
|
<SquareDashboardItem
|
2020-03-09 23:15:13 +01:00
|
|
|
color={this.colors.proximoColor}
|
2020-03-09 22:02:09 +01:00
|
|
|
icon={'shopping'}
|
|
|
|
clickAction={this.onProximoClick}
|
|
|
|
isAvailable={parseInt(proximoData) > 0}
|
|
|
|
badgeNumber={parseInt(proximoData)}
|
|
|
|
/>
|
|
|
|
<SquareDashboardItem
|
2020-03-09 23:15:13 +01:00
|
|
|
color={this.colors.menuColor}
|
2020-03-09 22:02:09 +01:00
|
|
|
icon={'silverware-fork-knife'}
|
|
|
|
clickAction={this.onMenuClick}
|
|
|
|
isAvailable={menuData.length > 0}
|
|
|
|
badgeNumber={0}
|
|
|
|
/>
|
2019-11-07 17:36:20 +01:00
|
|
|
</View>
|
2019-10-08 19:16:42 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-05 19:54:56 +01:00
|
|
|
openLink(link: string) {
|
2020-03-30 17:39:59 +02:00
|
|
|
openBrowser(link, this.colors.primary);
|
2020-03-05 19:54:56 +01:00
|
|
|
}
|
2019-10-08 19:16:42 +02:00
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Gets a render item for the given feed object
|
|
|
|
*
|
|
|
|
* @param item The feed item to display
|
|
|
|
* @return {*}
|
|
|
|
*/
|
2020-03-05 19:54:56 +01:00
|
|
|
getFeedItem(item: Object) {
|
|
|
|
const onImagePress = this.openLink.bind(this, item.full_picture);
|
|
|
|
const onOutLinkPress = this.openLink.bind(this, item.permalink_url);
|
2020-01-31 16:51:43 +01:00
|
|
|
return (
|
2020-03-07 11:49:32 +01:00
|
|
|
<FeedItem
|
|
|
|
title={NAME_AMICALE}
|
|
|
|
subtitle={HomeScreen.getFormattedDate(item.created_time)}
|
|
|
|
full_picture={item.full_picture}
|
|
|
|
message={item.message}
|
|
|
|
onImagePress={onImagePress}
|
|
|
|
onOutLinkPress={onOutLinkPress}
|
|
|
|
/>
|
2020-03-05 19:54:56 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Gets a FlatList render item
|
|
|
|
*
|
|
|
|
* @param item The item to display
|
|
|
|
* @param section The current section
|
|
|
|
* @return {*}
|
|
|
|
*/
|
2020-03-05 19:54:56 +01:00
|
|
|
getRenderItem({item, section}: Object) {
|
|
|
|
return (section['id'] === SECTIONS_ID[0] ?
|
|
|
|
this.getDashboardItem(item) : this.getFeedItem(item));
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const nav = this.props.navigation;
|
|
|
|
return (
|
2020-03-06 09:12:56 +01:00
|
|
|
<WebSectionList
|
|
|
|
createDataset={this.createDataset}
|
2020-03-05 19:54:56 +01:00
|
|
|
navigation={nav}
|
2020-03-08 15:50:34 +01:00
|
|
|
autoRefreshTime={REFRESH_TIME}
|
|
|
|
refreshOnFocus={true}
|
2020-03-06 09:12:56 +01:00
|
|
|
fetchUrl={DATA_URL}
|
2020-03-07 09:15:25 +01:00
|
|
|
renderItem={this.getRenderItem}/>
|
2020-01-31 16:51:43 +01:00
|
|
|
);
|
2019-07-25 17:52:16 +02:00
|
|
|
}
|
2019-06-25 22:20:24 +02:00
|
|
|
}
|
2020-03-09 23:15:13 +01:00
|
|
|
|
|
|
|
export default withTheme(HomeScreen);
|