import linkService from "../../services/link.js"; import server from "../../services/server.js"; import froca from "../../services/froca.js"; import NoteContextAwareWidget from "../note_context_aware_widget.js"; const TPL = `
`; export default class SimilarNotesWidget extends NoteContextAwareWidget { get name() { return "similarNotes"; } isEnabled() { return super.isEnabled() && this.note.type !== 'search' && !this.note.hasLabel('similarNotesWidgetDisabled'); } getTitle() { return { show: this.isEnabled(), title: 'Similar Notes', icon: 'bx bx-bar-chart' }; } doRender() { this.$widget = $(TPL); this.contentSized(); this.$similarNotesWrapper = this.$widget.find(".similar-notes-wrapper"); } async refreshWithNote() { // remember which title was when we found the similar notes this.title = this.note.title; const similarNotes = await server.get('similar-notes/' + this.noteId); if (similarNotes.length === 0) { this.$similarNotesWrapper.empty().append("No similar notes found."); return; } const noteIds = similarNotes.flatMap(note => note.notePath); await froca.getNotes(noteIds, true); // preload all at once const $list = $('