1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Disabled editor when no note is loaded

This commit is contained in:
Laurent Cozic 2017-11-10 17:58:17 +00:00
parent 5ddd1fc1b2
commit e2cfd8a5af
3 changed files with 47 additions and 13 deletions

View File

@ -69,11 +69,26 @@ class NoteListComponent extends React.Component {
render() {
const theme = themeStyle(this.props.theme);
const style = this.props.style;
if (!this.props.notes.length) {
const padding = 10;
const emptyDivStyle = Object.assign({
padding: padding + 'px',
fontSize: theme.fontSize,
color: theme.color,
backgroundColor: theme.backgroundColor,
fontFamily: theme.fontFamily,
}, style);
emptyDivStyle.width = emptyDivStyle.width - padding * 2;
emptyDivStyle.height = emptyDivStyle.height - padding * 2;
return <div style={emptyDivStyle}>{_('No notes in here. Create one by clicking on "New note".')}</div>
}
return (
<ItemList
itemHeight={this.props.itemHeight}
style={this.props.style}
style={style}
className={"note-list"}
items={this.props.notes}
itemRenderer={ (index, item) => { return this.itemRenderer(index, item, theme) } }

View File

@ -17,8 +17,7 @@ class NoteTextComponent extends React.Component {
super();
this.state = {
note: Note.new(),
mode: 'view',
note: null,
noteMetadata: '',
showNoteMetadata: false,
folder: null,
@ -57,7 +56,21 @@ class NoteTextComponent extends React.Component {
}
async componentWillMount() {
await shared.initState(this);
let note = null;
if (this.props.noteId) {
note = await Note.load(this.props.noteId);
}
const folder = note ? Folder.byId(this.props.folders, note.parent_id) : null;
this.setState({
lastSavedNote: Object.assign({}, note),
note: note,
folder: folder,
isLoading: false,
});
this.lastLoadedNoteId_ = note ? note.id : null;
}
componentWillUnmount() {
@ -94,10 +107,15 @@ class NoteTextComponent extends React.Component {
const note = noteId ? await Note.load(noteId) : null;
if (noteId !== this.lastLoadedNoteId_) return; // Race condition - current note was changed while this one was loading
// If we are loading nothing (noteId == null), make sure to
// set webviewReady to false too because the webview component
// is going to be removed in render().
const webviewReady = this.webview_ && this.state.webviewReady && noteId;
this.setState({
note: note,
lastSavedNote: Object.assign({}, note),
mode: 'view',
webviewReady: webviewReady,
});
}
}
@ -148,13 +166,6 @@ class NoteTextComponent extends React.Component {
this.saveOneProperty('body', newBody);
} else if (msg.toLowerCase().indexOf('http') === 0) {
require('electron').shell.openExternal(msg);
} else if (msg === 'editNote') {
const lineIndex = arg0 && arg0.length ? arg0[0] : 0;
this.webview_ref(null);
this.setState({
mode: 'edit',
webviewReady: false,
});
} else if (msg === 'percentScroll') {
this.ignoreNextEditorScroll_ = true;
this.setEditorPercentScroll(arg0);
@ -274,6 +285,14 @@ class NoteTextComponent extends React.Component {
const body = note ? note.body : '';
const theme = themeStyle(this.props.theme);
if (!note) {
const emptyDivStyle = Object.assign({
backgroundColor: 'black',
opacity: 0.1,
}, style);
return <div style={emptyDivStyle}></div>
}
const viewerStyle = {
width: Math.floor(style.width / 2),
height: style.height,

View File

@ -148,7 +148,7 @@ class MdToHtml {
let attrs = t.attrs ? t.attrs : [];
const isCodeBlock = tag === 'code' && t.block;
if (t.map) attrs.push(['data-map', t.map.join(':')]);
// if (t.map) attrs.push(['data-map', t.map.join(':')]);
if (tag && t.type.indexOf('_open') >= 0) {
openTag = tag;