2018-03-09 19:49:35 +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 { Log } = require("lib/log.js");
|
|
|
|
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 {
|
2017-07-06 21:48:17 +02:00
|
|
|
constructor() {
|
|
|
|
super();
|
2018-03-09 19:49:35 +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_ = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
backgroundColor: theme.backgroundColor,
|
|
|
|
borderTopWidth: 1,
|
|
|
|
borderTopColor: theme.dividerColor,
|
|
|
|
},
|
|
|
|
button: {
|
|
|
|
flex: 1,
|
2018-03-09 19:49:35 +02:00
|
|
|
flexDirection: "row",
|
2017-08-01 19:59:01 +02:00
|
|
|
height: 36,
|
2018-03-09 19:49:35 +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,
|
|
|
|
},
|
|
|
|
tagItemList: {
|
|
|
|
flex: 1,
|
2018-03-09 19:49:35 +02:00
|
|
|
flexDirection: "row",
|
|
|
|
flexWrap: "wrap",
|
2017-08-01 19:59:01 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
styles.folderButton = Object.assign({}, styles.button);
|
|
|
|
styles.folderButtonText = Object.assign({}, styles.buttonText);
|
|
|
|
styles.folderButtonSelected = Object.assign({}, styles.folderButton);
|
|
|
|
styles.folderButtonSelected.backgroundColor = theme.selectedColor;
|
|
|
|
styles.folderIcon = Object.assign({}, theme.icon);
|
2018-03-09 19:49:35 +02:00
|
|
|
styles.folderIcon.color = "#0072d5";
|
2017-08-01 19:59:01 +02:00
|
|
|
|
|
|
|
styles.tagButton = Object.assign({}, styles.button);
|
|
|
|
styles.tagButtonSelected = Object.assign({}, styles.tagButton);
|
|
|
|
styles.tagButtonSelected.backgroundColor = theme.selectedColor;
|
|
|
|
styles.tagButtonSelected.borderRadius = 1000;
|
|
|
|
styles.tagButtonText = Object.assign({}, styles.buttonText);
|
|
|
|
styles.tagButtonText.flex = 0;
|
|
|
|
|
|
|
|
styles.syncButton = Object.assign({}, styles.button);
|
|
|
|
styles.syncButtonText = Object.assign({}, styles.buttonText);
|
|
|
|
|
|
|
|
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 19:49:35 +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 19:49:35 +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
|
|
|
}
|
|
|
|
|
2017-07-25 20:36:52 +02:00
|
|
|
tag_press(tag) {
|
2018-03-09 19:49:35 +02:00
|
|
|
this.props.dispatch({ type: "SIDE_MENU_CLOSE" });
|
2017-07-25 20:36:52 +02:00
|
|
|
|
|
|
|
this.props.dispatch({
|
2018-03-09 19:49:35 +02:00
|
|
|
type: "NAV_GO",
|
|
|
|
routeName: "Notes",
|
2017-07-25 20:36:52 +02:00
|
|
|
tagId: tag.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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 19:49:35 +02:00
|
|
|
if (actionDone === "auth") this.props.dispatch({ type: "SIDE_MENU_CLOSE" });
|
2017-07-06 21:48:17 +02:00
|
|
|
}
|
|
|
|
|
2017-07-22 17:55:09 +02:00
|
|
|
folderItem(folder, selected) {
|
2018-03-09 19:49:35 +02:00
|
|
|
const iconComp = selected ? <Icon name="md-folder-open" style={this.styles().folderIcon} /> : <Icon name="md-folder" style={this.styles().folderIcon} />;
|
2017-08-01 19:59:01 +02:00
|
|
|
const folderButtonStyle = selected ? this.styles().folderButtonSelected : this.styles().folderButton;
|
2017-07-22 17:55:09 +02:00
|
|
|
|
|
|
|
return (
|
2018-03-09 19:49:35 +02:00
|
|
|
<TouchableOpacity
|
|
|
|
key={folder.id}
|
|
|
|
onPress={() => {
|
|
|
|
this.folder_press(folder);
|
|
|
|
}}
|
|
|
|
>
|
2017-07-22 17:55:09 +02:00
|
|
|
<View style={folderButtonStyle}>
|
2018-03-09 19:49:35 +02:00
|
|
|
{iconComp}
|
|
|
|
<Text numberOfLines={1} style={this.styles().folderButtonText}>
|
|
|
|
{Folder.displayTitle(folder)}
|
|
|
|
</Text>
|
2017-07-22 17:55:09 +02:00
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-07-25 20:36:52 +02:00
|
|
|
tagItem(tag, selected) {
|
2018-03-09 19:49:35 +02:00
|
|
|
const iconComp = <Icon name="md-pricetag" style={this.styles().folderIcon} />;
|
2017-08-01 19:59:01 +02:00
|
|
|
const tagButtonStyle = selected ? this.styles().tagButtonSelected : this.styles().tagButton;
|
2017-07-25 20:36:52 +02:00
|
|
|
|
|
|
|
return (
|
2018-03-09 19:49:35 +02:00
|
|
|
<TouchableOpacity
|
|
|
|
key={tag.id}
|
|
|
|
onPress={() => {
|
|
|
|
this.tag_press(tag);
|
|
|
|
}}
|
|
|
|
>
|
2017-07-25 20:36:52 +02:00
|
|
|
<View style={tagButtonStyle}>
|
2018-03-09 19:49:35 +02:00
|
|
|
{iconComp}
|
|
|
|
<Text numberOfLines={1} style={this.styles().tagButtonText}>
|
|
|
|
{Tag.displayTitle(tag)}
|
|
|
|
</Text>
|
2017-07-25 20:36:52 +02:00
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-07-22 17:55:09 +02:00
|
|
|
synchronizeButton(state) {
|
2018-03-09 19:49:35 +02:00
|
|
|
const title = state == "sync" ? _("Synchronise") : _("Cancel synchronisation");
|
|
|
|
const iconComp = state == "sync" ? <Icon name="md-sync" style={globalStyle.icon} /> : <Icon name="md-close" style={globalStyle.icon} />;
|
2017-07-22 17:55:09 +02:00
|
|
|
|
|
|
|
return (
|
2018-03-09 19:49:35 +02:00
|
|
|
<TouchableOpacity
|
|
|
|
key={"synchronize_button"}
|
|
|
|
onPress={() => {
|
|
|
|
this.synchronize_press();
|
|
|
|
}}
|
|
|
|
>
|
2017-08-01 19:59:01 +02:00
|
|
|
<View style={this.styles().syncButton}>
|
2018-03-09 19:49:35 +02:00
|
|
|
{iconComp}
|
2017-08-01 19:59:01 +02:00
|
|
|
<Text style={this.styles().syncButtonText}>{title}</Text>
|
2017-07-22 17:55:09 +02:00
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-07-25 20:36:52 +02:00
|
|
|
makeDivider(key) {
|
2018-03-09 19:49:35 +02:00
|
|
|
return <View style={{ marginTop: 15, marginBottom: 15, flex: -1, borderBottomWidth: 1, borderBottomColor: globalStyle.dividerColor }} key={key} />;
|
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 19:49:35 +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) {
|
2017-11-06 01:55:01 +02:00
|
|
|
const folderItems = shared.renderFolders(this.props, this.folderItem.bind(this));
|
|
|
|
items = items.concat(folderItems);
|
2018-03-09 19:49:35 +02:00
|
|
|
if (items.length) items.push(this.makeDivider("divider_1"));
|
2017-05-24 21:27:13 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 19:57:01 +02:00
|
|
|
if (this.props.tags.length) {
|
2017-11-06 01:55:01 +02:00
|
|
|
const tagItems = shared.renderTags(this.props, this.tagItem.bind(this));
|
2017-07-25 20:36:52 +02:00
|
|
|
|
2017-07-28 19:57:01 +02:00
|
|
|
items.push(
|
2017-08-01 19:59:01 +02:00
|
|
|
<View style={this.styles().tagItemList} key="tag_items">
|
2017-07-28 19:57:01 +02:00
|
|
|
{tagItems}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
|
2018-03-09 19:49:35 +02:00
|
|
|
if (tagItems.length) items.push(this.makeDivider("divider_2"));
|
2017-07-28 19:57:01 +02:00
|
|
|
}
|
2017-07-06 21:48:17 +02:00
|
|
|
|
2017-07-18 00:43:29 +02:00
|
|
|
let lines = Synchronizer.reportToLines(this.props.syncReport);
|
2018-03-09 19:49:35 +02:00
|
|
|
while (lines.length < 10) lines.push(""); // Add blank lines so that height of report text is fixed and doesn't affect scrolling
|
2017-07-18 00:43:29 +02:00
|
|
|
const syncReportText = lines.join("\n");
|
|
|
|
|
2018-03-09 19:49:35 +02:00
|
|
|
items.push(this.synchronizeButton(this.props.syncStarted ? "cancel" : "sync"));
|
2017-07-22 17:55:09 +02:00
|
|
|
|
2018-03-09 19:49:35 +02:00
|
|
|
items.push(
|
|
|
|
<Text key="sync_report" style={this.styles().syncStatus}>
|
|
|
|
{syncReportText}
|
|
|
|
</Text>
|
|
|
|
);
|
2017-07-06 21:48:17 +02:00
|
|
|
|
2018-03-09 19:49:35 +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 19:49:35 +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 19:49:35 +02:00
|
|
|
<View style={{ flex: 1, opacity: this.props.opacity }}>
|
|
|
|
<View style={{ flexDirection: "row" }}>
|
|
|
|
<Image style={{ flex: 1, height: 100 }} source={require("../images/SideMenuHeader.png")} />
|
2017-10-30 20:27:51 +02:00
|
|
|
</View>
|
|
|
|
<ScrollView scrollsToTop={false} style={this.styles().menu}>
|
2018-03-09 19:49:35 +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 19:49:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const SideMenuContent = connect(state => {
|
|
|
|
return {
|
|
|
|
folders: state.folders,
|
|
|
|
tags: state.tags,
|
|
|
|
syncStarted: state.syncStarted,
|
|
|
|
syncReport: state.syncReport,
|
|
|
|
selectedFolderId: state.selectedFolderId,
|
|
|
|
selectedTagId: state.selectedTagId,
|
|
|
|
notesParentType: state.notesParentType,
|
|
|
|
locale: state.settings.locale,
|
|
|
|
theme: state.settings.theme,
|
|
|
|
opacity: state.sideMenuOpenPercent,
|
|
|
|
};
|
|
|
|
})(SideMenuContentComponent);
|
|
|
|
|
|
|
|
module.exports = { SideMenuContent };
|