2019-11-07 11:46:01 +01:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import * as React from 'react';
|
2020-03-05 21:48:37 +01:00
|
|
|
import {MaterialCommunityIcons} from "@expo/vector-icons";
|
2019-11-07 11:46:01 +01:00
|
|
|
import {View} from "react-native";
|
|
|
|
import ThemeManager from "../utils/ThemeManager";
|
|
|
|
import HTML from "react-native-render-html";
|
|
|
|
import {LinearGradient} from "expo-linear-gradient";
|
2019-11-07 17:58:02 +01:00
|
|
|
import i18n from "i18n-js";
|
2020-03-06 23:15:01 +01:00
|
|
|
import {Avatar, Card, Text, Title} from 'react-native-paper';
|
2019-11-07 11:46:01 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
isAvailable: boolean,
|
|
|
|
icon: string,
|
|
|
|
color: string,
|
|
|
|
title: string,
|
|
|
|
subtitle: React.Node,
|
|
|
|
clickAction: Function,
|
|
|
|
isSquare: boolean,
|
|
|
|
isSquareLeft: boolean,
|
|
|
|
displayEvent: ?Object,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class DashboardItem extends React.Component<Props> {
|
|
|
|
static defaultProps = {
|
|
|
|
isSquare: false,
|
|
|
|
isSquareLeft: true,
|
|
|
|
displayEvent: undefined,
|
|
|
|
};
|
|
|
|
|
2020-02-11 01:05:24 +01:00
|
|
|
shouldComponentUpdate(nextProps: Props): boolean {
|
|
|
|
return nextProps.isAvailable !== this.props.isAvailable ||
|
|
|
|
nextProps.subtitle !== this.props.subtitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-07 11:46:01 +01:00
|
|
|
/**
|
|
|
|
* Convert the date string given by in the event list json to a date object
|
|
|
|
* @param dateString
|
|
|
|
* @return {Date}
|
|
|
|
*/
|
|
|
|
stringToDate(dateString: ?string): ?Date {
|
|
|
|
let date = new Date();
|
|
|
|
if (dateString === undefined || dateString === null)
|
|
|
|
date = undefined;
|
|
|
|
else if (dateString.split(' ').length > 1) {
|
|
|
|
let timeStr = dateString.split(' ')[1];
|
|
|
|
date.setHours(parseInt(timeStr.split(':')[0]), parseInt(timeStr.split(':')[1]), 0);
|
|
|
|
} else
|
|
|
|
date = undefined;
|
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
|
|
|
padStr(i: number) {
|
|
|
|
return (i < 10) ? "0" + i : "" + i;
|
|
|
|
}
|
|
|
|
|
|
|
|
getFormattedEventTime(event: Object): string {
|
|
|
|
let formattedStr = '';
|
|
|
|
let startDate = this.stringToDate(event['date_begin']);
|
|
|
|
let endDate = this.stringToDate(event['date_end']);
|
|
|
|
if (startDate !== undefined && startDate !== null && endDate !== undefined && endDate !== null)
|
|
|
|
formattedStr = this.padStr(startDate.getHours()) + ':' + this.padStr(startDate.getMinutes()) +
|
|
|
|
' - ' + this.padStr(endDate.getHours()) + ':' + this.padStr(endDate.getMinutes());
|
|
|
|
else if (startDate !== undefined && startDate !== null)
|
|
|
|
formattedStr = this.padStr(startDate.getHours()) + ':' + this.padStr(startDate.getMinutes());
|
|
|
|
return formattedStr
|
|
|
|
}
|
|
|
|
|
|
|
|
getEventPreviewContainer() {
|
|
|
|
if (this.props.displayEvent !== undefined && this.props.displayEvent !== null) {
|
2020-03-06 23:15:01 +01:00
|
|
|
const hasImage = this.props.displayEvent['logo'] !== '' && this.props.displayEvent['logo'] !== null;
|
2019-11-07 11:46:01 +01:00
|
|
|
return (
|
2020-03-06 23:15:01 +01:00
|
|
|
<Card style={{marginBottom: 10}}>
|
|
|
|
{hasImage ?
|
|
|
|
<Card.Title
|
|
|
|
title={this.props.displayEvent['title']}
|
|
|
|
subtitle={this.getFormattedEventTime(this.props.displayEvent)}
|
|
|
|
left={() =>
|
|
|
|
<Avatar.Image
|
|
|
|
source={{uri: this.props.displayEvent['logo']}}
|
|
|
|
size={60}
|
|
|
|
style={{backgroundColor: 'transparent'}}/>
|
|
|
|
}
|
|
|
|
/> :
|
|
|
|
<Card.Title
|
|
|
|
title={this.props.displayEvent['title']}
|
|
|
|
subtitle={this.getFormattedEventTime(this.props.displayEvent)}
|
|
|
|
/>}
|
|
|
|
<View>
|
|
|
|
<Card.Content style={{
|
|
|
|
height: this.props.displayEvent['description'].length > 70 ? 100 : 50,
|
2019-11-07 11:46:01 +01:00
|
|
|
overflow: 'hidden',
|
|
|
|
}}>
|
|
|
|
<HTML html={"<div>" + this.props.displayEvent['description'] + "</div>"}
|
|
|
|
tagsStyles={{
|
|
|
|
p: {
|
2020-03-06 23:15:01 +01:00
|
|
|
color: ThemeManager.getCurrentThemeVariables().text,
|
2019-11-07 11:46:01 +01:00
|
|
|
},
|
2020-03-06 23:15:01 +01:00
|
|
|
div: {color: ThemeManager.getCurrentThemeVariables().text},
|
2019-11-07 11:46:01 +01:00
|
|
|
}}/>
|
2020-03-06 23:15:01 +01:00
|
|
|
|
|
|
|
</Card.Content>
|
|
|
|
<LinearGradient
|
|
|
|
colors={[
|
|
|
|
// Fix for ios gradient: transparent color must match final color
|
|
|
|
ThemeManager.getNightMode() ? 'rgba(42,42,42,0)' : 'rgba(255,255,255,0)',
|
|
|
|
ThemeManager.getCurrentThemeVariables().card
|
|
|
|
]}
|
|
|
|
start={{x: 0, y: 0}}
|
|
|
|
end={{x: 0, y: 0.6}}
|
|
|
|
// end={[0, 0.6]}
|
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
|
|
|
width: '100%',
|
|
|
|
height: 65,
|
|
|
|
bottom: -5,
|
|
|
|
}}>
|
|
|
|
<View style={{
|
|
|
|
marginLeft: 'auto',
|
|
|
|
marginTop: 'auto',
|
|
|
|
flexDirection: 'row'
|
|
|
|
}}>
|
|
|
|
<Text style={{
|
2019-11-07 11:46:01 +01:00
|
|
|
marginTop: 'auto',
|
2020-03-06 23:15:01 +01:00
|
|
|
marginBottom: 'auto',
|
|
|
|
padding: 0,
|
2019-11-07 11:46:01 +01:00
|
|
|
}}>
|
2020-03-06 23:15:01 +01:00
|
|
|
{i18n.t("homeScreen.dashboard.seeMore")}
|
|
|
|
</Text>
|
|
|
|
<MaterialCommunityIcons
|
|
|
|
name={'chevron-right'}
|
|
|
|
size={26}
|
|
|
|
color={ThemeManager.getCurrentThemeVariables().text}/>
|
|
|
|
</View>
|
|
|
|
</LinearGradient>
|
|
|
|
</View>
|
|
|
|
</Card>
|
2019-11-07 11:46:01 +01:00
|
|
|
);
|
|
|
|
} else
|
|
|
|
return <View/>
|
|
|
|
}
|
|
|
|
|
|
|
|
getIcon() {
|
|
|
|
return (
|
2020-03-05 21:48:37 +01:00
|
|
|
<MaterialCommunityIcons
|
|
|
|
name={this.props.icon}
|
2019-11-07 11:46:01 +01:00
|
|
|
color={
|
|
|
|
this.props.isAvailable ?
|
|
|
|
this.props.color :
|
2020-03-06 23:15:01 +01:00
|
|
|
ThemeManager.getCurrentThemeVariables().textDisabled
|
2019-11-07 11:46:01 +01:00
|
|
|
}
|
2020-03-05 21:48:37 +01:00
|
|
|
size={this.props.isSquare ? 50 : 40}/>
|
2019-11-07 11:46:01 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getText() {
|
|
|
|
return (
|
|
|
|
<View style={{
|
|
|
|
width: this.props.isSquare ? '100%' : 'auto',
|
|
|
|
}}>
|
2020-03-06 23:15:01 +01:00
|
|
|
<Title style={{
|
2019-11-07 11:46:01 +01:00
|
|
|
color: this.props.isAvailable ?
|
2020-03-06 23:15:01 +01:00
|
|
|
ThemeManager.getCurrentThemeVariables().text :
|
|
|
|
ThemeManager.getCurrentThemeVariables().textDisabled,
|
2019-11-07 11:46:01 +01:00
|
|
|
textAlign: this.props.isSquare ? 'center' : 'left',
|
|
|
|
width: this.props.isSquare ? '100%' : 'auto',
|
|
|
|
}}>
|
|
|
|
{this.props.title}
|
2020-03-06 23:15:01 +01:00
|
|
|
</Title>
|
2019-11-07 11:46:01 +01:00
|
|
|
<Text style={{
|
|
|
|
color: this.props.isAvailable ?
|
2020-03-06 23:15:01 +01:00
|
|
|
ThemeManager.getCurrentThemeVariables().text :
|
|
|
|
ThemeManager.getCurrentThemeVariables().textDisabled,
|
2019-11-07 11:46:01 +01:00
|
|
|
textAlign: this.props.isSquare ? 'center' : 'left',
|
|
|
|
width: this.props.isSquare ? '100%' : 'auto',
|
|
|
|
}}>
|
|
|
|
{this.props.subtitle}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getContent() {
|
|
|
|
if (this.props.isSquare) {
|
|
|
|
return (
|
2020-03-06 23:15:01 +01:00
|
|
|
<View>
|
2019-11-07 11:46:01 +01:00
|
|
|
<View style={{marginLeft: 'auto', marginRight: 'auto'}}>
|
|
|
|
{this.getIcon()}
|
|
|
|
</View>
|
|
|
|
{this.getText()}
|
2020-03-06 23:15:01 +01:00
|
|
|
</View>
|
2019-11-07 11:46:01 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render() {
|
2020-02-11 01:05:24 +01:00
|
|
|
// console.log("rendering DashboardItem " + this.props.title);
|
2019-11-07 11:46:01 +01:00
|
|
|
let marginRight = 10;
|
|
|
|
if (this.props.isSquare) {
|
|
|
|
if (this.props.isSquareLeft)
|
|
|
|
marginRight = '4%';
|
|
|
|
else
|
|
|
|
marginRight = 0
|
|
|
|
}
|
2020-03-06 23:15:01 +01:00
|
|
|
const color = this.props.isAvailable ?
|
|
|
|
ThemeManager.getCurrentThemeVariables().text :
|
|
|
|
ThemeManager.getCurrentThemeVariables().textDisabled;
|
2019-11-07 11:46:01 +01:00
|
|
|
return (
|
2020-03-06 23:15:01 +01:00
|
|
|
<Card
|
|
|
|
style={{
|
|
|
|
width: this.props.isSquare ? '48%' : 'auto',
|
|
|
|
marginLeft: this.props.isSquare ? 0 : 10,
|
|
|
|
marginRight: marginRight,
|
|
|
|
marginTop: 10,
|
|
|
|
overflow: 'hidden',
|
|
|
|
}}
|
|
|
|
onPress={this.props.clickAction}>
|
|
|
|
{this.props.isSquare ?
|
|
|
|
<Card.Content>
|
|
|
|
{this.getContent()}
|
|
|
|
</Card.Content>
|
|
|
|
:
|
2019-11-07 11:46:01 +01:00
|
|
|
<View>
|
2020-03-06 23:15:01 +01:00
|
|
|
<Card.Title
|
|
|
|
title={this.props.title}
|
|
|
|
titleStyle={{color: color}}
|
|
|
|
subtitle={this.props.subtitle}
|
|
|
|
subtitleStyle={{color: color}}
|
|
|
|
left={(props) => <Avatar.Icon
|
|
|
|
{...props}
|
|
|
|
icon={this.props.icon}
|
|
|
|
color={this.props.isAvailable ? this.props.color : ThemeManager.getCurrentThemeVariables().textDisabled}
|
|
|
|
size={60}
|
|
|
|
style={{backgroundColor: 'transparent'}}/>}
|
|
|
|
/>
|
|
|
|
<Card.Content>
|
|
|
|
{this.getEventPreviewContainer()}
|
|
|
|
</Card.Content>
|
|
|
|
</View>}
|
2019-11-07 11:46:01 +01:00
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|