application-amicale/components/Sidebar.js

191 lines
5 KiB
JavaScript
Raw Normal View History

// @flow
import * as React from 'react';
import {Dimensions, FlatList, Image, Platform, StyleSheet, View} from 'react-native';
2019-06-25 22:20:24 +02:00
import i18n from "i18n-js";
2020-03-05 10:40:25 +01:00
import * as WebBrowser from 'expo-web-browser';
import SidebarDivider from "./SidebarDivider";
import SidebarItem from "./SidebarItem";
2019-06-25 22:20:24 +02:00
const deviceWidth = Dimensions.get("window").width;
2019-06-25 22:20:24 +02:00
type Props = {
navigation: Object,
state: Object,
};
type State = {
active: string,
};
2019-06-29 15:43:57 +02:00
/**
* Class used to define a navigation drawer
*/
export default class SideBar extends React.PureComponent<Props, State> {
dataSet: Array<Object>;
2019-06-25 22:20:24 +02:00
2019-06-29 15:43:57 +02:00
state = {
active: 'Home',
};
2020-02-23 18:15:30 +01:00
getRenderItem: Function;
2019-06-29 15:43:57 +02:00
/**
* Generate the datasets
*
* @param props
*/
constructor(props: Props) {
2019-06-25 22:20:24 +02:00
super(props);
// Dataset used to render the drawer
2019-06-25 22:20:24 +02:00
this.dataSet = [
2020-03-06 09:12:56 +01:00
{
2020-03-08 12:17:04 +01:00
name: i18n.t('screens.home'),
2020-03-06 09:12:56 +01:00
route: "Main",
icon: "home",
},
{
name: i18n.t('sidenav.divider2'),
route: "Divider2"
},
{
name: i18n.t('screens.menuSelf'),
route: "SelfMenuScreen",
icon: "silverware-fork-knife",
},
{
name: i18n.t('screens.availableRooms'),
route: "AvailableRoomScreen",
icon: "calendar-check",
},
{
2020-03-08 12:17:04 +01:00
name: i18n.t('screens.bib'),
2020-03-06 09:12:56 +01:00
route: "BibScreen",
icon: "book",
},
{
name: i18n.t('screens.bluemind'),
route: "BlueMindScreen",
link: "https://etud-mel.insa-toulouse.fr/webmail/",
icon: "email",
},
{
name: i18n.t('screens.ent'),
route: "EntScreen",
link: "https://ent.insa-toulouse.fr/",
icon: "notebook",
},
{
name: i18n.t('sidenav.divider1'),
route: "Divider1"
},
2019-07-31 14:43:19 +02:00
{
name: "Amicale",
route: "AmicaleScreen",
2020-03-05 10:40:25 +01:00
link: "https://amicale-insat.fr/",
icon: "alpha-a-box",
},
2020-01-29 13:53:05 +01:00
{
name: "Élus Étudiants",
route: "ElusEtudScreen",
2020-03-05 10:40:25 +01:00
link: "https://etud.insa-toulouse.fr/~eeinsat/",
2020-01-29 13:53:05 +01:00
icon: "alpha-e-box",
},
2019-06-27 10:45:16 +02:00
{
name: "Wiketud",
route: "WiketudScreen",
2020-03-05 10:40:25 +01:00
link: "https://wiki.etud.insa-toulouse.fr",
icon: "wikipedia",
2019-06-27 10:45:16 +02:00
},
2019-09-19 22:33:28 +02:00
{
name: "Tutor'INSA",
route: "TutorInsaScreen",
2020-03-05 10:40:25 +01:00
link: "https://www.etud.insa-toulouse.fr/~tutorinsa/",
2019-09-19 22:33:28 +02:00
icon: "school",
},
{
name: i18n.t('sidenav.divider3'),
route: "Divider3"
},
{
name: i18n.t('screens.settings'),
route: "SettingsScreen",
icon: "settings",
},
{
name: i18n.t('screens.about'),
route: "AboutScreen",
icon: "information",
},
2019-06-25 22:20:24 +02:00
];
2020-02-11 01:05:24 +01:00
this.getRenderItem = this.getRenderItem.bind(this);
2019-06-25 22:20:24 +02:00
}
2020-03-05 10:40:25 +01:00
onListItemPress(item: Object) {
if (item.link === undefined)
this.props.navigation.navigate(item.route);
else
WebBrowser.openBrowserAsync(item.link);
2020-02-11 01:05:24 +01:00
}
2020-02-23 18:15:30 +01:00
listKeyExtractor(item: Object) {
2020-02-11 01:05:24 +01:00
return item.route;
}
getRenderItem({item}: Object) {
2020-03-05 10:40:25 +01:00
const onListItemPress = this.onListItemPress.bind(this, item);
if (item.icon !== undefined) {
return (
<SidebarItem
title={item.name}
icon={item.icon}
onPress={onListItemPress}
/>
);
} else {
return (
<SidebarDivider title={item.name}/>
);
}
}
2019-06-25 22:20:24 +02:00
render() {
return (
<View style={{height: '100%'}}>
<Image source={require("../assets/drawer-cover.png")} style={styles.drawerCover}/>
<FlatList
data={this.dataSet}
extraData={this.state}
2020-02-11 01:05:24 +01:00
keyExtractor={this.listKeyExtractor}
renderItem={this.getRenderItem}
/>
</View>
2019-06-25 22:20:24 +02:00
);
}
}
const styles = StyleSheet.create({
drawerCover: {
height: deviceWidth / 3,
width: 2 * deviceWidth / 3,
2019-06-25 22:20:24 +02:00
position: "relative",
marginBottom: 10,
marginTop: 20
},
text: {
fontWeight: Platform.OS === "ios" ? "500" : "400",
fontSize: 16,
marginLeft: 20
},
badgeText: {
fontSize: Platform.OS === "ios" ? 13 : 11,
fontWeight: "400",
textAlign: "center",
marginTop: Platform.OS === "android" ? -3 : undefined
}
});