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.

Sidebar.js 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. // @flow
  2. import * as React from 'react';
  3. import {Dimensions, FlatList, Image, StyleSheet, View,} from 'react-native';
  4. import i18n from "i18n-js";
  5. import {TouchableRipple} from "react-native-paper";
  6. import ConnectionManager from "../../managers/ConnectionManager";
  7. import LogoutDialog from "../Amicale/LogoutDialog";
  8. import SideBarSection from "./SideBarSection";
  9. const deviceWidth = Dimensions.get("window").width;
  10. type Props = {
  11. navigation: Object,
  12. state: Object,
  13. theme: Object,
  14. };
  15. type State = {
  16. isLoggedIn: boolean,
  17. dialogVisible: boolean,
  18. activeRoute: string;
  19. };
  20. /**
  21. * Component used to render the drawer menu content
  22. */
  23. class SideBar extends React.Component<Props, State> {
  24. dataSet: Array<Object>;
  25. /**
  26. * Generate the dataset
  27. *
  28. * @param props
  29. */
  30. constructor(props: Props) {
  31. super(props);
  32. // Dataset used to render the drawer
  33. const mainData = [
  34. {
  35. name: i18n.t('screens.home'),
  36. route: "main",
  37. icon: "home",
  38. },
  39. ];
  40. const amicaleData = [
  41. {
  42. name: i18n.t('screens.login'),
  43. route: "login",
  44. icon: "login",
  45. onlyWhenLoggedOut: true,
  46. shouldEmphasis: true,
  47. },
  48. {
  49. name: i18n.t('screens.profile'),
  50. route: "profile",
  51. icon: "account",
  52. onlyWhenLoggedIn: true,
  53. },
  54. {
  55. name: i18n.t('clubs.clubList'),
  56. route: "club-list",
  57. icon: "account-group",
  58. onlyWhenLoggedIn: true,
  59. },
  60. {
  61. name: i18n.t('screens.vote'),
  62. route: "vote",
  63. icon: "vote",
  64. onlyWhenLoggedIn: true,
  65. },
  66. {
  67. name: i18n.t('screens.logout'),
  68. route: 'disconnect',
  69. action: this.showDisconnectDialog,
  70. icon: "logout",
  71. onlyWhenLoggedIn: true,
  72. },
  73. ];
  74. const servicesData = [
  75. {
  76. name: i18n.t('screens.menuSelf'),
  77. route: "self-menu",
  78. icon: "silverware-fork-knife",
  79. },
  80. {
  81. name: i18n.t('screens.availableRooms'),
  82. route: "available-rooms",
  83. icon: "calendar-check",
  84. },
  85. {
  86. name: i18n.t('screens.bib'),
  87. route: "bib",
  88. icon: "book",
  89. },
  90. {
  91. name: i18n.t('screens.bluemind'),
  92. route: "bluemind",
  93. link: "https://etud-mel.insa-toulouse.fr/webmail/",
  94. icon: "email",
  95. },
  96. {
  97. name: i18n.t('screens.ent'),
  98. route: "ent",
  99. link: "https://ent.insa-toulouse.fr/",
  100. icon: "notebook",
  101. },
  102. ];
  103. const websitesData = [
  104. {
  105. name: "Amicale",
  106. route: "amicale",
  107. link: "https://amicale-insat.fr/",
  108. icon: "alpha-a-box",
  109. },
  110. {
  111. name: "Élus Étudiants",
  112. route: "elus-etudiants",
  113. link: "https://etud.insa-toulouse.fr/~eeinsat/",
  114. icon: "alpha-e-box",
  115. },
  116. {
  117. name: "Wiketud",
  118. route: "wiketud",
  119. link: "https://wiki.etud.insa-toulouse.fr",
  120. icon: "wikipedia",
  121. },
  122. {
  123. name: "Tutor'INSA",
  124. route: "tutor-insa",
  125. link: "https://www.etud.insa-toulouse.fr/~tutorinsa/",
  126. icon: "school",
  127. },
  128. ];
  129. const othersData = [
  130. {
  131. name: i18n.t('screens.settings'),
  132. route: "settings",
  133. icon: "settings",
  134. },
  135. {
  136. name: i18n.t('screens.about'),
  137. route: "about",
  138. icon: "information",
  139. },
  140. ];
  141. this.dataSet = [
  142. {
  143. key: '1',
  144. name: i18n.t('screens.home'),
  145. startOpen: true, // App always starts on Main
  146. data: mainData
  147. },
  148. {
  149. key: '2',
  150. name: i18n.t('sidenav.divider4'),
  151. startOpen: false, // TODO set by user preferences
  152. data: amicaleData
  153. },
  154. {
  155. key: '3',
  156. name: i18n.t('sidenav.divider2'),
  157. startOpen: false,
  158. data: servicesData
  159. },
  160. {
  161. key: '4',
  162. name: i18n.t('sidenav.divider1'),
  163. startOpen: false,
  164. data: websitesData
  165. },
  166. {
  167. key: '5',
  168. name: i18n.t('sidenav.divider3'),
  169. startOpen: false,
  170. data: othersData
  171. },
  172. ];
  173. ConnectionManager.getInstance().addLoginStateListener(this.onLoginStateChange);
  174. this.props.navigation.addListener('state', this.onRouteChange);
  175. this.state = {
  176. isLoggedIn: ConnectionManager.getInstance().isLoggedIn(),
  177. dialogVisible: false,
  178. activeRoute: 'Main',
  179. };
  180. }
  181. onRouteChange = (event: Object) => {
  182. try {
  183. const state = event.data.state.routes[0].state; // Get the Drawer's state if it exists
  184. // Get the current route name. This will only show Drawer routes.
  185. // Tab routes will be shown as 'Main'
  186. const routeName = state.routeNames[state.index];
  187. if (this.state.activeRoute !== routeName)
  188. this.setState({activeRoute: routeName});
  189. } catch (e) {
  190. this.setState({activeRoute: 'Main'});
  191. }
  192. };
  193. showDisconnectDialog = () => this.setState({dialogVisible: true});
  194. hideDisconnectDialog = () => this.setState({dialogVisible: false});
  195. onLoginStateChange = (isLoggedIn: boolean) => this.setState({isLoggedIn: isLoggedIn});
  196. /**
  197. * Gets the render item for the given list item
  198. *
  199. * @param item The item to render
  200. * @return {*}
  201. */
  202. getRenderItem = ({item}: Object) => {
  203. return <SideBarSection
  204. {...this.props}
  205. listKey={item.key}
  206. activeRoute={this.state.activeRoute}
  207. isLoggedIn={this.state.isLoggedIn}
  208. sectionName={item.name}
  209. startOpen={item.startOpen}
  210. listData={item.data}
  211. />
  212. };
  213. render() {
  214. return (
  215. <View style={{height: '100%'}}>
  216. <TouchableRipple
  217. onPress={() => this.props.navigation.navigate("tetris")}
  218. >
  219. <Image
  220. source={require("../../../assets/drawer-cover.png")}
  221. style={styles.drawerCover}
  222. />
  223. </TouchableRipple>
  224. {/*$FlowFixMe*/}
  225. <FlatList
  226. data={this.dataSet}
  227. extraData={this.state.isLoggedIn.toString() + this.state.activeRoute}
  228. renderItem={this.getRenderItem}
  229. />
  230. <LogoutDialog
  231. {...this.props}
  232. visible={this.state.dialogVisible}
  233. onDismiss={this.hideDisconnectDialog}
  234. />
  235. </View>
  236. );
  237. }
  238. }
  239. const styles = StyleSheet.create({
  240. drawerCover: {
  241. height: deviceWidth / 3,
  242. width: 2 * deviceWidth / 3,
  243. position: "relative",
  244. marginBottom: 10,
  245. marginTop: 20
  246. },
  247. });
  248. export default SideBar;