use notePath in tabContext

This commit is contained in:
zadam 2019-05-08 20:14:41 +02:00
parent bacf163c96
commit a7a42ff4af
4 changed files with 18 additions and 13 deletions

View File

@ -53,7 +53,9 @@ async function showTree() {
showDetailPane(); showDetailPane();
noteDetailService.switchToNote(noteId, true); const notePath = await treeUtils.getNotePath(node);
noteDetailService.switchToNote(notePath);
}, },
expand: (event, data) => treeService.setExpandedToServer(data.node.data.branchId, true), expand: (event, data) => treeService.setExpandedToServer(data.node.data.branchId, true),
collapse: (event, data) => treeService.setExpandedToServer(data.node.data.branchId, false), collapse: (event, data) => treeService.setExpandedToServer(data.node.data.branchId, false),

View File

@ -77,8 +77,9 @@ class TabContext {
console.log(`Created note tab ${this.tabId} for ${this.noteId}`); console.log(`Created note tab ${this.tabId} for ${this.noteId}`);
} }
setNote(note) { setNote(note, notePath) {
this.noteId = note.noteId; this.noteId = note.noteId;
this.notePath = notePath;
this.note = note; this.note = note;
this.tab.setAttribute('data-note-id', this.noteId); this.tab.setAttribute('data-note-id', this.noteId);
this.$tabContent.attr('data-note-id', note.noteId); this.$tabContent.attr('data-note-id', note.noteId);

View File

@ -9,6 +9,7 @@ import bundleService from "./bundle.js";
import utils from "./utils.js"; import utils from "./utils.js";
import importDialog from "../dialogs/import.js"; import importDialog from "../dialogs/import.js";
import contextMenuService from "./context_menu.js"; import contextMenuService from "./context_menu.js";
import treeUtils from "./tree_utils.js";
const chromeTabsEl = document.querySelector('.chrome-tabs'); const chromeTabsEl = document.querySelector('.chrome-tabs');
const chromeTabs = new ChromeTabs(); const chromeTabs = new ChromeTabs();
@ -47,7 +48,7 @@ async function reloadAllTabs() {
for (const tabContext of tabContexts) { for (const tabContext of tabContexts) {
const note = await loadNote(tabContext.note.noteId); const note = await loadNote(tabContext.note.noteId);
await loadNoteDetailToContext(tabContext, note); await loadNoteDetailToContext(tabContext, note, tabContext.notePath);
} }
} }
@ -56,12 +57,10 @@ async function openInTab(noteId) {
await loadNoteDetail(noteId, true); await loadNoteDetail(noteId, true);
} }
async function switchToNote(noteId) { async function switchToNote(notePath) {
//if (getActiveNoteId() !== noteId) { await saveNotesIfChanged();
await saveNotesIfChanged();
await loadNoteDetail(noteId); await loadNoteDetail(notePath);
//}
} }
function getActiveNoteContent() { function getActiveNoteContent() {
@ -109,8 +108,8 @@ function showTab(tabId) {
* @param {TabContext} ctx * @param {TabContext} ctx
* @param {NoteFull} note * @param {NoteFull} note
*/ */
async function loadNoteDetailToContext(ctx, note) { async function loadNoteDetailToContext(ctx, note, notePath) {
ctx.setNote(note); ctx.setNote(note, notePath);
if (utils.isDesktop()) { if (utils.isDesktop()) {
// needs to happen after loading the note itself because it references active noteId // needs to happen after loading the note itself because it references active noteId
@ -163,7 +162,8 @@ async function loadNoteDetailToContext(ctx, note) {
} }
} }
async function loadNoteDetail(noteId, newTab = false) { async function loadNoteDetail(notePath, newTab = false) {
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
const loadedNote = await loadNote(noteId); const loadedNote = await loadNote(noteId);
let ctx; let ctx;
@ -189,7 +189,7 @@ async function loadNoteDetail(noteId, newTab = false) {
return; return;
} }
await loadNoteDetailToContext(ctx, loadedNote); await loadNoteDetailToContext(ctx, loadedNote, notePath);
} }
async function loadNote(noteId) { async function loadNote(noteId) {

View File

@ -436,7 +436,9 @@ function initFancyTree(tree) {
await setCurrentNotePathToHash(node); await setCurrentNotePathToHash(node);
noteDetailService.switchToNote(noteId); const notePath = await treeUtils.getNotePath(node);
noteDetailService.switchToNote(notePath);
showPaths(noteId, node); showPaths(noteId, node);
}, },