navigation state is more nicely and completely serialized into URL

This commit is contained in:
zadam
2023-04-11 21:41:55 +02:00
parent 9e71c44c76
commit 17128c5874
12 changed files with 183 additions and 99 deletions

View File

@@ -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;