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.

ServicesScreen.js 10KB

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