2017-05-16 21:57:09 +02:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux'
|
2017-05-16 22:25:19 +02:00
|
|
|
import { View, Text, Button, StyleSheet } from 'react-native';
|
2017-06-24 20:06:28 +02:00
|
|
|
import { Log } from 'lib/log.js';
|
2017-05-16 22:25:19 +02:00
|
|
|
import { Menu, MenuOptions, MenuOption, MenuTrigger } from 'react-native-popup-menu';
|
2017-06-24 20:06:28 +02:00
|
|
|
import { _ } from 'lib/locale.js';
|
|
|
|
import { Setting } from 'lib/models/setting.js';
|
2017-07-06 20:58:01 +02:00
|
|
|
import { FileApi } from 'lib/file-api.js';
|
|
|
|
import { FileApiDriverOneDrive } from 'lib/file-api-driver-onedrive.js';
|
2017-05-16 21:57:09 +02:00
|
|
|
|
2017-05-16 22:25:19 +02:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
divider: {
|
|
|
|
marginVertical: 5,
|
|
|
|
marginHorizontal: 2,
|
|
|
|
borderBottomWidth: 1,
|
|
|
|
borderColor: '#ccc'
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-05-16 21:57:09 +02:00
|
|
|
class ScreenHeaderComponent extends Component {
|
|
|
|
|
|
|
|
showBackButton() {
|
|
|
|
// Note: this is hardcoded for now because navigation.state doesn't tell whether
|
|
|
|
// it's possible to go back or not. Maybe it's possible to get this information
|
|
|
|
// from somewhere else.
|
2017-05-24 22:11:37 +02:00
|
|
|
return this.props.navState.routeName != 'Notes';
|
2017-05-16 21:57:09 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 22:01:43 +02:00
|
|
|
sideMenuButton_press() {
|
2017-05-24 21:27:13 +02:00
|
|
|
this.props.dispatch({ type: 'SIDE_MENU_TOGGLE' });
|
|
|
|
}
|
|
|
|
|
2017-06-06 22:01:43 +02:00
|
|
|
backButton_press() {
|
2017-05-16 21:57:09 +02:00
|
|
|
this.props.dispatch({ type: 'Navigation/BACK' });
|
|
|
|
}
|
|
|
|
|
2017-06-06 22:01:43 +02:00
|
|
|
menu_select(value) {
|
2017-05-16 22:25:19 +02:00
|
|
|
if (typeof(value) == 'function') {
|
|
|
|
value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-06 20:58:01 +02:00
|
|
|
menu_synchronize() {
|
2017-07-06 21:29:09 +02:00
|
|
|
this.props.dispatch({
|
|
|
|
type: 'Navigation/NAVIGATE',
|
|
|
|
routeName: 'OneDriveLogin',
|
|
|
|
});
|
|
|
|
|
2017-07-06 20:58:01 +02:00
|
|
|
// const CLIENT_ID = 'e09fc0de-c958-424f-83a2-e56a721d331b';
|
|
|
|
// const CLIENT_SECRET = 'JA3cwsqSGHFtjMwd5XoF5L5';
|
2017-05-16 23:46:21 +02:00
|
|
|
|
2017-07-06 20:58:01 +02:00
|
|
|
// let driver = new FileApiDriverOneDrive(CLIENT_ID, CLIENT_SECRET);
|
|
|
|
// let auth = Setting.value('sync.onedrive.auth');
|
|
|
|
|
|
|
|
// if (auth) {
|
|
|
|
// auth = JSON.parse(auth);
|
|
|
|
// } else {
|
|
|
|
// driver.api().oauthDance(vorpal);
|
|
|
|
// //auth = driver.api().oauthDance(vorpal);
|
|
|
|
// //Setting.setValue('sync.onedrive.auth', JSON.stringify(auth));
|
|
|
|
// }
|
2017-05-16 23:46:21 +02:00
|
|
|
}
|
|
|
|
|
2017-05-16 21:57:09 +02:00
|
|
|
render() {
|
2017-05-16 23:46:21 +02:00
|
|
|
let key = 0;
|
2017-05-16 22:25:19 +02:00
|
|
|
let menuOptionComponents = [];
|
|
|
|
for (let i = 0; i < this.props.menuOptions.length; i++) {
|
|
|
|
let o = this.props.menuOptions[i];
|
|
|
|
menuOptionComponents.push(
|
2017-05-16 23:46:21 +02:00
|
|
|
<MenuOption value={o.onPress} key={'menuOption_' + key++}>
|
2017-05-16 22:25:19 +02:00
|
|
|
<Text>{o.title}</Text>
|
2017-05-16 23:46:21 +02:00
|
|
|
</MenuOption>);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (menuOptionComponents.length) {
|
|
|
|
menuOptionComponents.push(<View key={'menuOption_' + key++} style={styles.divider}/>);
|
2017-05-16 22:25:19 +02:00
|
|
|
}
|
|
|
|
|
2017-07-06 20:58:01 +02:00
|
|
|
menuOptionComponents.push(
|
|
|
|
<MenuOption value={() => this.menu_synchronize()} key={'menuOption_' + key++}>
|
|
|
|
<Text>{_('Synchronize')}</Text>
|
|
|
|
</MenuOption>);
|
2017-05-16 23:46:21 +02:00
|
|
|
|
|
|
|
menuOptionComponents.push(
|
|
|
|
<MenuOption value={1} key={'menuOption_' + key++}>
|
|
|
|
<Text>{_('Configuration')}</Text>
|
|
|
|
</MenuOption>);
|
|
|
|
|
2017-05-16 22:25:19 +02:00
|
|
|
let title = 'title' in this.props && this.props.title !== null ? this.props.title : _(this.props.navState.routeName);
|
|
|
|
|
2017-05-16 21:57:09 +02:00
|
|
|
return (
|
|
|
|
<View style={{ flexDirection: 'row', padding: 10, backgroundColor: '#ffffff', alignItems: 'center' }} >
|
2017-06-06 22:01:43 +02:00
|
|
|
<Button title="☰" onPress={() => this.sideMenuButton_press()} />
|
|
|
|
<Button disabled={!this.showBackButton()} title="<" onPress={() => this.backButton_press()}></Button>
|
2017-05-16 22:25:19 +02:00
|
|
|
<Text style={{ flex:1, marginLeft: 10 }} >{title}</Text>
|
2017-06-06 22:01:43 +02:00
|
|
|
<Menu onSelect={(value) => this.menu_select(value)}>
|
2017-05-16 22:25:19 +02:00
|
|
|
<MenuTrigger>
|
|
|
|
<Text style={{ fontSize: 20 }}> ⋮ </Text>
|
|
|
|
</MenuTrigger>
|
|
|
|
<MenuOptions>
|
|
|
|
{ menuOptionComponents }
|
|
|
|
</MenuOptions>
|
|
|
|
</Menu>
|
2017-05-16 21:57:09 +02:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-06-11 23:11:14 +02:00
|
|
|
ScreenHeaderComponent.defaultProps = {
|
|
|
|
menuOptions: [],
|
|
|
|
};
|
|
|
|
|
2017-05-16 21:57:09 +02:00
|
|
|
const ScreenHeader = connect(
|
|
|
|
(state) => {
|
2017-05-16 23:46:21 +02:00
|
|
|
return { user: state.user };
|
2017-05-16 21:57:09 +02:00
|
|
|
}
|
|
|
|
)(ScreenHeaderComponent)
|
|
|
|
|
|
|
|
export { ScreenHeader };
|