Skip to content

Instantly share code, notes, and snippets.

@dantman
Created September 7, 2017 01:30
Show Gist options
  • Save dantman/caefc8778303dd1609659860bd4729ab to your computer and use it in GitHub Desktop.
Save dantman/caefc8778303dd1609659860bd4729ab to your computer and use it in GitHub Desktop.
render() {
const {styles, onLogout} = this;
const {onOverlayStateChanged} = this;
const {materialTheme, sections: rawSections, navigation, screenProps: {statusBarHeight}, user, activeCompany, company, teams} = this.props;
const {overlayOpen} = this.state;
const sections = navigation.state.routes::groupBy((route) => this._getScreenOptions(route.key).drawerSection);
const {companyList=[]} = user || {};
const children = [];
let first = true;
for ( let sectionName of rawSections ) {
if ( !first ) {
children.push(<Divider key={`${sectionName}-divider`} />);
}
if ( sectionLabels[sectionName] ) {
children.push(
<Subheader
key={`${sectionName}-subheader`}
secondary
text={sectionLabels[sectionName]} />
);
}
let items = sections[sectionName] || [];
if ( sectionName === 'teams' ) {
const activeRoute = navigation.state.routes[navigation.state.index];
const activeParams = activeRoute && activeRoute.routeName === 'Teams'
&& activeRoute.routes[0].params;
children.push(
<DrawerItem
key='Team'
onPress={() => {
navigation.dispatch(NavigationActions.navigate({
key: 'DrawerClose',
routeName: 'Teams',
}));
setImmediate(() => {
navigation.dispatch(NavigationActions.reset({
key: 'Teams',
index: 0,
actions: [
NavigationActions.navigate({
routeName: 'Teams',
params: {
bundle: 'all',
departmentName: undefined,
searchRows: undefined,
},
})
],
}));
});
}}
active={activeParams && !activeParams.departmentName}
iconColor={colors.deepPurple500}
icon='aex:teams'
label='All' />);
for ( const team of teams ) {
children.push(
<DrawerItem
key={`Team-${team.departmentName}`}
onPress={() => {
navigation.dispatch(NavigationActions.navigate({
key: 'DrawerClose',
routeName: 'Teams',
}));
setImmediate(() => {
navigation.dispatch(NavigationActions.reset({
key: 'Teams',
index: 0,
actions: [
NavigationActions.navigate({
routeName: 'Teams',
params: {
bundle: 'department',
departmentName: team.departmentName,
searchRows: [
{
searchFieldType: 1,
searchField: 'd.r',
searchOperator: '9',
searchValue: `department-${team.departmentName}`,
rawType: '1'
}
],
},
})
],
}));
});
}}
active={activeParams && activeParams.departmentName === team.departmentName}
label={team.departmentName} />);
}
} else {
children.push(
<DrawerItems
key={sectionName}
{...this.props}
items={items} />
);
}
first = false;
}
return (
<ScrollView>
<DrawerHeader
{...{statusBarHeight, user, company}}
expanded={overlayOpen}
onExpansionChanged={onOverlayStateChanged} />
<Divider />
<DrawerOverlayableBody
expanded={overlayOpen}
body={children}
overlay={
<View style={{backgroundColor: materialTheme.palette.container}}>
<DrawerItem
onPress={onLogout}
icon='+logout'
label='Log out' />
<Divider style={styles.divider} />
<Subheader
secondary
text='Companies' />
{companyList.map(({companyId, companyName}) => (
<DrawerItem
key={companyId}
onPress={() => {
this.props.dispatch(SessionActions.setCompany(companyId))
navigation.dispatch(NavigationActions.navigate({
key: 'DrawerClose',
routeName: 'Workspace',
}));
setImmediate(() => {
navigation.dispatch(NavigationActions.reset({
key: 'Workspace',
index: 0,
actions: [
NavigationActions.navigate({
routeName: 'Workspace',
params: {
bundle: 'myworkspace',
},
})
],
}));
});
}}
active={activeCompany === companyId}
avatarText={companyName && companyName.charAt(0)}
label={companyName} />
))}
</View>
} />
</ScrollView>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment