same note in different tabs are synced

This commit is contained in:
zadam 2019-05-20 22:25:04 +02:00
parent 48b4488a58
commit 32fae5e9e8
2 changed files with 22 additions and 5 deletions

View File

@ -41,14 +41,20 @@ async function reload() {
await loadNoteDetail(getActiveTabContext().notePath); await loadNoteDetail(getActiveTabContext().notePath);
} }
async function reloadAllTabs() { async function reloadTab(tabContext) {
for (const tabContext of tabContexts) { if (tabContext.note) {
const note = await loadNote(tabContext.note.noteId); const note = await loadNote(tabContext.note.noteId);
await loadNoteDetailToContext(tabContext, note, tabContext.notePath); await loadNoteDetailToContext(tabContext, note, tabContext.notePath);
} }
} }
async function reloadAllTabs() {
for (const tabContext of tabContexts) {
await reloadTab(tabContext);
}
}
async function openInTab(notePath) { async function openInTab(notePath) {
await loadNoteDetail(notePath, { newTab: true }); await loadNoteDetail(notePath, { newTab: true });
} }
@ -289,6 +295,14 @@ async function noteDeleted(noteId) {
} }
} }
async function refreshTabs(sourceTabId, noteId) {
for (const tc of tabContexts) {
if (tc.noteId === noteId && tc.tabId !== sourceTabId) {
await reloadTab(tc);
}
}
}
function focusOnTitle() { function focusOnTitle() {
getActiveTabContext().$noteTitle.focus(); getActiveTabContext().$noteTitle.focus();
} }
@ -322,10 +336,10 @@ function fireDetailLoaded() {
} }
messagingService.subscribeToSyncMessages(syncData => { messagingService.subscribeToSyncMessages(syncData => {
if (syncData.some(sync => sync.entityName === 'notes' && sync.entityId === getActiveNoteId())) { if (syncData.some(sync => sync.entityName === 'notes')) {
infoService.showMessage('Reloading note because of background changes'); infoService.showMessage('Reloading note because of background changes');
reload(); refreshTabs(null, sync.entityId);
} }
}); });
@ -505,5 +519,6 @@ export default {
clearOpenTabsTask, clearOpenTabsTask,
filterTabs, filterTabs,
openEmptyTab, openEmptyTab,
noteDeleted noteDeleted,
refreshTabs
}; };

View File

@ -221,6 +221,8 @@ class TabContext {
async saveNoteIfChanged() { async saveNoteIfChanged() {
if (this.isNoteChanged) { if (this.isNoteChanged) {
await this.saveNote(); await this.saveNote();
noteDetailService.refreshTabs(this.tabId, this.noteId);
} }
} }