application-amicale/screens/Amicale/Clubs/ClubDisplayScreen.js

137 lines
4.4 KiB
JavaScript
Raw Normal View History

2020-04-02 19:19:30 +02:00
// @flow
import * as React from 'react';
import {ScrollView, View} from 'react-native';
2020-04-02 19:19:30 +02:00
import HTML from "react-native-render-html";
import {Linking} from "expo";
import {Avatar, Card, Chip, Paragraph, withTheme} from 'react-native-paper';
import ImageModal from 'react-native-image-modal';
2020-04-02 20:01:56 +02:00
import i18n from "i18n-js";
2020-04-02 19:19:30 +02:00
type Props = {
navigation: Object,
route: Object
};
type State = {
imageModalVisible: boolean,
};
function openWebLink(event, link) {
Linking.openURL(link).catch((err) => console.error('Error opening link', err));
}
/**
* Class defining a planning event information page.
*/
class ClubDisplayScreen extends React.Component<Props, State> {
displayData = this.props.route.params['data'];
categories = this.props.route.params['categories'];
2020-04-02 19:19:30 +02:00
colors: Object;
state = {
imageModalVisible: false,
};
constructor(props) {
super(props);
this.colors = props.theme.colors;
}
componentDidMount(): * {
this.props.navigation.setOptions({title: this.displayData.name})
}
getCategoryName(id: number) {
for (let i = 0; i < this.categories.length; i++) {
if (id === this.categories[i].id)
return this.categories[i].name;
}
return "";
}
2020-04-04 11:55:51 +02:00
getCategoriesRender(categories: Array<number | null>) {
let final = [];
for (let i = 0; i < categories.length; i++) {
2020-04-04 11:55:51 +02:00
if (categories[i] !== null) {
final.push(
<Chip
style={{marginRight: 5}}
key={i.toString()}>
{this.getCategoryName(categories[i])}
</Chip>
);
}
}
return <View style={{flexDirection: 'row', marginTop: 5}}>{final}</View>;
}
2020-04-04 11:55:51 +02:00
getManagersRender(resp: Array<string>) {
2020-04-02 19:19:30 +02:00
let final = [];
for (let i = 0; i < resp.length; i++) {
2020-04-04 11:55:51 +02:00
final.push(<Paragraph key={i.toString()}>{resp[i]}</Paragraph>)
2020-04-02 19:19:30 +02:00
}
2020-04-03 14:42:43 +02:00
const hasManagers = resp.length > 0;
2020-04-02 19:19:30 +02:00
return (
<Card style={{marginTop: 10, marginBottom: 10}}>
<Card.Title
2020-04-02 20:01:56 +02:00
title={i18n.t('clubs.managers')}
2020-04-03 14:42:43 +02:00
subtitle={hasManagers ? i18n.t('clubs.managersSubtitle') : i18n.t('clubs.managersUnavailable')}
2020-04-02 19:19:30 +02:00
left={(props) => <Avatar.Icon
{...props}
2020-04-03 14:42:43 +02:00
style={{backgroundColor: 'transparent'}}
color={hasManagers ? this.colors.success : this.colors.primary}
icon="account-tie"/>}
2020-04-02 19:19:30 +02:00
/>
<Card.Content>
{final}
</Card.Content>
</Card>
);
}
render() {
return (
<ScrollView style={{paddingLeft: 5, paddingRight: 5}}>
{this.getCategoriesRender(this.displayData.category)}
2020-04-02 19:19:30 +02:00
{this.displayData.logo !== null ?
<View style={{
marginLeft: 'auto',
marginRight: 'auto',
marginTop: 10,
marginBottom: 10,
}}>
<ImageModal
resizeMode="contain"
imageBackgroundColor={this.colors.background}
style={{
width: 300,
height: 300,
}}
source={{
uri: this.displayData.logo,
}}
/></View>
2020-04-02 19:19:30 +02:00
: <View/>}
{this.displayData.description !== null ?
// Surround description with div to allow text styling if the description is not html
<Card.Content>
<HTML html={"<div>" + this.displayData.description + "</div>"}
tagsStyles={{
p: {color: this.colors.text,},
div: {color: this.colors.text}
}}
onLinkPress={openWebLink}/>
</Card.Content>
: <View/>}
2020-04-04 11:55:51 +02:00
{this.getManagersRender(this.displayData.responsibles)}
2020-04-02 19:19:30 +02:00
</ScrollView>
);
}
}
export default withTheme(ClubDisplayScreen);