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.

ServicesScreen.js 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. // @flow
  2. import * as React from 'react';
  3. import type {cardList} from "../../components/Lists/CardList/CardList";
  4. import CardList from "../../components/Lists/CardList/CardList";
  5. import CustomTabBar from "../../components/Tabbar/CustomTabBar";
  6. import {withCollapsible} from "../../utils/withCollapsible";
  7. import {Collapsible} from "react-navigation-collapsible";
  8. import {Animated, View} from "react-native";
  9. import {Avatar, Card, Divider, List, TouchableRipple, withTheme} from "react-native-paper";
  10. import type {CustomTheme} from "../../managers/ThemeManager";
  11. import i18n from 'i18n-js';
  12. import MaterialHeaderButtons, {Item} from "../../components/Overrides/CustomHeaderButton";
  13. import ConnectionManager from "../../managers/ConnectionManager";
  14. import {StackNavigationProp} from "@react-navigation/stack";
  15. import AvailableWebsites from "../../constants/AvailableWebsites";
  16. type Props = {
  17. navigation: StackNavigationProp,
  18. collapsibleStack: Collapsible,
  19. theme: CustomTheme,
  20. }
  21. export type listItem = {
  22. title: string,
  23. description: string,
  24. image: string,
  25. shouldLogin: boolean,
  26. content: cardList,
  27. }
  28. const CLUBS_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Clubs.png";
  29. const PROFILE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ProfilAmicaliste.png";
  30. const VOTE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Vote.png";
  31. const AMICALE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/WebsiteAmicale.png";
  32. const PROXIMO_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Proximo.png"
  33. const WIKETUD_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Wiketud.png";
  34. const EE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/EEC.png";
  35. const TUTORINSA_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/TutorINSA.png";
  36. const BIB_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Bib.png";
  37. const RU_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/RU.png";
  38. const ROOM_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Salles.png";
  39. const EMAIL_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Bluemind.png";
  40. const ENT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ENT.png";
  41. const ACCOUNT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Account.png";
  42. class ServicesScreen extends React.Component<Props> {
  43. amicaleDataset: cardList;
  44. studentsDataset: cardList;
  45. insaDataset: cardList;
  46. finalDataset: Array<listItem>
  47. constructor(props) {
  48. super(props);
  49. const nav = props.navigation;
  50. this.amicaleDataset = [
  51. {
  52. title: i18n.t('screens.clubsAbout'),
  53. subtitle: i18n.t('servicesScreen.descriptions.clubs'),
  54. image: CLUBS_IMAGE,
  55. onPress: () => this.onAmicaleServicePress("club-list"),
  56. },
  57. {
  58. title: i18n.t('screens.profile'),
  59. subtitle: i18n.t('servicesScreen.descriptions.profile'),
  60. image: PROFILE_IMAGE,
  61. onPress: () => this.onAmicaleServicePress("profile"),
  62. },
  63. {
  64. title: i18n.t('screens.amicaleWebsite'),
  65. subtitle: i18n.t('servicesScreen.descriptions.amicaleWebsite'),
  66. image: AMICALE_IMAGE,
  67. onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.AMICALE, title: i18n.t('screens.amicaleWebsite')}),
  68. },
  69. {
  70. title: i18n.t('screens.vote'),
  71. subtitle: i18n.t('servicesScreen.descriptions.vote'),
  72. image: VOTE_IMAGE,
  73. onPress: () => this.onAmicaleServicePress("vote"),
  74. },
  75. ];
  76. this.studentsDataset = [
  77. {
  78. title: i18n.t('screens.proximo'),
  79. subtitle: i18n.t('servicesScreen.descriptions.proximo'),
  80. image: PROXIMO_IMAGE,
  81. onPress: () => nav.navigate("proximo"),
  82. },
  83. {
  84. title: "Wiketud",
  85. subtitle: i18n.t('servicesScreen.descriptions.wiketud'),
  86. image: WIKETUD_IMAGE,
  87. onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.WIKETUD, title: "Wiketud"}),
  88. },
  89. {
  90. title: "Élus Étudiants",
  91. subtitle: i18n.t('servicesScreen.descriptions.elusEtudiants'),
  92. image: EE_IMAGE,
  93. onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.ELUS_ETUDIANTS, title: "Élus Étudiants"}),
  94. },
  95. {
  96. title: "Tutor'INSA",
  97. subtitle: i18n.t('servicesScreen.descriptions.tutorInsa'),
  98. image: TUTORINSA_IMAGE,
  99. onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.TUTOR_INSA, title: "Tutor'INSA"})
  100. },
  101. ];
  102. this.insaDataset = [
  103. {
  104. title: i18n.t('screens.menuSelf'),
  105. subtitle: i18n.t('servicesScreen.descriptions.self'),
  106. image: RU_IMAGE,
  107. onPress: () => nav.navigate("self-menu"),
  108. },
  109. {
  110. title: i18n.t('screens.availableRooms'),
  111. subtitle: i18n.t('servicesScreen.descriptions.availableRooms'),
  112. image: ROOM_IMAGE,
  113. onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.AVAILABLE_ROOMS, title: i18n.t('screens.availableRooms')}),
  114. },
  115. {
  116. title: i18n.t('screens.bib'),
  117. subtitle: i18n.t('servicesScreen.descriptions.bib'),
  118. image: BIB_IMAGE,
  119. onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.BIB, title: i18n.t('screens.bib')}),
  120. },
  121. {
  122. title: i18n.t('screens.bluemind'),
  123. subtitle: i18n.t('servicesScreen.descriptions.mails'),
  124. image: EMAIL_IMAGE,
  125. onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.BLUEMIND, title: i18n.t('screens.bluemind')}),
  126. },
  127. {
  128. title: i18n.t('screens.ent'),
  129. subtitle: i18n.t('servicesScreen.descriptions.ent'),
  130. image: ENT_IMAGE,
  131. onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.ENT, title: i18n.t('screens.ent')}),
  132. },
  133. {
  134. title: i18n.t('screens.insaAccount'),
  135. subtitle: i18n.t('servicesScreen.descriptions.insaAccount'),
  136. image: ACCOUNT_IMAGE,
  137. onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.INSA_ACCOUNT, title: i18n.t('screens.insaAccount')}),
  138. },
  139. ];
  140. this.finalDataset = [
  141. {
  142. title: i18n.t("servicesScreen.amicale"),
  143. description: "LOGIN",
  144. image: AMICALE_IMAGE,
  145. shouldLogin: true,
  146. content: this.amicaleDataset
  147. },
  148. {
  149. title: i18n.t("servicesScreen.students"),
  150. description: "SERVICES OFFERED BY STUDENTS",
  151. image: 'account-group',
  152. shouldLogin: false,
  153. content: this.studentsDataset
  154. },
  155. {
  156. title: i18n.t("servicesScreen.insa"),
  157. description: "SERVICES OFFERED BY INSA",
  158. image: 'school',
  159. shouldLogin: false,
  160. content: this.insaDataset
  161. },
  162. ];
  163. }
  164. componentDidMount() {
  165. this.props.navigation.setOptions({
  166. headerRight: this.getAboutButton,
  167. });
  168. }
  169. getAboutButton = () =>
  170. <MaterialHeaderButtons>
  171. <Item title="information" iconName="information" onPress={this.onAboutPress}/>
  172. </MaterialHeaderButtons>;
  173. onAboutPress = () => this.props.navigation.navigate('amicale-contact');
  174. /**
  175. * Gets the list title image for the list.
  176. *
  177. * @param props Props to pass to the component
  178. * @param source The source image to display
  179. * @returns {*}
  180. */
  181. getListTitleImage(props, source: string) {
  182. return <Avatar.Image
  183. {...props}
  184. size={48}
  185. source={source}
  186. style={{backgroundColor: 'transparent'}}
  187. />
  188. }
  189. /**
  190. * Redirects to the given route or to the login screen if user is not logged in.
  191. *
  192. * @param route The route to navigate to
  193. */
  194. onAmicaleServicePress(route: string) {
  195. if (ConnectionManager.getInstance().isLoggedIn())
  196. this.props.navigation.navigate(route);
  197. else
  198. this.props.navigation.navigate("login", {nextScreen: route});
  199. }
  200. /**
  201. * A list item showing a list of available services for the current category
  202. *
  203. * @param item
  204. * @returns {*}
  205. */
  206. renderItem = ({item}: { item: listItem }) => {
  207. return (
  208. <TouchableRipple
  209. style={{
  210. margin: 5,
  211. marginBottom: 20,
  212. }}
  213. onPress={() => this.props.navigation.navigate("services-section", {data: item})}
  214. >
  215. <View>
  216. <Card.Title
  217. title={item.title}
  218. left={(props) => this.getListTitleImage(props, item.image)}
  219. right={(props) => <List.Icon {...props} icon="chevron-right"/>}
  220. />
  221. <CardList
  222. dataset={item.content}
  223. isHorizontal={true}
  224. />
  225. </View>
  226. </TouchableRipple>
  227. );
  228. };
  229. keyExtractor = (item: listItem) => {
  230. return item.title;
  231. }
  232. render() {
  233. const {containerPaddingTop, scrollIndicatorInsetTop, onScroll} = this.props.collapsibleStack;
  234. return <Animated.FlatList
  235. data={this.finalDataset}
  236. renderItem={this.renderItem}
  237. keyExtractor={this.keyExtractor}
  238. onScroll={onScroll}
  239. contentContainerStyle={{
  240. paddingTop: containerPaddingTop,
  241. paddingBottom: CustomTabBar.TAB_BAR_HEIGHT + 20
  242. }}
  243. scrollIndicatorInsets={{top: scrollIndicatorInsetTop}}
  244. ItemSeparatorComponent={() => <Divider/>}
  245. />
  246. }
  247. }
  248. export default withCollapsible(withTheme(ServicesScreen));