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() {
|
2017-11-10 19:18:19 +00:00
|
|
|
this.setState({
|
|
|
|
newNotePromptVisible: false,
|
|
|
|
newFolderPromptVisible: false,
|
2017-11-10 20:34:36 +00:00
|
|
|
promptOptions: null,
|
2017-11-10 19:18:19 +00:00
|
|
|
noteVisiblePanes: ['editor', 'viewer'],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleVisiblePanes() {
|
|
|
|
let panes = this.state.noteVisiblePanes.slice();
|
|
|
|
if (panes.length === 2) {
|
|
|
|
panes = ['editor'];
|
|
|
|
} else if (panes.indexOf('editor') >= 0) {
|
|
|
|
panes = ['viewer'];
|
|
|
|
} else if (panes.indexOf('viewer') >= 0) {
|
|
|
|
panes = ['editor', 'viewer'];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({ noteVisiblePanes: panes });
|
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);
|
2017-11-10 20:34:36 +00:00
|
|
|
const promptOptions = this.state.promptOptions;
|
2017-11-06 20:54:58 +00:00
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2017-11-10 20:34:36 +00:00
|
|
|
const createNewNote = async (title, isTodo) => {
|
|
|
|
const folderId = Setting.value('activeFolderId');
|
|
|
|
if (!folderId) return;
|
|
|
|
|
|
|
|
const note = await Note.save({
|
|
|
|
title: title,
|
|
|
|
parent_id: folderId,
|
|
|
|
is_todo: isTodo ? 1 : 0,
|
|
|
|
});
|
|
|
|
Note.updateGeolocation(note.id);
|
|
|
|
|
|
|
|
this.props.dispatch({
|
|
|
|
type: 'NOTE_SELECT',
|
|
|
|
id: note.id,
|
|
|
|
});
|
|
|
|
}
|
2017-11-08 21:22:24 +00:00
|
|
|
|
2017-11-10 20:34:36 +00:00
|
|
|
const headerButtons = [];
|
|
|
|
|
|
|
|
headerButtons.push({
|
|
|
|
title: _('New note'),
|
|
|
|
iconName: 'fa-file-o',
|
|
|
|
onClick: () => {
|
|
|
|
this.setState({
|
|
|
|
promptOptions: {
|
|
|
|
message: _('Note title:'),
|
|
|
|
onClose: async (answer) => {
|
|
|
|
if (answer) await createNewNote(answer, false);
|
|
|
|
this.setState({ promptOptions: null });
|
|
|
|
}
|
|
|
|
},
|
2017-11-08 21:22:24 +00:00
|
|
|
});
|
2017-11-10 20:34:36 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
headerButtons.push({
|
|
|
|
title: _('New to-do'),
|
|
|
|
iconName: 'fa-check-square-o',
|
|
|
|
onClick: () => {
|
|
|
|
this.setState({
|
|
|
|
promptOptions: {
|
|
|
|
message: _('Note title:'),
|
|
|
|
onClose: async (answer) => {
|
|
|
|
if (answer) await createNewNote(answer, true);
|
|
|
|
this.setState({ promptOptions: null });
|
|
|
|
}
|
|
|
|
},
|
2017-11-08 21:22:24 +00:00
|
|
|
});
|
2017-11-10 20:34:36 +00:00
|
|
|
},
|
|
|
|
});
|
2017-11-08 17:51:55 +00:00
|
|
|
|
2017-11-10 20:34:36 +00:00
|
|
|
headerButtons.push({
|
|
|
|
title: _('New notebook'),
|
|
|
|
iconName: 'fa-folder-o',
|
|
|
|
onClick: () => {
|
|
|
|
this.setState({
|
|
|
|
promptOptions: {
|
|
|
|
message: _('Notebook title:'),
|
|
|
|
onClose: 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({ promptOptions: null });
|
|
|
|
}
|
|
|
|
},
|
2017-11-08 21:22:24 +00:00
|
|
|
});
|
2017-11-10 20:34:36 +00:00
|
|
|
},
|
|
|
|
});
|
2017-11-08 21:22:24 +00:00
|
|
|
|
2017-11-10 20:34:36 +00:00
|
|
|
headerButtons.push({
|
|
|
|
title: _('Layout'),
|
|
|
|
iconName: 'fa-columns',
|
|
|
|
onClick: () => {
|
|
|
|
this.toggleVisiblePanes();
|
|
|
|
},
|
|
|
|
});
|
2017-11-08 17:51:55 +00:00
|
|
|
|
2017-11-06 18:35:04 +00:00
|
|
|
return (
|
|
|
|
<div style={style}>
|
2017-11-10 20:34:36 +00:00
|
|
|
<PromptDialog theme={this.props.theme} style={promptStyle} onClose={(answer) => promptOptions.onClose(answer)} message={promptOptions ? promptOptions.message : ''} visible={!!this.state.promptOptions}/>
|
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} />
|
2017-11-10 19:18:19 +00:00
|
|
|
<NoteText style={noteTextStyle} visiblePanes={this.state.noteVisiblePanes} />
|
2017-11-06 18:35:04 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => {
|
2017-11-06 20:54:58 +00:00
|
|
|
return {
|
2017-11-10 20:34:36 +00:00
|
|
|
theme: state.settings.theme,
|
2017-11-06 20:54:58 +00:00
|
|
|
};
|
2017-11-06 18:35:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const MainScreen = connect(mapStateToProps)(MainScreenComponent);
|
|
|
|
|
|
|
|
module.exports = { MainScreen };
|