Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
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 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // @flow
  2. import * as React from 'react';
  3. import {ScrollView, View} from 'react-native';
  4. import {Avatar, Card, Chip, Paragraph, withTheme} from 'react-native-paper';
  5. import ImageModal from 'react-native-image-modal';
  6. import i18n from "i18n-js";
  7. import AuthenticatedScreen from "../../../components/Amicale/AuthenticatedScreen";
  8. import CustomHTML from "../../../components/Custom/CustomHTML";
  9. type Props = {
  10. navigation: Object,
  11. route: Object
  12. };
  13. type State = {
  14. imageModalVisible: boolean,
  15. };
  16. /**
  17. * Class defining a club event information page.
  18. * If called with data and categories navigation parameters, will use those to display the data.
  19. * If called with clubId parameter, will fetch the information on the server
  20. */
  21. class ClubDisplayScreen extends React.Component<Props, State> {
  22. displayData: Object;
  23. categories: Object | null;
  24. clubId: number;
  25. shouldFetchData: boolean;
  26. colors: Object;
  27. state = {
  28. imageModalVisible: false,
  29. };
  30. constructor(props) {
  31. super(props);
  32. this.colors = props.theme.colors;
  33. if (this.props.route.params.data !== undefined && this.props.route.params.categories !== undefined) {
  34. this.displayData = this.props.route.params.data;
  35. this.categories = this.props.route.params.categories;
  36. this.clubId = this.props.route.params.data.id;
  37. this.shouldFetchData = false;
  38. } else {
  39. this.displayData = null;
  40. this.categories = null;
  41. this.clubId = this.props.route.params.clubId;
  42. this.shouldFetchData = true;
  43. }
  44. }
  45. getCategoryName(id: number) {
  46. if (this.categories !== null) {
  47. for (let i = 0; i < this.categories.length; i++) {
  48. if (id === this.categories[i].id)
  49. return this.categories[i].name;
  50. }
  51. }
  52. return "";
  53. }
  54. getCategoriesRender(categories: Array<number | null>) {
  55. if (this.categories === null)
  56. return null;
  57. let final = [];
  58. for (let i = 0; i < categories.length; i++) {
  59. let cat = categories[i];
  60. if (cat !== null) {
  61. final.push(
  62. <Chip
  63. style={{marginRight: 5}}
  64. key={i.toString()}>
  65. {this.getCategoryName(cat)}
  66. </Chip>
  67. );
  68. }
  69. }
  70. return <View style={{flexDirection: 'row', marginTop: 5}}>{final}</View>;
  71. }
  72. getManagersRender(resp: Array<string>) {
  73. let final = [];
  74. for (let i = 0; i < resp.length; i++) {
  75. final.push(<Paragraph key={i.toString()}>{resp[i]}</Paragraph>)
  76. }
  77. const hasManagers = resp.length > 0;
  78. return (
  79. <Card style={{marginTop: 10, marginBottom: 10}}>
  80. <Card.Title
  81. title={i18n.t('clubs.managers')}
  82. subtitle={hasManagers ? i18n.t('clubs.managersSubtitle') : i18n.t('clubs.managersUnavailable')}
  83. left={(props) => <Avatar.Icon
  84. {...props}
  85. style={{backgroundColor: 'transparent'}}
  86. color={hasManagers ? this.colors.success : this.colors.primary}
  87. icon="account-tie"/>}
  88. />
  89. <Card.Content>
  90. {final}
  91. </Card.Content>
  92. </Card>
  93. );
  94. }
  95. updateHeaderTitle(data: Object) {
  96. this.props.navigation.setOptions({title: data.name})
  97. }
  98. getScreen = (response: Array<Object>) => {
  99. let data = response[0];
  100. this.updateHeaderTitle(data);
  101. return (
  102. <ScrollView style={{paddingLeft: 5, paddingRight: 5}}>
  103. {this.getCategoriesRender(data.category)}
  104. {data.logo !== null ?
  105. <View style={{
  106. marginLeft: 'auto',
  107. marginRight: 'auto',
  108. marginTop: 10,
  109. marginBottom: 10,
  110. }}>
  111. <ImageModal
  112. isTranslucent={Platform.OS === 'android'}
  113. resizeMode="contain"
  114. imageBackgroundColor={this.colors.background}
  115. style={{
  116. width: 300,
  117. height: 300,
  118. }}
  119. source={{
  120. uri: data.logo,
  121. }}
  122. /></View>
  123. : <View/>}
  124. {data.description !== null ?
  125. // Surround description with div to allow text styling if the description is not html
  126. <Card.Content>
  127. <CustomHTML html={data.description}/>
  128. </Card.Content>
  129. : <View/>}
  130. {this.getManagersRender(data.responsibles)}
  131. </ScrollView>
  132. );
  133. };
  134. render() {
  135. if (this.shouldFetchData)
  136. return <AuthenticatedScreen
  137. {...this.props}
  138. requests={[
  139. {
  140. link: 'clubs/info',
  141. params: {'id': this.clubId},
  142. mandatory: true
  143. }
  144. ]}
  145. renderFunction={this.getScreen}
  146. />;
  147. else
  148. return this.getScreen([this.displayData]);
  149. }
  150. }
  151. export default withTheme(ClubDisplayScreen);