more refactorings

This commit is contained in:
zadam 2020-01-19 21:24:14 +01:00
parent 0760dc742b
commit 562c729ed6
4 changed files with 30 additions and 54 deletions

View File

@ -180,9 +180,14 @@ class AppContext {
return this.tabContexts;
}
/** @returns {TabContext} */
getTabContextById(tabId) {
return this.tabContexts.find(tc => tc.tabId === tabId);
}
/** @returns {TabContext} */
getActiveTabContext() {
return this.tabContexts.find(tc => tc.tabId === this.activeTabId);
return this.getTabContextById(this.activeTabId);
}
/** @returns {string|null} */
@ -253,14 +258,6 @@ class AppContext {
}
}
async refreshTabs(sourceTabId, noteId) {
for (const tc of this.tabContexts) {
if (tc.noteId === noteId && tc.tabId !== sourceTabId) {
await this.reloadTab(tc);
}
}
}
async reloadTab(tc) {
if (tc.note) {
noteDetailService.reloadNote(tc);

View File

@ -190,6 +190,7 @@ ws.subscribeToOutsideSyncMessages(syncData => {
.filter(sync => sync.entityName === 'attributes')
.forEach(sync => noteIdsToRefresh.add(sync.noteId));
// FIXME
for (const noteId of noteIdsToRefresh) {
appContext.refreshTabs(null, noteId);
}

View File

@ -1,4 +1,3 @@
import treeService from "./tree.js";
import protectedSessionHolder from "./protected_session_holder.js";
import server from "./server.js";
import bundleService from "./bundle.js";
@ -44,10 +43,6 @@ class TabContext extends Component {
/** @property {NoteFull} */
this.note = await noteDetailService.loadNote(noteId);
this.tabRow.updateTab(this.$tab[0], {title: this.note.title});
this.setupClasses();
//this.cleanup(); // esp. on windows autocomplete is not getting closed automatically
setTimeout(async () => {
@ -70,39 +65,12 @@ class TabContext extends Component {
this.trigger('tabNoteSwitched', {tabId: this.tabId});
}
async show() {
}
hide() {
// FIXME
}
isActive() {
return this.tabId === this.tabRow.activeTabId;
}
async remove() {
await this.trigger('beforeTabRemove', {tabId: this.tabId}, true);
this.trigger('tabRemoved', {tabId: this.tabId});
}
setupClasses() {
for (const clazz of Array.from(this.$tab[0].classList)) { // create copy to safely iterate over while removing classes
if (clazz !== 'note-tab') {
this.$tab.removeClass(clazz);
}
}
this.$tab.addClass(this.note.cssClass);
this.$tab.addClass(utils.getNoteTypeClass(this.note.type));
this.$tab.addClass(utils.getMimeTypeClass(this.note.mime));
}
async activate() {
await this.tabRow.activateTab(this.$tab[0]);
}
async saveNote() {
return; // FIXME
@ -125,19 +93,6 @@ class TabContext extends Component {
if (this.note.isProtected) {
protectedSessionHolder.touchProtectedSession();
}
// FIXME trigger "noteSaved" event so that title indicator is triggered
this.eventReceived('noteSaved');
}
async saveNoteIfChanged() {
if (this.isNoteChanged) {
await this.saveNote();
appContext.refreshTabs(this.tabId, this.note.noteId);
}
}
getTabState() {

File diff suppressed because one or more lines are too long