2018-03-09 22:59:12 +02:00
|
|
|
const React = require('react'); const Component = React.Component;
|
|
|
|
const { TouchableOpacity , Button, Text, Image, StyleSheet, ScrollView, View } = require('react-native');
|
|
|
|
const { connect } = require('react-redux');
|
|
|
|
const Icon = require('react-native-vector-icons/Ionicons').default;
|
|
|
|
const Tag = require('lib/models/Tag.js');
|
|
|
|
const Note = require('lib/models/Note.js');
|
|
|
|
const Folder = require('lib/models/Folder.js');
|
|
|
|
const Setting = require('lib/models/Setting.js');
|
|
|
|
const { FoldersScreenUtils } = require('lib/folders-screen-utils.js');
|
|
|
|
const { Synchronizer } = require('lib/synchronizer.js');
|
|
|
|
const { reg } = require('lib/registry.js');
|
|
|
|
const { _ } = require('lib/locale.js');
|
|
|
|
const { globalStyle, themeStyle } = require('lib/components/global-style.js');
|
|
|
|
const shared = require('lib/components/shared/side-menu-shared.js');
|
2017-05-24 21:27:13 +02:00
|
|
|
|
|
|
|
class SideMenuContentComponent extends Component {
|
2018-03-09 22:59:12 +02:00
|
|
|
|
2017-07-06 21:48:17 +02:00
|
|
|
constructor() {
|
|
|
|
super();
|
2018-03-09 22:59:12 +02:00
|
|
|
this.state = { syncReportText: '',
|
2017-07-25 20:36:52 +02:00
|
|
|
//width: 0,
|
|
|
|
};
|
2017-08-01 19:59:01 +02:00
|
|
|
this.styles_ = {};
|
2019-03-14 00:42:16 +02:00
|
|
|
|
|
|
|
this.tagButton_press = this.tagButton_press.bind(this);
|
2017-08-01 19:59:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
styles() {
|
|
|
|
const theme = themeStyle(this.props.theme);
|
|
|
|
|
|
|
|
if (this.styles_[this.props.theme]) return this.styles_[this.props.theme];
|
|
|
|
this.styles_ = {};
|
|
|
|
|
|
|
|
let styles = {
|
|
|
|
menu: {
|
|
|
|
flex: 1,
|
2019-02-15 01:09:21 +02:00
|
|
|
backgroundColor: theme.backgroundColor
|
2017-08-01 19:59:01 +02:00
|
|
|
},
|
|
|
|
button: {
|
|
|
|
flex: 1,
|
2018-03-09 22:59:12 +02:00
|
|
|
flexDirection: 'row',
|
2017-08-01 19:59:01 +02:00
|
|
|
height: 36,
|
2018-03-09 22:59:12 +02:00
|
|
|
alignItems: 'center',
|
2017-08-01 19:59:01 +02:00
|
|
|
paddingLeft: theme.marginLeft,
|
|
|
|
paddingRight: theme.marginRight,
|
|
|
|
},
|
|
|
|
buttonText: {
|
|
|
|
flex: 1,
|
|
|
|
color: theme.color,
|
|
|
|
paddingLeft: 10,
|
|
|
|
fontSize: theme.fontSize,
|
|
|
|
},
|
|
|
|
syncStatus: {
|
|
|
|
paddingLeft: theme.marginLeft,
|
|
|
|
paddingRight: theme.marginRight,
|
|
|
|
color: theme.colorFaded,
|
|
|
|
fontSize: theme.fontSizeSmaller,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
styles.folderButton = Object.assign({}, styles.button);
|
2018-05-09 13:39:17 +02:00
|
|
|
styles.folderButton.paddingLeft = 0;
|
2017-08-01 19:59:01 +02:00
|
|
|
styles.folderButtonText = Object.assign({}, styles.buttonText);
|
|
|
|
styles.folderButtonSelected = Object.assign({}, styles.folderButton);
|
|
|
|
styles.folderButtonSelected.backgroundColor = theme.selectedColor;
|
|
|
|
styles.folderIcon = Object.assign({}, theme.icon);
|
2018-05-09 13:39:17 +02:00
|
|
|
styles.folderIcon.color = theme.colorFaded;//'#0072d5';
|
|
|
|
styles.folderIcon.paddingTop = 3;
|
2017-08-01 19:59:01 +02:00
|
|
|
|
2019-03-14 00:42:16 +02:00
|
|
|
styles.sideButton = Object.assign({}, styles.button);
|
|
|
|
styles.sideButtonText = Object.assign({}, styles.buttonText);
|
2017-08-01 19:59:01 +02:00
|
|
|
|
|
|
|
this.styles_[this.props.theme] = StyleSheet.create(styles);
|
|
|
|
return this.styles_[this.props.theme];
|
2017-07-06 21:48:17 +02:00
|
|
|
}
|
|
|
|
|
2017-05-24 21:27:13 +02:00
|
|
|
folder_press(folder) {
|
2018-03-09 22:59:12 +02:00
|
|
|
this.props.dispatch({ type: 'SIDE_MENU_CLOSE' });
|
2017-05-24 22:11:37 +02:00
|
|
|
|
2017-07-25 20:09:01 +02:00
|
|
|
this.props.dispatch({
|
2018-03-09 22:59:12 +02:00
|
|
|
type: 'NAV_GO',
|
|
|
|
routeName: 'Notes',
|
2017-07-25 20:09:01 +02:00
|
|
|
folderId: folder.id,
|
|
|
|
});
|
2017-05-24 21:27:13 +02:00
|
|
|
}
|
|
|
|
|
2018-05-09 13:39:17 +02:00
|
|
|
folder_togglePress(folder) {
|
|
|
|
this.props.dispatch({
|
|
|
|
type: 'FOLDER_TOGGLE',
|
|
|
|
id: folder.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-14 00:42:16 +02:00
|
|
|
tagButton_press() {
|
2018-03-09 22:59:12 +02:00
|
|
|
this.props.dispatch({ type: 'SIDE_MENU_CLOSE' });
|
2017-07-25 20:36:52 +02:00
|
|
|
|
|
|
|
this.props.dispatch({
|
2018-03-09 22:59:12 +02:00
|
|
|
type: 'NAV_GO',
|
2019-03-14 00:42:16 +02:00
|
|
|
routeName: 'Tags',
|
2017-07-25 20:36:52 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-07-06 21:48:17 +02:00
|
|
|
async synchronize_press() {
|
2017-11-06 23:11:15 +02:00
|
|
|
const actionDone = await shared.synchronize_press(this);
|
2018-03-09 22:59:12 +02:00
|
|
|
if (actionDone === 'auth') this.props.dispatch({ type: 'SIDE_MENU_CLOSE' });
|
2017-07-06 21:48:17 +02:00
|
|
|
}
|
|
|
|
|
2018-05-09 13:39:17 +02:00
|
|
|
folderItem(folder, selected, hasChildren, depth) {
|
|
|
|
const theme = themeStyle(this.props.theme);
|
2017-07-22 17:55:09 +02:00
|
|
|
|
2018-05-09 13:39:17 +02:00
|
|
|
const folderButtonStyle = {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
height: 36,
|
|
|
|
alignItems: 'center',
|
|
|
|
paddingLeft: theme.marginLeft,
|
|
|
|
paddingRight: theme.marginRight,
|
|
|
|
};
|
|
|
|
if (selected) folderButtonStyle.backgroundColor = theme.selectedColor;
|
|
|
|
folderButtonStyle.paddingLeft = depth * 10;
|
|
|
|
|
|
|
|
const iconWrapperStyle = { paddingLeft: 10, paddingRight: 10 };
|
|
|
|
if (selected) iconWrapperStyle.backgroundColor = theme.selectedColor;
|
|
|
|
|
|
|
|
const iconName = this.props.collapsedFolderIds.indexOf(folder.id) >= 0 ? 'md-arrow-dropdown' : 'md-arrow-dropup';
|
|
|
|
const iconComp = <Icon name={iconName} style={this.styles().folderIcon} />
|
|
|
|
|
|
|
|
const iconWrapper = !hasChildren ? null : (
|
|
|
|
<TouchableOpacity style={iconWrapperStyle} folderid={folder.id} onPress={() => { if (hasChildren) this.folder_togglePress(folder) }}>
|
|
|
|
{ iconComp }
|
2017-07-22 17:55:09 +02:00
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
2018-05-09 13:39:17 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<View key={folder.id} style={{ flex: 1, flexDirection: 'row' }}>
|
|
|
|
<TouchableOpacity style={{ flex: 1 }} onPress={() => { this.folder_press(folder) }}>
|
|
|
|
<View style={folderButtonStyle}>
|
|
|
|
<Text numberOfLines={1} style={this.styles().folderButtonText}>{Folder.displayTitle(folder)}</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
{ iconWrapper }
|
|
|
|
</View>
|
|
|
|
);
|
2017-07-22 17:55:09 +02:00
|
|
|
}
|
|
|
|
|
2019-03-14 00:42:16 +02:00
|
|
|
synchronizeButton(state) {
|
|
|
|
const theme = themeStyle(this.props.theme);
|
|
|
|
|
|
|
|
const title = state == 'sync' ? _('Synchronise') : _('Cancel synchronisation');
|
|
|
|
const iconComp = state == 'sync' ? <Icon name='md-sync' style={theme.icon} /> : <Icon name='md-close' style={theme.icon} />;
|
2017-07-25 20:36:52 +02:00
|
|
|
|
|
|
|
return (
|
2019-03-14 00:42:16 +02:00
|
|
|
<TouchableOpacity key={'synchronize_button'} onPress={() => { this.synchronize_press() }}>
|
|
|
|
<View style={this.styles().sideButton}>
|
2018-03-09 22:59:12 +02:00
|
|
|
{ iconComp }
|
2019-03-14 00:42:16 +02:00
|
|
|
<Text style={this.styles().sideButtonText}>{title}</Text>
|
2017-07-25 20:36:52 +02:00
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-03-14 00:42:16 +02:00
|
|
|
tagButton() {
|
2018-03-26 19:52:49 +02:00
|
|
|
const theme = themeStyle(this.props.theme);
|
2017-07-22 17:55:09 +02:00
|
|
|
|
|
|
|
return (
|
2019-03-14 00:42:16 +02:00
|
|
|
<TouchableOpacity key={'tag_button'} onPress={this.tagButton_press}>
|
|
|
|
<View style={this.styles().sideButton}>
|
|
|
|
<Icon name='md-pricetag' style={theme.icon} />
|
|
|
|
<Text style={this.styles().sideButtonText}>Tags</Text>
|
2017-07-22 17:55:09 +02:00
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-07-25 20:36:52 +02:00
|
|
|
makeDivider(key) {
|
2018-03-09 22:59:12 +02:00
|
|
|
return <View style={{ marginTop: 15, marginBottom: 15, flex: -1, borderBottomWidth: 1, borderBottomColor: globalStyle.dividerColor }} key={key}></View>
|
2017-07-25 20:36:52 +02:00
|
|
|
}
|
|
|
|
|
2017-05-24 21:27:13 +02:00
|
|
|
render() {
|
2017-07-06 21:48:17 +02:00
|
|
|
let items = [];
|
2017-07-22 17:55:09 +02:00
|
|
|
|
2017-10-30 20:27:51 +02:00
|
|
|
const theme = themeStyle(this.props.theme);
|
|
|
|
|
2017-07-22 17:55:09 +02:00
|
|
|
// HACK: inner height of ScrollView doesn't appear to be calculated correctly when
|
|
|
|
// using padding. So instead creating blank elements for padding bottom and top.
|
2018-03-09 22:59:12 +02:00
|
|
|
items.push(<View style={{ height: globalStyle.marginTop }} key='bottom_top_hack'/>);
|
2017-07-22 17:55:09 +02:00
|
|
|
|
2017-07-28 19:57:01 +02:00
|
|
|
if (this.props.folders.length) {
|
2019-01-26 20:04:32 +02:00
|
|
|
const result = shared.renderFolders(this.props, this.folderItem.bind(this));
|
2019-02-03 18:15:07 +02:00
|
|
|
const folderItems = result.items;
|
2017-11-06 01:55:01 +02:00
|
|
|
items = items.concat(folderItems);
|
2017-05-24 21:27:13 +02:00
|
|
|
}
|
|
|
|
|
2019-03-14 00:42:16 +02:00
|
|
|
items.push(this.makeDivider('divider_1'));
|
|
|
|
|
|
|
|
items.push(this.tagButton());
|
2017-07-28 19:57:01 +02:00
|
|
|
|
2019-03-14 00:42:16 +02:00
|
|
|
items.push(this.makeDivider('divider_tag_bottom'));
|
2017-07-06 21:48:17 +02:00
|
|
|
|
2017-07-18 00:43:29 +02:00
|
|
|
let lines = Synchronizer.reportToLines(this.props.syncReport);
|
|
|
|
const syncReportText = lines.join("\n");
|
|
|
|
|
2018-06-10 18:43:24 +02:00
|
|
|
let decryptionReportText = '';
|
|
|
|
if (this.props.decryptionWorker && this.props.decryptionWorker.state !== 'idle' && this.props.decryptionWorker.itemCount) {
|
|
|
|
decryptionReportText = _('Decrypting items: %d/%d', this.props.decryptionWorker.itemIndex + 1, this.props.decryptionWorker.itemCount);
|
|
|
|
}
|
|
|
|
|
2018-11-14 00:27:58 +02:00
|
|
|
let resourceFetcherText = '';
|
|
|
|
if (this.props.resourceFetcher && this.props.resourceFetcher.toFetchCount) {
|
2019-05-22 16:56:07 +02:00
|
|
|
resourceFetcherText = _('Fetching resources: %d/%d', this.props.resourceFetcher.fetchingCount, this.props.resourceFetcher.toFetchCount);
|
2018-11-14 00:27:58 +02:00
|
|
|
}
|
|
|
|
|
2018-06-10 18:43:24 +02:00
|
|
|
let fullReport = [];
|
|
|
|
if (syncReportText) fullReport.push(syncReportText);
|
2018-11-14 00:27:58 +02:00
|
|
|
// if (fullReport.length) fullReport.push('');
|
2019-05-22 16:56:07 +02:00
|
|
|
if (resourceFetcherText) fullReport.push(resourceFetcherText);
|
2018-06-10 18:43:24 +02:00
|
|
|
if (decryptionReportText) fullReport.push(decryptionReportText);
|
|
|
|
|
|
|
|
while (fullReport.length < 12) fullReport.push(''); // Add blank lines so that height of report text is fixed and doesn't affect scrolling
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
items.push(this.synchronizeButton(this.props.syncStarted ? 'cancel' : 'sync'));
|
2017-07-22 17:55:09 +02:00
|
|
|
|
2018-06-10 18:43:24 +02:00
|
|
|
items.push(<Text key='sync_report' style={this.styles().syncStatus}>{fullReport.join('\n')}</Text>);
|
2017-07-06 21:48:17 +02:00
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
items.push(<View style={{ height: globalStyle.marginBottom }} key='bottom_padding_hack'/>);
|
2017-07-06 21:48:17 +02:00
|
|
|
|
2017-10-30 20:27:51 +02:00
|
|
|
let style = {
|
2018-03-09 22:59:12 +02:00
|
|
|
flex:1,
|
2017-10-30 20:27:51 +02:00
|
|
|
borderRightWidth: 1,
|
|
|
|
borderRightColor: globalStyle.dividerColor,
|
|
|
|
backgroundColor: theme.backgroundColor,
|
|
|
|
};
|
|
|
|
|
2017-05-24 21:27:13 +02:00
|
|
|
return (
|
2017-10-30 20:27:51 +02:00
|
|
|
<View style={style}>
|
2018-03-09 22:59:12 +02:00
|
|
|
<View style={{flex:1, opacity: this.props.opacity}}>
|
2017-10-30 20:27:51 +02:00
|
|
|
<ScrollView scrollsToTop={false} style={this.styles().menu}>
|
2018-03-09 22:59:12 +02:00
|
|
|
{ items }
|
2017-10-30 20:27:51 +02:00
|
|
|
</ScrollView>
|
2017-07-22 17:55:09 +02:00
|
|
|
</View>
|
|
|
|
</View>
|
2017-05-24 21:27:13 +02:00
|
|
|
);
|
|
|
|
}
|
2018-03-09 22:59:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const SideMenuContent = connect(
|
|
|
|
(state) => {
|
|
|
|
return {
|
|
|
|
folders: state.folders,
|
|
|
|
syncStarted: state.syncStarted,
|
|
|
|
syncReport: state.syncReport,
|
|
|
|
selectedFolderId: state.selectedFolderId,
|
|
|
|
selectedTagId: state.selectedTagId,
|
|
|
|
notesParentType: state.notesParentType,
|
|
|
|
locale: state.settings.locale,
|
|
|
|
theme: state.settings.theme,
|
2019-03-14 00:42:16 +02:00
|
|
|
// Don't do the opacity animation as it means re-rendering the list multiple times
|
|
|
|
// opacity: state.sideMenuOpenPercent,
|
2018-05-09 13:39:17 +02:00
|
|
|
collapsedFolderIds: state.collapsedFolderIds,
|
2018-06-10 18:43:24 +02:00
|
|
|
decryptionWorker: state.decryptionWorker,
|
2018-11-14 00:27:58 +02:00
|
|
|
resourceFetcher: state.resourceFetcher,
|
2018-03-09 22:59:12 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
)(SideMenuContentComponent)
|
|
|
|
|
|
|
|
module.exports = { SideMenuContent };
|