feat(client/ts): port note_list

This commit is contained in:
Elian Doran 2025-01-28 14:13:21 +02:00
parent 15c63f52dc
commit 546274a79d
No known key found for this signature in database
4 changed files with 25 additions and 14 deletions

View File

@ -291,6 +291,9 @@ type EventMappings = {
tabReorder: { tabReorder: {
ntxIdsInOrder: string[] ntxIdsInOrder: string[]
}; };
refreshNoteList: {
noteId: string;
}
}; };
export type EventListener<T extends EventNames> = { export type EventListener<T extends EventNames> = {

View File

@ -193,7 +193,7 @@ export class TypedBasicWidget<T extends TypedComponent<any>> extends TypedCompon
* Indicates if the widget is enabled. Widgets are enabled by default. Generally setting this to `false` will cause the widget not to be displayed, however it will still be available on the DOM but hidden. * Indicates if the widget is enabled. Widgets are enabled by default. Generally setting this to `false` will cause the widget not to be displayed, however it will still be available on the DOM but hidden.
* @returns whether the widget is enabled. * @returns whether the widget is enabled.
*/ */
isEnabled() { isEnabled(): boolean | null | undefined {
return true; return true;
} }

View File

@ -54,7 +54,7 @@ class NoteContextAwareWidget extends BasicWidget {
* *
* @returns true when an active note exists * @returns true when an active note exists
*/ */
isEnabled() { isEnabled(): boolean | null | undefined {
return !!this.note; return !!this.note;
} }

View File

@ -1,5 +1,7 @@
import NoteContextAwareWidget from "./note_context_aware_widget.js"; import NoteContextAwareWidget from "./note_context_aware_widget.js";
import NoteListRenderer from "../services/note_list_renderer.js"; import NoteListRenderer from "../services/note_list_renderer.js";
import type FNote from "../entities/fnote.js";
import type { EventData } from "../components/app_context.js";
const TPL = ` const TPL = `
<div class="note-list-widget"> <div class="note-list-widget">
@ -19,8 +21,14 @@ const TPL = `
</div>`; </div>`;
export default class NoteListWidget extends NoteContextAwareWidget { export default class NoteListWidget extends NoteContextAwareWidget {
private $content!: JQuery<HTMLElement>;
private isIntersecting?: boolean;
private noteIdRefreshed?: string;
private shownNoteId?: string | null;
isEnabled() { isEnabled() {
return super.isEnabled() && this.noteContext.hasNoteList(); return super.isEnabled() && this.noteContext?.hasNoteList();
} }
doRender() { doRender() {
@ -50,13 +58,13 @@ export default class NoteListWidget extends NoteContextAwareWidget {
// console.log(`${this.noteIdRefreshed} === ${this.noteId}`, this.noteIdRefreshed === this.noteId); // console.log(`${this.noteIdRefreshed} === ${this.noteId}`, this.noteIdRefreshed === this.noteId);
// console.log("this.shownNoteId !== this.noteId", this.shownNoteId !== this.noteId); // console.log("this.shownNoteId !== this.noteId", this.shownNoteId !== this.noteId);
if (this.isIntersecting && this.noteIdRefreshed === this.noteId && this.shownNoteId !== this.noteId) { if (this.note && this.isIntersecting && this.noteIdRefreshed === this.noteId && this.shownNoteId !== this.noteId) {
this.shownNoteId = this.noteId; this.shownNoteId = this.noteId;
this.renderNoteList(this.note); this.renderNoteList(this.note);
} }
} }
async renderNoteList(note) { async renderNoteList(note: FNote) {
const noteListRenderer = new NoteListRenderer(this.$content, note, note.getChildNoteIds()); const noteListRenderer = new NoteListRenderer(this.$content, note, note.getChildNoteIds());
await noteListRenderer.renderList(); await noteListRenderer.renderList();
} }
@ -67,8 +75,8 @@ export default class NoteListWidget extends NoteContextAwareWidget {
await super.refresh(); await super.refresh();
} }
async refreshNoteListEvent({ noteId }) { async refreshNoteListEvent({ noteId }: EventData<"refreshNoteList">) {
if (this.isNote(noteId)) { if (this.isNote(noteId) && this.note) {
await this.renderNoteList(this.note); await this.renderNoteList(this.note);
} }
} }
@ -78,7 +86,7 @@ export default class NoteListWidget extends NoteContextAwareWidget {
* If it's evaluated before note detail, then it's clearly intersected (visible) although after note detail load * If it's evaluated before note detail, then it's clearly intersected (visible) although after note detail load
* it is not intersected (visible) anymore. * it is not intersected (visible) anymore.
*/ */
noteDetailRefreshedEvent({ ntxId }) { noteDetailRefreshedEvent({ ntxId }: EventData<"noteDetailRefreshed">) {
if (!this.isNoteContext(ntxId)) { if (!this.isNoteContext(ntxId)) {
return; return;
} }
@ -88,14 +96,14 @@ export default class NoteListWidget extends NoteContextAwareWidget {
setTimeout(() => this.checkRenderStatus(), 100); setTimeout(() => this.checkRenderStatus(), 100);
} }
notesReloadedEvent({ noteIds }) { notesReloadedEvent({ noteIds }: EventData<"notesReloaded">) {
if (noteIds.includes(this.noteId)) { if (this.noteId && noteIds.includes(this.noteId)) {
this.refresh(); this.refresh();
} }
} }
entitiesReloadedEvent({ loadResults }) { entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
if (loadResults.getAttributeRows().find((attr) => attr.noteId === this.noteId && ["viewType", "expanded", "pageSize"].includes(attr.name))) { if (loadResults.getAttributeRows().find((attr) => attr.noteId === this.noteId && attr.name && ["viewType", "expanded", "pageSize"].includes(attr.name))) {
this.shownNoteId = null; // force render this.shownNoteId = null; // force render
this.checkRenderStatus(); this.checkRenderStatus();