mirror of
https://github.com/zadam/trilium.git
synced 2025-10-30 18:05:55 +01:00
navigation state is more nicely and completely serialized into URL
This commit is contained in:
@@ -12,13 +12,17 @@ class NoteContext extends Component {
|
||||
constructor(ntxId = null, hoistedNoteId = 'root', mainNtxId = null) {
|
||||
super();
|
||||
|
||||
this.ntxId = ntxId || utils.randomString(4);
|
||||
this.ntxId = ntxId || this.constructor.generateNtxId();
|
||||
this.hoistedNoteId = hoistedNoteId;
|
||||
this.mainNtxId = mainNtxId;
|
||||
|
||||
this.resetViewScope();
|
||||
}
|
||||
|
||||
static generateNtxId() {
|
||||
return utils.randomString(6);
|
||||
}
|
||||
|
||||
setEmpty() {
|
||||
this.notePath = null;
|
||||
this.noteId = null;
|
||||
@@ -57,9 +61,8 @@ class NoteContext extends Component {
|
||||
utils.closeActiveDialog();
|
||||
|
||||
this.notePath = resolvedNotePath;
|
||||
({noteId: this.noteId, parentNoteId: this.parentNoteId} = treeService.getNoteIdAndParentIdFromNotePath(resolvedNotePath));
|
||||
|
||||
this.viewScope = opts.viewScope;
|
||||
({noteId: this.noteId, parentNoteId: this.parentNoteId} = treeService.getNoteIdAndParentIdFromNotePath(resolvedNotePath));
|
||||
|
||||
this.saveToRecentNotes(resolvedNotePath);
|
||||
|
||||
@@ -298,6 +301,29 @@ class NoteContext extends Component {
|
||||
// this is reset after navigating to a different note
|
||||
this.viewScope = {};
|
||||
}
|
||||
|
||||
async getNavigationTitle() {
|
||||
if (!this.note) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { note, viewScope } = this;
|
||||
|
||||
let title = viewScope.viewMode === 'default'
|
||||
? note.title
|
||||
: `${note.title}: ${viewScope.viewMode}`;
|
||||
|
||||
if (viewScope.attachmentId) {
|
||||
// assuming the attachment has been already loaded
|
||||
const attachment = await note.getAttachmentById(viewScope.attachmentId);
|
||||
|
||||
if (attachment) {
|
||||
title += `: ${attachment.title}`;
|
||||
}
|
||||
}
|
||||
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
||||
export default NoteContext;
|
||||
|
||||
Reference in New Issue
Block a user