2020-11-25 23:18:30 +01:00
|
|
|
import TabAwareWidget from "./tab_aware_widget.js";
|
|
|
|
import NoteListRenderer from "../services/note_list_renderer.js";
|
|
|
|
|
|
|
|
const TPL = `
|
|
|
|
<div class="note-list-widget">
|
2020-11-26 23:00:27 +01:00
|
|
|
<style>
|
|
|
|
.note-list-widget {
|
|
|
|
flex-grow: 100000;
|
|
|
|
flex-shrink: 100000;
|
|
|
|
min-height: 0;
|
2020-12-13 20:13:57 +01:00
|
|
|
overflow: auto;
|
2020-11-26 23:00:27 +01:00
|
|
|
}
|
2020-12-13 23:27:42 +01:00
|
|
|
|
|
|
|
.note-list-widget .note-list {
|
|
|
|
padding: 10px;
|
|
|
|
}
|
2020-11-26 23:00:27 +01:00
|
|
|
</style>
|
|
|
|
|
|
|
|
<div class="note-list-widget-content">
|
|
|
|
</div>
|
2020-11-25 23:18:30 +01:00
|
|
|
</div>`;
|
|
|
|
|
|
|
|
export default class NoteListWidget extends TabAwareWidget {
|
|
|
|
isEnabled() {
|
2020-12-29 22:27:31 +01:00
|
|
|
return super.isEnabled()
|
|
|
|
&& this.note.mime !== 'text/x-sqlite;schema=trilium'
|
|
|
|
&& (
|
|
|
|
['book', 'search', 'code'].includes(this.note.type)
|
|
|
|
|| (this.note.type === 'text' && this.note.hasChildren())
|
|
|
|
);
|
2020-11-25 23:18:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
doRender() {
|
|
|
|
this.$widget = $(TPL);
|
2020-11-26 23:00:27 +01:00
|
|
|
this.$content = this.$widget.find('.note-list-widget-content');
|
2020-11-25 23:18:30 +01:00
|
|
|
this.contentSized();
|
2020-12-27 22:19:27 +01:00
|
|
|
|
|
|
|
const observer = new IntersectionObserver(entries => {
|
|
|
|
this.isIntersecting = entries[0].isIntersecting;
|
|
|
|
|
|
|
|
this.checkRenderStatus();
|
|
|
|
}, {
|
|
|
|
rootMargin: '50px',
|
|
|
|
threshold: 0.1
|
|
|
|
});
|
|
|
|
|
|
|
|
observer.observe(this.$widget[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
checkRenderStatus() {
|
|
|
|
if (this.isIntersecting
|
|
|
|
&& this.noteIdRefreshed === this.noteId
|
|
|
|
&& this.shownNoteId !== this.noteId) {
|
|
|
|
|
|
|
|
this.shownNoteId = this.noteId;
|
|
|
|
this.renderNoteList(this.note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async renderNoteList(note) {
|
|
|
|
const noteListRenderer = new NoteListRenderer(this.$content, note, note.getChildNoteIds());
|
|
|
|
await noteListRenderer.renderList();
|
2020-11-25 23:18:30 +01:00
|
|
|
}
|
|
|
|
|
2020-12-27 22:19:27 +01:00
|
|
|
noteDetailRefreshedEvent({tabId}) {
|
|
|
|
if (!this.isTab(tabId)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.noteIdRefreshed = this.noteId;
|
2020-11-25 23:18:30 +01:00
|
|
|
|
2020-12-27 22:19:27 +01:00
|
|
|
setTimeout(() => this.checkRenderStatus(), 100);
|
2020-11-25 23:18:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
autoBookDisabledEvent({tabContext}) {
|
|
|
|
if (this.isTab(tabContext.tabId)) {
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
}
|
2020-11-26 23:00:27 +01:00
|
|
|
|
2020-12-17 21:19:52 +01:00
|
|
|
notesReloadedEvent({noteIds}) {
|
|
|
|
if (noteIds.includes(this.noteId)) {
|
2020-11-26 23:00:27 +01:00
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
}
|
2020-11-25 23:18:30 +01:00
|
|
|
}
|