mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
71efff6827
* Update eslint config * Applied linter to lib * Applied eslint config to CliClient/app * Removed prettier due to https://github.com/prettier/prettier/pull/4765 * First pass on test units * Applied linter config to test units * Applied eslint config to clipper * Applied to plugin dir * Applied to root of ElectronClient * Applied on RN root * Applied on CLI root * Applied on Clipper root * Applied config to tools * test hook * test hook * test hook * Added pre-commit hook * Applied rule no-trailing-spaces * Make sure root packages are installed when installing sub-dir * Added doc
64 lines
1.7 KiB
JavaScript
64 lines
1.7 KiB
JavaScript
const Note = require('lib/models/Note.js');
|
|
const TextWidget = require('tkwidgets/TextWidget.js');
|
|
const { _ } = require('lib/locale.js');
|
|
|
|
class NoteWidget extends TextWidget {
|
|
constructor() {
|
|
super();
|
|
this.noteId_ = 0;
|
|
this.note_ = null;
|
|
this.notes_ = [];
|
|
this.lastLoadedNoteId_ = null;
|
|
}
|
|
|
|
get notes() {
|
|
return this.notes_;
|
|
}
|
|
|
|
set notes(v) {
|
|
// If the note collection has changed it means the current note might
|
|
// have changed or has been deleted, so refresh the note.
|
|
this.notes_ = v;
|
|
this.reloadNote();
|
|
}
|
|
|
|
get noteId() {
|
|
return this.noteId_;
|
|
}
|
|
|
|
set noteId(v) {
|
|
this.noteId_ = v;
|
|
this.note_ = null;
|
|
this.reloadNote();
|
|
}
|
|
|
|
welcomeText() {
|
|
return _('Welcome to Joplin!\n\nType `:help shortcuts` for the list of keyboard shortcuts, or just `:help` for usage information.\n\nFor example, to create a notebook press `mb`; to create a note press `mn`.');
|
|
}
|
|
|
|
reloadNote() {
|
|
if (!this.noteId_ && !this.notes.length) {
|
|
this.text = this.welcomeText();
|
|
this.scrollTop = 0;
|
|
} else if (this.noteId_) {
|
|
this.doAsync('loadNote', async () => {
|
|
this.note_ = await Note.load(this.noteId_);
|
|
|
|
if (this.note_ && this.note_.encryption_applied) {
|
|
this.text = _('One or more items are currently encrypted and you may need to supply a master password. To do so please type `e2ee decrypt`. If you have already supplied the password, the encrypted items are being decrypted in the background and will be available soon.');
|
|
} else {
|
|
this.text = this.note_ ? this.note_.title + '\n\n' + this.note_.body : '';
|
|
}
|
|
|
|
if (this.lastLoadedNoteId_ !== this.noteId_) this.scrollTop = 0;
|
|
this.lastLoadedNoteId_ = this.noteId_;
|
|
});
|
|
} else {
|
|
this.text = '';
|
|
this.scrollTop = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = NoteWidget;
|