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

133 lines
3.0 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'
import { Synchronizer } from 'lib/synchronizer.js';
2017-07-06 21:48:17 +02:00
import { reg } from 'lib/registry.js';
import { _ } from 'lib/locale.js';
2017-07-21 23:40:02 +02:00
import { globalStyle } from 'lib/components/global-style.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,
2017-07-21 23:40:02 +02:00
backgroundColor: globalStyle.backgroundColor,
2017-05-24 21:27:13 +02:00
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",
2017-07-21 23:40:02 +02:00
height: 36,
2017-07-16 23:17:22 +02:00
marginBottom: 5,
2017-07-15 20:56:24 +02:00
},
folderButtonText: {
color: "#ffffff",
fontWeight: 'bold',
2017-07-21 23:40:02 +02:00
textAlign: 'center',
textAlignVertical: 'center',
flex: 1,
2017-07-15 20:56:24 +02:00
},
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-06 21:48:17 +02:00
async synchronize_press() {
const sync = await reg.synchronizer()
if (this.props.syncStarted) {
sync.cancel();
2017-07-06 21:48:17 +02:00
} else {
if (reg.oneDriveApi().auth()) {
2017-07-19 21:15:55 +02:00
reg.scheduleSync(1);
} else {
this.props.dispatch({ type: 'SIDE_MENU_CLOSE' });
this.props.dispatch({
type: 'Navigation/NAVIGATE',
routeName: 'OneDriveLogin',
});
}
2017-07-06 21:48:17 +02:00
}
}
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-22 00:42:24 +02:00
const syncTitle = this.props.syncStarted ? _('Cancel sync') : _('Synchronize');
let lines = Synchronizer.reportToLines(this.props.syncReport);
const syncReportText = lines.join("\n");
items.push(<Button title={syncTitle} onPress={() => { this.synchronize_press() }} key='synchronize' />);
2017-07-06 21:48:17 +02:00
items.push(<Text key='sync_report'>{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,
syncStarted: state.syncStarted,
syncReport: state.syncReport,
2017-05-24 21:27:13 +02:00
};
}
)(SideMenuContentComponent)
export { SideMenuContent };