import TabAwareWidget from "./tab_aware_widget.js"; import NoteListRenderer from "../services/note_list_renderer.js"; const TPL = `
`; export default class NoteListWidget extends TabAwareWidget { isEnabled() { return super.isEnabled() && ( ['book', 'search'].includes(this.note.type) || (this.note.type === 'text' && this.note.hasChildren()) ); } doRender() { this.$widget = $(TPL); this.$content = this.$widget.find('.note-list-widget-content'); this.contentSized(); const observer = new IntersectionObserver(entries => { this.isIntersecting = entries[0].isIntersecting; this.checkRenderStatus(); }, { rootMargin: '50px', threshold: 0.1 }); observer.observe(this.$widget[0]); } checkRenderStatus() { console.log("this.isIntersecting", this.isIntersecting); console.log("this.noteIdRefreshed === this.noteId", this.noteIdRefreshed === this.noteId); console.log("this.shownNoteId !== this.noteId", this.shownNoteId !== this.noteId); 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(); } noteDetailRefreshedEvent({tabId}) { if (!this.isTab(tabId)) { return; } this.noteIdRefreshed = this.noteId; setTimeout(() => this.checkRenderStatus(), 100); } autoBookDisabledEvent({tabContext}) { if (this.isTab(tabContext.tabId)) { this.refresh(); } } notesReloadedEvent({noteIds}) { if (noteIds.includes(this.noteId)) { this.refresh(); } } }