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 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. import AuthenticatedScreen from "../../../components/Amicale/AuthenticatedScreen";
  10. type Props = {
  11. navigation: Object,
  12. route: Object
  13. };
  14. type State = {
  15. imageModalVisible: boolean,
  16. };
  17. function openWebLink(event, link) {
  18. Linking.openURL(link).catch((err) => console.error('Error opening link', err));
  19. }
  20. const FakeClub = {
  21. "category": [
  22. 3,
  23. 6,
  24. ],
  25. "description": "<p class=\"ql-align-justify\">Les 100 Tours de l’INSA reviennent en force pour une cinquième édition les 5 et 6 juin prochain&nbsp;!</p><p class=\"ql-align-justify\"><br></p><p class=\"ql-align-justify\">Prépare-toi pour le plus gros évènement de l’année sur le campus de notre belle école qui nous réunit tous autour d’activités folles&nbsp;pour fêter la fin de l’année dans la bonne humeur !</p><p class=\"ql-align-justify\">L’éco-festival tournera autour d’une grande course par équipe qui nous vaut ce doux nom de 100 tours. Ce sera le moment de défier tes potes pour tenter de remporter de nombreux lots, et surtout l’admiration de tous. Mais cela ne s’arrête pas là, puisque tu pourras aussi participer à des activités à sensation, divers ateliers, et de quoi chiller avec tes potes en écoutant de la bonne musique. Tu pourras ensuite enchaîner sur LA soirée de l’année, rythmée par des artistes sur-motivés&nbsp;!</p><p class=\"ql-align-justify\"><br></p><p class=\"ql-align-justify\">Tu es bien entendu le bienvenu si l’envie te prend de rejoindre l’équipe et de nous aider à organiser cet évènement du turfu&nbsp;!</p><p class=\"ql-align-justify\"><br></p><p class=\"ql-align-justify\">La team 100 Tours</p><p class=\"ql-align-justify\"><br></p><p>Contact&nbsp;: <a href=\"mailto:100Tours@amicale-insat.fr\" target=\"_blank\">100tours@amicale-insat.fr</a></p><p>Facebook&nbsp;: Les 100 Tours de l’INSA</p><p>Instagram&nbsp;: 100tours.insatoulouse</p>",
  26. "id": 110,
  27. "logo": "https://www.amicale-insat.fr/storage/clubLogos/2cca8885dd3bdf902124f038b548962b.jpeg",
  28. "name": "100 Tours",
  29. "responsibles": [
  30. "Juliette Duval",
  31. "Emilie Cuminal",
  32. "Maxime Doré",
  33. ],
  34. };
  35. /**
  36. * Class defining a club event information page.
  37. * If called with data and categories navigation parameters, will use those to display the data.
  38. * If called with clubId parameter, will fetch the information on the server
  39. */
  40. class ClubDisplayScreen extends React.Component<Props, State> {
  41. displayData: Object;
  42. categories: Object | null;
  43. clubId: number;
  44. shouldFetchData: boolean;
  45. colors: Object;
  46. state = {
  47. imageModalVisible: false,
  48. };
  49. constructor(props) {
  50. super(props);
  51. this.colors = props.theme.colors;
  52. if (this.props.route.params.data !== undefined && this.props.route.params.categories !== undefined) {
  53. this.displayData = this.props.route.params.data;
  54. this.categories = this.props.route.params.categories;
  55. this.clubId = this.props.route.params.data.id;
  56. this.shouldFetchData = false;
  57. } else {
  58. this.displayData = null;
  59. this.categories = null;
  60. this.clubId = this.props.route.params.clubId;
  61. this.shouldFetchData = true;
  62. }
  63. }
  64. getCategoryName(id: number) {
  65. if (this.categories !== null) {
  66. for (let i = 0; i < this.categories.length; i++) {
  67. if (id === this.categories[i].id)
  68. return this.categories[i].name;
  69. }
  70. }
  71. return "";
  72. }
  73. getCategoriesRender(categories: Array<number | null>) {
  74. if (this.categories === null)
  75. return null;
  76. let final = [];
  77. for (let i = 0; i < categories.length; i++) {
  78. let cat = categories[i];
  79. if (cat !== null) {
  80. final.push(
  81. <Chip
  82. style={{marginRight: 5}}
  83. key={i.toString()}>
  84. {this.getCategoryName(cat)}
  85. </Chip>
  86. );
  87. }
  88. }
  89. return <View style={{flexDirection: 'row', marginTop: 5}}>{final}</View>;
  90. }
  91. getManagersRender(resp: Array<string>) {
  92. let final = [];
  93. for (let i = 0; i < resp.length; i++) {
  94. final.push(<Paragraph key={i.toString()}>{resp[i]}</Paragraph>)
  95. }
  96. const hasManagers = resp.length > 0;
  97. return (
  98. <Card style={{marginTop: 10, marginBottom: 10}}>
  99. <Card.Title
  100. title={i18n.t('clubs.managers')}
  101. subtitle={hasManagers ? i18n.t('clubs.managersSubtitle') : i18n.t('clubs.managersUnavailable')}
  102. left={(props) => <Avatar.Icon
  103. {...props}
  104. style={{backgroundColor: 'transparent'}}
  105. color={hasManagers ? this.colors.success : this.colors.primary}
  106. icon="account-tie"/>}
  107. />
  108. <Card.Content>
  109. {final}
  110. </Card.Content>
  111. </Card>
  112. );
  113. }
  114. updateHeaderTitle(data: Object) {
  115. this.props.navigation.setOptions({title: data.name})
  116. }
  117. getScreen = (data: Object) => {
  118. console.log('fetchedData passed to screen:');
  119. console.log(data);
  120. console.log("Using fake data");
  121. data = FakeClub;
  122. this.updateHeaderTitle(data);
  123. return (
  124. <ScrollView style={{paddingLeft: 5, paddingRight: 5}}>
  125. {this.getCategoriesRender(data.category)}
  126. {data.logo !== null ?
  127. <View style={{
  128. marginLeft: 'auto',
  129. marginRight: 'auto',
  130. marginTop: 10,
  131. marginBottom: 10,
  132. }}>
  133. <ImageModal
  134. resizeMode="contain"
  135. imageBackgroundColor={this.colors.background}
  136. style={{
  137. width: 300,
  138. height: 300,
  139. }}
  140. source={{
  141. uri: data.logo,
  142. }}
  143. /></View>
  144. : <View/>}
  145. {data.description !== null ?
  146. // Surround description with div to allow text styling if the description is not html
  147. <Card.Content>
  148. <HTML html={"<div>" + data.description + "</div>"}
  149. tagsStyles={{
  150. p: {color: this.colors.text,},
  151. div: {color: this.colors.text}
  152. }}
  153. onLinkPress={openWebLink}/>
  154. </Card.Content>
  155. : <View/>}
  156. {this.getManagersRender(data.responsibles)}
  157. </ScrollView>
  158. );
  159. };
  160. render() {
  161. if (this.shouldFetchData)
  162. return <AuthenticatedScreen
  163. {...this.props}
  164. links={[
  165. {
  166. link: 'clubs/' + this.clubId,
  167. mandatory: true,
  168. }
  169. ]}
  170. renderFunction={this.getScreen}
  171. />;
  172. else
  173. return this.getScreen(this.displayData);
  174. }
  175. }
  176. export default withTheme(ClubDisplayScreen);