1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/ReactNativeClient/lib/components/side-menu-content.js

139 lines
3.2 KiB
JavaScript
Raw Normal View History

2017-05-24 21:27:13 +02:00
import { connect } from 'react-redux'
2017-07-15 20:56:24 +02:00
import { TouchableOpacity , Button, Text } from 'react-native';
2017-06-24 20:06:28 +02:00
import { Log } from 'lib/log.js';
import { Note } from 'lib/models/note.js';
2017-07-15 18:14:15 +02:00
import { FoldersScreenUtils } from 'lib/components/screens/folders-utils.js'
2017-07-05 23:29:00 +02:00
import { NotesScreenUtils } from 'lib/components/screens/notes-utils.js'
2017-07-06 21:48:17 +02:00
import { reg } from 'lib/registry.js';
import { _ } from 'lib/locale.js';
2017-05-24 21:27:13 +02:00
const React = require('react');
const {
Dimensions,
StyleSheet,
ScrollView,
View,
Image,
} = require('react-native');
const { Component } = React;
const styles = StyleSheet.create({
menu: {
flex: 1,
backgroundColor: 'white',
padding: 20,
},
name: {
position: 'absolute',
left: 70,
top: 20,
},
item: {
fontSize: 14,
fontWeight: '300',
paddingTop: 5,
},
2017-07-15 20:56:24 +02:00
folderButton: {
flex: 1,
backgroundColor: "#0482E3",
paddingLeft: 20,
paddingRight: 20,
paddingTop: 14,
paddingBottom: 14,
2017-07-16 23:17:22 +02:00
marginBottom: 5,
2017-07-15 20:56:24 +02:00
},
folderButtonText: {
color: "#ffffff",
fontWeight: 'bold',
},
2017-05-24 21:27:13 +02:00
button: {
flex: 1,
textAlign: 'left',
}
});
class SideMenuContentComponent extends Component {
2017-07-06 21:48:17 +02:00
constructor() {
super();
this.state = { syncReportText: '' };
}
2017-05-24 21:27:13 +02:00
folder_press(folder) {
2017-07-08 00:25:03 +02:00
this.props.dispatch({ type: 'SIDE_MENU_CLOSE' });
2017-05-24 22:11:37 +02:00
2017-07-05 23:29:00 +02:00
NotesScreenUtils.openNoteList(folder.id);
2017-05-24 21:27:13 +02:00
}
2017-07-16 23:17:22 +02:00
async synchronizer_progress(report) {
const sync = await reg.synchronizer();
let lines = sync.reportToLines(report);
this.setState({ syncReportText: lines.join("\n") });
}
synchronizer_complete() {
FoldersScreenUtils.refreshFolders();
}
async componentWillMount() {
reg.dispatcher().on('synchronizer_progress', this.synchronizer_progress.bind(this));
reg.dispatcher().on('synchronizer_complete', this.synchronizer_complete.bind(this));
}
componentWillUnmount() {
reg.dispatcher().off('synchronizer_progress', this.synchronizer_progress.bind(this));
reg.dispatcher().off('synchronizer_complete', this.synchronizer_complete.bind(this));
}
2017-07-06 21:48:17 +02:00
async synchronize_press() {
if (reg.oneDriveApi().auth()) {
2017-07-14 21:06:01 +02:00
const sync = await reg.synchronizer()
2017-07-16 23:17:22 +02:00
sync.start();
2017-07-06 21:48:17 +02:00
} else {
2017-07-08 00:25:03 +02:00
this.props.dispatch({ type: 'SIDE_MENU_CLOSE' });
2017-07-06 21:48:17 +02:00
this.props.dispatch({
type: 'Navigation/NAVIGATE',
routeName: 'OneDriveLogin',
});
}
}
2017-05-24 21:27:13 +02:00
render() {
2017-07-06 21:48:17 +02:00
let items = [];
2017-05-24 21:27:13 +02:00
for (let i = 0; i < this.props.folders.length; i++) {
let f = this.props.folders[i];
2017-07-06 21:48:17 +02:00
let title = f.title ? f.title : '';
2017-07-15 20:56:24 +02:00
2017-07-06 21:48:17 +02:00
items.push(
2017-07-15 20:56:24 +02:00
<TouchableOpacity key={f.id} onPress={() => { this.folder_press(f) }}>
<View style={styles.folderButton}>
2017-07-16 23:17:22 +02:00
<Text numberOfLines={1} style={styles.folderButtonText}>{title}</Text>
2017-07-15 20:56:24 +02:00
</View>
</TouchableOpacity>
2017-05-24 21:27:13 +02:00
);
}
2017-07-16 00:47:11 +02:00
if (items.length) items.push(<View style={{ height: 50, flex: -1 }} key='divider_1'></View>); // DIVIDER
2017-07-06 21:48:17 +02:00
2017-07-15 20:56:24 +02:00
items.push(<Button title="Synchronize" onPress={() => { this.synchronize_press() }} key='synchronize' />);
2017-07-06 21:48:17 +02:00
2017-07-15 20:56:24 +02:00
items.push(<Text key='sync_report'>{this.state.syncReportText}</Text>);
2017-07-06 21:48:17 +02:00
2017-05-24 21:27:13 +02:00
return (
<ScrollView scrollsToTop={false} style={styles.menu}>
2017-07-06 21:48:17 +02:00
{ items }
2017-05-24 21:27:13 +02:00
</ScrollView>
);
}
};
const SideMenuContent = connect(
(state) => {
return {
folders: state.folders,
};
}
)(SideMenuContentComponent)
export { SideMenuContent };