2017-11-06 18:35:04 +00:00
|
|
|
const React = require('react');
|
|
|
|
const { connect } = require('react-redux');
|
2017-11-06 20:54:58 +00:00
|
|
|
const { Header } = require('./Header.min.js');
|
2017-11-06 18:35:04 +00:00
|
|
|
const { SideBar } = require('./SideBar.min.js');
|
|
|
|
const { NoteList } = require('./NoteList.min.js');
|
|
|
|
const { NoteText } = require('./NoteText.min.js');
|
2017-11-08 17:51:55 +00:00
|
|
|
const { PromptDialog } = require('./PromptDialog.min.js');
|
|
|
|
const { Setting } = require('lib/models/setting.js');
|
|
|
|
const { Note } = require('lib/models/note.js');
|
2017-11-08 21:22:24 +00:00
|
|
|
const { Folder } = require('lib/models/folder.js');
|
2017-11-06 20:54:58 +00:00
|
|
|
const { themeStyle } = require('../theme.js');
|
2017-11-08 17:51:55 +00:00
|
|
|
const { _ } = require('lib/locale.js');
|
2017-11-07 21:11:14 +00:00
|
|
|
const layoutUtils = require('lib/layout-utils.js');
|
2017-11-08 17:51:55 +00:00
|
|
|
const { bridge } = require('electron').remote.require('./bridge');
|
2017-11-06 18:35:04 +00:00
|
|
|
|
|
|
|
class MainScreenComponent extends React.Component {
|
|
|
|
|
2017-11-08 17:51:55 +00:00
|
|
|
componentWillMount() {
|
|
|
|
this.setState({ newNotePromptVisible: false });
|
2017-11-08 21:22:24 +00:00
|
|
|
this.setState({ newFolderPromptVisible: false });
|
2017-11-08 17:51:55 +00:00
|
|
|
}
|
|
|
|
|
2017-11-06 18:35:04 +00:00
|
|
|
render() {
|
|
|
|
const style = this.props.style;
|
2017-11-06 20:54:58 +00:00
|
|
|
const theme = themeStyle(this.props.theme);
|
|
|
|
|
|
|
|
const headerStyle = {
|
|
|
|
width: style.width,
|
|
|
|
};
|
|
|
|
|
|
|
|
const rowHeight = style.height - theme.headerHeight;
|
2017-11-06 18:35:04 +00:00
|
|
|
|
2017-11-07 21:11:14 +00:00
|
|
|
const sideBarStyle = {
|
2017-11-09 22:44:10 +00:00
|
|
|
width: Math.floor(layoutUtils.size(style.width * .2, 100, 300)),
|
2017-11-06 20:54:58 +00:00
|
|
|
height: rowHeight,
|
2017-11-06 18:35:04 +00:00
|
|
|
display: 'inline-block',
|
|
|
|
verticalAlign: 'top',
|
|
|
|
};
|
|
|
|
|
2017-11-07 21:11:14 +00:00
|
|
|
const noteListStyle = {
|
2017-11-09 22:44:10 +00:00
|
|
|
width: Math.floor(layoutUtils.size(style.width * .2, 100, 300)),
|
2017-11-06 20:54:58 +00:00
|
|
|
height: rowHeight,
|
2017-11-06 18:35:04 +00:00
|
|
|
display: 'inline-block',
|
|
|
|
verticalAlign: 'top',
|
|
|
|
};
|
|
|
|
|
2017-11-07 21:11:14 +00:00
|
|
|
const noteTextStyle = {
|
2017-11-09 22:44:10 +00:00
|
|
|
width: Math.floor(layoutUtils.size(style.width - sideBarStyle.width - noteListStyle.width, 0)),
|
2017-11-06 20:54:58 +00:00
|
|
|
height: rowHeight,
|
2017-11-06 18:35:04 +00:00
|
|
|
display: 'inline-block',
|
|
|
|
verticalAlign: 'top',
|
|
|
|
};
|
|
|
|
|
2017-11-08 17:51:55 +00:00
|
|
|
const promptStyle = {
|
|
|
|
width: style.width,
|
|
|
|
height: style.height,
|
|
|
|
};
|
|
|
|
|
|
|
|
const headerButtons = [
|
|
|
|
{
|
|
|
|
title: _('New note'),
|
|
|
|
onClick: () => {
|
|
|
|
this.setState({ newNotePromptVisible: true });
|
|
|
|
},
|
2017-11-08 22:23:26 +00:00
|
|
|
iconName: 'ion-document',
|
2017-11-08 21:22:24 +00:00
|
|
|
}, {
|
|
|
|
title: _('New notebook'),
|
|
|
|
onClick: () => {
|
|
|
|
this.setState({ newFolderPromptVisible: true });
|
|
|
|
},
|
2017-11-08 22:23:26 +00:00
|
|
|
iconName: 'ion-android-folder-open',
|
2017-11-08 17:51:55 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2017-11-08 21:22:24 +00:00
|
|
|
const newNotePromptOnClose = async (answer) => {
|
|
|
|
if (answer) {
|
|
|
|
const folderId = Setting.value('activeFolderId');
|
|
|
|
if (!folderId) return;
|
|
|
|
|
|
|
|
const note = await Note.save({
|
|
|
|
title: answer,
|
|
|
|
parent_id: folderId,
|
|
|
|
});
|
|
|
|
Note.updateGeolocation(note.id);
|
2017-11-08 17:51:55 +00:00
|
|
|
|
2017-11-08 21:22:24 +00:00
|
|
|
this.props.dispatch({
|
|
|
|
type: 'NOTE_SELECT',
|
|
|
|
id: note.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({ newNotePromptVisible: false });
|
|
|
|
}
|
2017-11-08 17:51:55 +00:00
|
|
|
|
2017-11-08 21:22:24 +00:00
|
|
|
const newFolderPromptOnClose = async (answer) => {
|
|
|
|
if (answer) {
|
|
|
|
let folder = null;
|
|
|
|
try {
|
|
|
|
folder = await Folder.save({ title: answer }, { userSideValidation: true });
|
|
|
|
} catch (error) {
|
|
|
|
bridge().showErrorMessageBox(error.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.props.dispatch({
|
|
|
|
type: 'FOLDER_SELECT',
|
|
|
|
id: folder.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({ newFolderPromptVisible: false });
|
2017-11-08 17:51:55 +00:00
|
|
|
}
|
|
|
|
|
2017-11-06 18:35:04 +00:00
|
|
|
return (
|
|
|
|
<div style={style}>
|
2017-11-08 21:22:24 +00:00
|
|
|
<PromptDialog style={promptStyle} onClose={(answer) => newNotePromptOnClose(answer)} message={_('Note title:')} visible={this.state.newNotePromptVisible}/>
|
|
|
|
<PromptDialog style={promptStyle} onClose={(answer) => newFolderPromptOnClose(answer)} message={_('Notebook title:')} visible={this.state.newFolderPromptVisible}/>
|
2017-11-08 17:51:55 +00:00
|
|
|
<Header style={headerStyle} showBackButton={false} buttons={headerButtons} />
|
2017-11-06 20:54:58 +00:00
|
|
|
<SideBar style={sideBarStyle} />
|
|
|
|
<NoteList itemHeight={40} style={noteListStyle} />
|
|
|
|
<NoteText style={noteTextStyle} />
|
2017-11-06 18:35:04 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => {
|
2017-11-06 20:54:58 +00:00
|
|
|
return {
|
|
|
|
theme: state.theme,
|
|
|
|
};
|
2017-11-06 18:35:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const MainScreen = connect(mapStateToProps)(MainScreenComponent);
|
|
|
|
|
|
|
|
module.exports = { MainScreen };
|