Notes/src/public/javascripts/widgets/tab_aware_widget.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-01-12 19:05:09 +01:00
import BasicWidget from "./basic_widget.js";
export default class TabAwareWidget extends BasicWidget {
setTabContextListener({tabContext}) {
2020-01-12 19:05:09 +01:00
/** @var {TabContext} */
2020-01-16 22:44:36 +01:00
this.tabContext = tabContext;
2020-01-18 18:01:16 +01:00
this.noteSwitched();
2020-01-12 19:05:09 +01:00
}
isTab(tabId) {
return this.tabContext && this.tabContext.tabId === tabId;
}
isNote(noteId) {
return this.tabContext && this.tabContext.note && this.tabContext.note.noteId === noteId;
}
2020-01-18 18:01:16 +01:00
tabNoteSwitchedListener({tabId}) {
if (this.isTab(tabId)) {
2020-01-18 18:01:16 +01:00
this.noteSwitched();
}
}
noteSwitched() {
this.refresh();
}
2020-01-18 18:01:16 +01:00
activeTabChanged() {
this.refresh();
}
2020-01-19 11:37:24 +01:00
refresh() {
if (this.tabContext && this.tabContext.note) {
this.toggle(true);
this.refreshWithNote(this.tabContext.note, this.tabContext.notePath);
2020-01-19 11:37:24 +01:00
}
else {
this.toggle(false);
}
}
2020-01-19 13:19:40 +01:00
refreshWithNote(note) {}
2020-01-12 19:05:09 +01:00
activeTabChangedListener() {
this.tabContext = this.appContext.getActiveTabContext();
this.activeTabChanged();
}
}