application-amicale/components/PreviewEventDashboardItem.js

86 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-03-09 19:00:12 +01:00
// @flow
import * as React from 'react';
2020-03-29 14:46:44 +02:00
import {StyleSheet, View} from "react-native";
2020-03-09 19:00:12 +01:00
import HTML from "react-native-render-html";
import i18n from "i18n-js";
import {Avatar, Button, Card, withTheme} from 'react-native-paper';
2020-03-30 15:28:08 +02:00
import {getFormattedEventTime, isDescriptionEmpty} from "../utils/Planning";
2020-03-09 19:00:12 +01:00
2020-03-29 14:46:44 +02:00
/**
* Component used to display an event preview if an event is available
*
* @param props Props to pass to the component
* @return {*}
*/
2020-03-09 19:00:12 +01:00
function PreviewEventDashboardItem(props) {
const {colors} = props.theme;
2020-03-29 14:46:44 +02:00
const isEmpty = props.event === undefined
? true
2020-03-30 15:28:08 +02:00
: isDescriptionEmpty(props.event['description']);
2020-03-29 14:46:44 +02:00
2020-03-09 19:00:12 +01:00
if (props.event !== undefined && props.event !== null) {
const hasImage = props.event['logo'] !== '' && props.event['logo'] !== null;
const getImage = () => <Avatar.Image
source={{uri: props.event['logo']}}
size={50}
2020-03-29 14:46:44 +02:00
style={styles.avatar}/>;
2020-03-09 19:00:12 +01:00
return (
<Card
2020-03-29 14:46:44 +02:00
style={styles.card}
2020-03-09 19:00:12 +01:00
onPress={props.clickAction}
elevation={3}
>
{hasImage ?
<Card.Title
title={props.event['title']}
2020-03-30 15:28:08 +02:00
subtitle={getFormattedEventTime(props.event['date_begin'], props.event['date_end'])}
2020-03-09 19:00:12 +01:00
left={getImage}
/> :
<Card.Title
title={props.event['title']}
2020-03-30 15:28:08 +02:00
subtitle={getFormattedEventTime(props.event['date_begin'], props.event['date_end'])}
2020-03-09 19:00:12 +01:00
/>}
{!isEmpty ?
2020-03-29 14:46:44 +02:00
<Card.Content style={styles.content}>
<HTML html={"<div>" + props.event['description'] + "</div>"}
tagsStyles={{
p: {color: colors.text,},
div: {color: colors.text},
}}/>
</Card.Content> : null}
2020-03-09 19:00:12 +01:00
2020-03-29 14:46:44 +02:00
<Card.Actions style={styles.actions}>
<Button
2020-03-09 19:00:12 +01:00
icon={'chevron-right'}
>
{i18n.t("homeScreen.dashboard.seeMore")}
</Button>
</Card.Actions>
2020-03-09 19:00:12 +01:00
</Card>
);
} else
return <View/>
}
2020-03-29 14:46:44 +02:00
const styles = StyleSheet.create({
card: {
marginBottom: 10
},
content: {
maxHeight: 150,
overflow: 'hidden',
},
actions: {
marginLeft: 'auto',
marginTop: 'auto',
flexDirection: 'row'
},
avatar: {
backgroundColor: 'transparent'
}
});
2020-03-09 19:00:12 +01:00
export default withTheme(PreviewEventDashboardItem);