Application Android et IOS pour l'amicale des élèves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClubDisplayScreen.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // @flow
  2. import * as React from 'react';
  3. import {ScrollView, View} from 'react-native';
  4. import HTML from "react-native-render-html";
  5. import {Linking} from "expo";
  6. import {Avatar, Card, Chip, Paragraph, withTheme} from 'react-native-paper';
  7. import ImageModal from 'react-native-image-modal';
  8. import i18n from "i18n-js";
  9. type Props = {
  10. navigation: Object,
  11. route: Object
  12. };
  13. type State = {
  14. imageModalVisible: boolean,
  15. };
  16. function openWebLink(event, link) {
  17. Linking.openURL(link).catch((err) => console.error('Error opening link', err));
  18. }
  19. /**
  20. * Class defining a planning event information page.
  21. */
  22. class ClubDisplayScreen extends React.Component<Props, State> {
  23. displayData = this.props.route.params['data'];
  24. categories = this.props.route.params['categories'];
  25. colors: Object;
  26. state = {
  27. imageModalVisible: false,
  28. };
  29. constructor(props) {
  30. super(props);
  31. this.colors = props.theme.colors;
  32. }
  33. componentDidMount(): * {
  34. this.props.navigation.setOptions({title: this.displayData.name})
  35. }
  36. getCategoryName(id: number) {
  37. for (let i = 0; i < this.categories.length; i++) {
  38. if (id === this.categories[i].id)
  39. return this.categories[i].name;
  40. }
  41. return "";
  42. }
  43. getCategoriesRender(categories: Array<number | null>) {
  44. let final = [];
  45. for (let i = 0; i < categories.length; i++) {
  46. if (categories[i] !== null) {
  47. final.push(
  48. <Chip
  49. style={{marginRight: 5}}
  50. key={i.toString()}>
  51. {this.getCategoryName(categories[i])}
  52. </Chip>
  53. );
  54. }
  55. }
  56. return <View style={{flexDirection: 'row', marginTop: 5}}>{final}</View>;
  57. }
  58. getManagersRender(resp: Array<string>) {
  59. let final = [];
  60. for (let i = 0; i < resp.length; i++) {
  61. final.push(<Paragraph key={i.toString()}>{resp[i]}</Paragraph>)
  62. }
  63. const hasManagers = resp.length > 0;
  64. return (
  65. <Card style={{marginTop: 10, marginBottom: 10}}>
  66. <Card.Title
  67. title={i18n.t('clubs.managers')}
  68. subtitle={hasManagers ? i18n.t('clubs.managersSubtitle') : i18n.t('clubs.managersUnavailable')}
  69. left={(props) => <Avatar.Icon
  70. {...props}
  71. style={{backgroundColor: 'transparent'}}
  72. color={hasManagers ? this.colors.success : this.colors.primary}
  73. icon="account-tie"/>}
  74. />
  75. <Card.Content>
  76. {final}
  77. </Card.Content>
  78. </Card>
  79. );
  80. }
  81. render() {
  82. return (
  83. <ScrollView style={{paddingLeft: 5, paddingRight: 5}}>
  84. {this.getCategoriesRender(this.displayData.category)}
  85. {this.displayData.logo !== null ?
  86. <View style={{
  87. marginLeft: 'auto',
  88. marginRight: 'auto',
  89. marginTop: 10,
  90. marginBottom: 10,
  91. }}>
  92. <ImageModal
  93. resizeMode="contain"
  94. imageBackgroundColor={this.colors.background}
  95. style={{
  96. width: 300,
  97. height: 300,
  98. }}
  99. source={{
  100. uri: this.displayData.logo,
  101. }}
  102. /></View>
  103. : <View/>}
  104. {this.displayData.description !== null ?
  105. // Surround description with div to allow text styling if the description is not html
  106. <Card.Content>
  107. <HTML html={"<div>" + this.displayData.description + "</div>"}
  108. tagsStyles={{
  109. p: {color: this.colors.text,},
  110. div: {color: this.colors.text}
  111. }}
  112. onLinkPress={openWebLink}/>
  113. </Card.Content>
  114. : <View/>}
  115. {this.getManagersRender(this.displayData.responsibles)}
  116. </ScrollView>
  117. );
  118. }
  119. }
  120. export default withTheme(ClubDisplayScreen);