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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 {CommonActions} from "@react-navigation/native";
  9. import {Animated, View} from "react-native";
  10. import {Avatar, Button, Card, Divider, List, Title, TouchableRipple, withTheme} from "react-native-paper";
  11. import type {CustomTheme} from "../../managers/ThemeManager";
  12. import ConnectionManager from "../../managers/ConnectionManager";
  13. import i18n from 'i18n-js';
  14. type Props = {
  15. navigation: Object,
  16. route: Object,
  17. collapsibleStack: Collapsible,
  18. theme: CustomTheme,
  19. }
  20. const BIB_IMAGE = "https://scontent-cdg2-1.xx.fbcdn.net/v/t1.0-9/50695561_2124263197597162_2325349608210825216_n.jpg?_nc_cat=109&_nc_sid=8bfeb9&_nc_ohc=tmcV6FWO7_kAX9vfWHU&_nc_ht=scontent-cdg2-1.xx&oh=3b81c76e46b49f7c3a033ea3b07ec212&oe=5EC59B4D";
  21. const RU_IMAGE = "https://scontent-cdg2-1.xx.fbcdn.net/v/t1.0-9/47123773_2041883702501779_5289372776166064128_o.jpg?_nc_cat=100&_nc_sid=cdbe9c&_nc_ohc=dpuBGlIIy_EAX8CyC0l&_nc_ht=scontent-cdg2-1.xx&oh=5c5bb4f0c7f12b554246f7c9b620a5f3&oe=5EC4DB31";
  22. const ROOM_IMAGE = "https://scontent-cdt1-1.xx.fbcdn.net/v/t1.0-9/47041013_2043521689004647_316124496522117120_n.jpg?_nc_cat=103&_nc_sid=8bfeb9&_nc_ohc=bIp8OVJvvSEAX8mKnDZ&_nc_ht=scontent-cdt1-1.xx&oh=b4fef72a645804a849ad30e9e20fca12&oe=5EC29309";
  23. const EMAIL_IMAGE = "https://etud-mel.insa-toulouse.fr/webmail/images/logo-bluemind.png";
  24. const ENT_IMAGE = "https://ent.insa-toulouse.fr/media/org/jasig/portal/layout/tab-column/xhtml-theme/insa/institutional/LogoInsa.png";
  25. const PROXIMO_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/proximo-logo.png"
  26. const WIKETUD_LINK = "https://wiki.etud.insa-toulouse.fr/resources/assets/wiketud.png?ff051";
  27. const AMICALE_IMAGE = require("../../../assets/amicale.png");
  28. const EE_IMAGE = "https://etud.insa-toulouse.fr/~eeinsat/wp-content/uploads/2019/09/logo-blanc.png";
  29. const TUTORINSA_IMAGE = "https://www.etud.insa-toulouse.fr/~tutorinsa/public/images/logo-gray.png";
  30. export type listItem = {
  31. title: string,
  32. description: string,
  33. image: string | number,
  34. shouldLogin: boolean,
  35. content: cardList,
  36. }
  37. type State = {
  38. isLoggedIn: boolean,
  39. }
  40. class ServicesScreen extends React.Component<Props, State> {
  41. amicaleDataset: cardList;
  42. studentsDataset: cardList;
  43. insaDataset: cardList;
  44. finalDataset: Array<listItem>
  45. constructor(props) {
  46. super(props);
  47. const nav = props.navigation;
  48. this.amicaleDataset = [
  49. {
  50. title: i18n.t('screens.clubsAbout'),
  51. subtitle: "CLUB LIST",
  52. image: AMICALE_IMAGE,
  53. onPress: () => nav.navigate("club-list"),
  54. },
  55. {
  56. title: i18n.t('screens.profile'),
  57. subtitle: "PROFIL",
  58. image: AMICALE_IMAGE,
  59. onPress: () => nav.navigate("profile"),
  60. },
  61. {
  62. title: i18n.t('screens.amicaleAbout'),
  63. subtitle: "CONTACT",
  64. image: AMICALE_IMAGE,
  65. onPress: () => nav.navigate("amicale-contact"),
  66. },
  67. {
  68. title: i18n.t('screens.vote'),
  69. subtitle: "ELECTIONS",
  70. image: AMICALE_IMAGE,
  71. onPress: () => nav.navigate("vote"),
  72. },
  73. ];
  74. this.studentsDataset = [
  75. {
  76. title: i18n.t('screens.proximo'),
  77. subtitle: "proximo",
  78. image: PROXIMO_IMAGE,
  79. onPress: () => nav.navigate("proximo"),
  80. },
  81. {
  82. title: i18n.t('screens.amicaleWebsite'),
  83. subtitle: "AMICALE",
  84. image: AMICALE_IMAGE,
  85. onPress: () => nav.navigate("amicale-website"),
  86. },
  87. {
  88. title: "Wiketud",
  89. subtitle: "wiketud",
  90. image: WIKETUD_LINK,
  91. onPress: () => nav.navigate("wiketud"),
  92. },
  93. {
  94. title: "Élus Étudiants",
  95. subtitle: "ELUS ETUDIANTS",
  96. image: EE_IMAGE,
  97. onPress: () => nav.navigate("elus-etudiants"),
  98. },
  99. {
  100. title: "Tutor'INSA",
  101. subtitle: "TUTOR INSA",
  102. image: TUTORINSA_IMAGE,
  103. onPress: () => nav.navigate("tutorinsa"),
  104. },
  105. ];
  106. this.insaDataset = [
  107. {
  108. title: i18n.t('screens.menuSelf'),
  109. subtitle: "the ru",
  110. image: RU_IMAGE,
  111. onPress: () => nav.navigate("self-menu"),
  112. },
  113. {
  114. title: i18n.t('screens.availableRooms'),
  115. subtitle: "ROOMS",
  116. image: ROOM_IMAGE,
  117. onPress: () => nav.navigate("available-rooms"),
  118. },
  119. {
  120. title: i18n.t('screens.bib'),
  121. subtitle: "BIB",
  122. image: BIB_IMAGE,
  123. onPress: () => nav.navigate("bib"),
  124. },
  125. {
  126. title: i18n.t('screens.bluemind'),
  127. subtitle: "EMAIL",
  128. image: EMAIL_IMAGE,
  129. onPress: () => nav.navigate("bluemind"),
  130. },
  131. {
  132. title: i18n.t('screens.ent'),
  133. subtitle: "ENT",
  134. image: ENT_IMAGE,
  135. onPress: () => nav.navigate("ent"),
  136. },
  137. ];
  138. this.finalDataset = [
  139. {
  140. title: i18n.t("servicesScreen.amicale"),
  141. description: "LOGIN",
  142. image: AMICALE_IMAGE,
  143. shouldLogin: true,
  144. content: this.amicaleDataset
  145. },
  146. {
  147. title: i18n.t("servicesScreen.students"),
  148. description: "SERVICES OFFERED BY STUDENTS",
  149. image: 'account-group',
  150. shouldLogin: false,
  151. content: this.studentsDataset
  152. },
  153. {
  154. title: i18n.t("servicesScreen.insa"),
  155. description: "SERVICES OFFERED BY INSA",
  156. image: 'school',
  157. shouldLogin: false,
  158. content: this.insaDataset
  159. },
  160. ];
  161. this.state = {
  162. isLoggedIn: ConnectionManager.getInstance().isLoggedIn()
  163. }
  164. }
  165. componentDidMount() {
  166. this.props.navigation.addListener('focus', this.onFocus);
  167. }
  168. onFocus = () => {
  169. this.handleNavigationParams();
  170. this.setState({isLoggedIn: ConnectionManager.getInstance().isLoggedIn()})
  171. }
  172. handleNavigationParams() {
  173. if (this.props.route.params != null) {
  174. if (this.props.route.params.nextScreen != null) {
  175. this.props.navigation.navigate(this.props.route.params.nextScreen);
  176. // reset params to prevent infinite loop
  177. this.props.navigation.dispatch(CommonActions.setParams({nextScreen: null}));
  178. }
  179. }
  180. };
  181. getAvatar(props, source: string | number) {
  182. if (typeof source === "number")
  183. return <Avatar.Image
  184. {...props}
  185. size={48}
  186. source={AMICALE_IMAGE}
  187. style={{backgroundColor: 'transparent'}}
  188. />
  189. else
  190. return <Avatar.Icon
  191. {...props}
  192. size={48}
  193. icon={source}
  194. color={this.props.theme.colors.primary}
  195. style={{backgroundColor: 'transparent'}}
  196. />
  197. }
  198. getLoginMessage() {
  199. return (
  200. <View>
  201. <Title style={{
  202. marginLeft: 'auto',
  203. marginRight: 'auto',
  204. }}>
  205. {i18n.t("servicesScreen.notLoggedIn")}
  206. </Title>
  207. <Button
  208. icon="login"
  209. mode="contained"
  210. onPress={() => this.props.navigation.navigate("login")}
  211. style={{
  212. marginLeft: 'auto',
  213. marginRight: 'auto',
  214. }}>
  215. {i18n.t("screens.login")}
  216. </Button>
  217. </View>
  218. )
  219. }
  220. renderItem = ({item}: { item: listItem }) => {
  221. const shouldShowLogin = !this.state.isLoggedIn && item.shouldLogin;
  222. return (
  223. <TouchableRipple
  224. style={{
  225. margin: 5,
  226. marginBottom: 20,
  227. }}
  228. onPress={shouldShowLogin
  229. ? undefined
  230. : () => this.props.navigation.navigate("services-section", {data: item})}
  231. >
  232. <View>
  233. <Card.Title
  234. title={item.title}
  235. left={(props) => this.getAvatar(props, item.image)}
  236. right={shouldShowLogin
  237. ? undefined
  238. : (props) => <List.Icon {...props} icon="chevron-right"/>}
  239. />
  240. {
  241. shouldShowLogin
  242. ? this.getLoginMessage()
  243. : <CardList
  244. dataset={item.content}
  245. isHorizontal={true}
  246. />
  247. }
  248. </View>
  249. </TouchableRipple>
  250. );
  251. };
  252. keyExtractor = (item: listItem) => {
  253. return item.title;
  254. }
  255. render() {
  256. const {containerPaddingTop, scrollIndicatorInsetTop, onScroll} = this.props.collapsibleStack;
  257. return <Animated.FlatList
  258. data={this.finalDataset}
  259. renderItem={this.renderItem}
  260. keyExtractor={this.keyExtractor}
  261. onScroll={onScroll}
  262. contentContainerStyle={{
  263. paddingTop: containerPaddingTop,
  264. paddingBottom: CustomTabBar.TAB_BAR_HEIGHT + 20
  265. }}
  266. scrollIndicatorInsets={{top: scrollIndicatorInsetTop}}
  267. ItemSeparatorComponent={() => <Divider/>}
  268. />
  269. }
  270. }
  271. export default withCollapsible(withTheme(ServicesScreen));