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.

Sidebar.js 7.7KB

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