2018-11-09 03:01:25 +08:00
|
|
|
import server from "./server.js";
|
2019-08-27 02:21:43 +08:00
|
|
|
import ws from "./ws.js";
|
2018-11-09 03:01:25 +08:00
|
|
|
import treeUtils from "./tree_utils.js";
|
|
|
|
import noteAutocompleteService from "./note_autocomplete.js";
|
2020-01-16 04:36:01 +08:00
|
|
|
import Component from "../widgets/component.js";
|
|
|
|
import utils from "./utils.js";
|
2018-11-09 03:01:25 +08:00
|
|
|
|
2020-01-16 04:36:01 +08:00
|
|
|
class Attributes extends Component {
|
2019-05-05 04:44:25 +08:00
|
|
|
/**
|
2020-01-16 04:36:01 +08:00
|
|
|
* @param {AppContext} appContext
|
|
|
|
* @param {TabContext} tabContext
|
2019-05-05 04:44:25 +08:00
|
|
|
*/
|
2020-01-16 04:36:01 +08:00
|
|
|
constructor(appContext, tabContext) {
|
|
|
|
super(appContext);
|
|
|
|
this.tabContext = tabContext;
|
2019-05-05 04:44:25 +08:00
|
|
|
this.attributePromise = null;
|
|
|
|
}
|
2018-11-09 03:01:25 +08:00
|
|
|
|
2019-05-05 04:44:25 +08:00
|
|
|
invalidateAttributes() {
|
|
|
|
this.attributePromise = null;
|
|
|
|
}
|
2018-11-09 03:01:25 +08:00
|
|
|
|
2019-05-05 04:44:25 +08:00
|
|
|
reloadAttributes() {
|
2020-01-16 04:36:01 +08:00
|
|
|
this.attributePromise = server.get(`notes/${this.tabContext.note.noteId}/attributes`);
|
2019-05-05 04:44:25 +08:00
|
|
|
}
|
2018-12-25 06:08:43 +08:00
|
|
|
|
2019-05-05 04:44:25 +08:00
|
|
|
async refreshAttributes() {
|
|
|
|
this.reloadAttributes();
|
|
|
|
}
|
2018-11-09 03:01:25 +08:00
|
|
|
|
2019-05-05 04:44:25 +08:00
|
|
|
async getAttributes() {
|
|
|
|
if (!this.attributePromise) {
|
|
|
|
this.reloadAttributes();
|
|
|
|
}
|
2018-11-09 03:01:25 +08:00
|
|
|
|
2019-09-05 04:13:22 +08:00
|
|
|
return this.attributePromise;
|
2018-12-25 06:08:43 +08:00
|
|
|
}
|
|
|
|
|
2020-01-16 04:36:01 +08:00
|
|
|
syncDataListener({data}) {
|
|
|
|
if (this.tabContext.note && data.find(sd => sd.entityName === 'attributes' && sd.noteId === this.tabContext.note.noteId)) {
|
|
|
|
this.reloadAttributes();
|
2019-09-05 04:45:12 +08:00
|
|
|
}
|
2020-01-16 04:36:01 +08:00
|
|
|
}
|
2019-09-05 04:45:12 +08:00
|
|
|
|
2020-01-19 03:49:49 +08:00
|
|
|
tabNoteSwitchedListener() {
|
2020-01-16 04:36:01 +08:00
|
|
|
if (utils.isDesktop()) {
|
2020-01-16 05:11:30 +08:00
|
|
|
this.refreshAttributes();
|
2020-01-16 04:36:01 +08:00
|
|
|
} else {
|
|
|
|
// mobile usually doesn't need attributes so we just invalidate
|
2020-01-16 05:11:30 +08:00
|
|
|
this.invalidateAttributes();
|
2019-08-07 05:20:27 +08:00
|
|
|
}
|
|
|
|
}
|
2018-11-09 03:01:25 +08:00
|
|
|
}
|
|
|
|
|
2019-05-05 04:44:25 +08:00
|
|
|
export default Attributes;
|