From 546274a79df8788d06c47bbe61982a9bd3a53434 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 28 Jan 2025 14:13:21 +0200 Subject: [PATCH] feat(client/ts): port note_list --- src/public/app/components/app_context.ts | 3 ++ src/public/app/widgets/basic_widget.ts | 2 +- .../app/widgets/note_context_aware_widget.ts | 2 +- .../widgets/{note_list.js => note_list.ts} | 32 ++++++++++++------- 4 files changed, 25 insertions(+), 14 deletions(-) rename src/public/app/widgets/{note_list.js => note_list.ts} (72%) diff --git a/src/public/app/components/app_context.ts b/src/public/app/components/app_context.ts index d3868eac3..072977695 100644 --- a/src/public/app/components/app_context.ts +++ b/src/public/app/components/app_context.ts @@ -291,6 +291,9 @@ type EventMappings = { tabReorder: { ntxIdsInOrder: string[] }; + refreshNoteList: { + noteId: string; + } }; export type EventListener = { diff --git a/src/public/app/widgets/basic_widget.ts b/src/public/app/widgets/basic_widget.ts index ec10acde6..23a2e04d1 100644 --- a/src/public/app/widgets/basic_widget.ts +++ b/src/public/app/widgets/basic_widget.ts @@ -193,7 +193,7 @@ export class TypedBasicWidget> 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. * @returns whether the widget is enabled. */ - isEnabled() { + isEnabled(): boolean | null | undefined { return true; } diff --git a/src/public/app/widgets/note_context_aware_widget.ts b/src/public/app/widgets/note_context_aware_widget.ts index 7db5c1027..9f9d2448b 100644 --- a/src/public/app/widgets/note_context_aware_widget.ts +++ b/src/public/app/widgets/note_context_aware_widget.ts @@ -54,7 +54,7 @@ class NoteContextAwareWidget extends BasicWidget { * * @returns true when an active note exists */ - isEnabled() { + isEnabled(): boolean | null | undefined { return !!this.note; } diff --git a/src/public/app/widgets/note_list.js b/src/public/app/widgets/note_list.ts similarity index 72% rename from src/public/app/widgets/note_list.js rename to src/public/app/widgets/note_list.ts index c202bc523..97fd19bef 100644 --- a/src/public/app/widgets/note_list.js +++ b/src/public/app/widgets/note_list.ts @@ -1,5 +1,7 @@ import NoteContextAwareWidget from "./note_context_aware_widget.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 = `
@@ -8,19 +10,25 @@ const TPL = ` min-height: 0; overflow: auto; } - + .note-list-widget .note-list { padding: 10px; } - +
`; export default class NoteListWidget extends NoteContextAwareWidget { + + private $content!: JQuery; + private isIntersecting?: boolean; + private noteIdRefreshed?: string; + private shownNoteId?: string | null; + isEnabled() { - return super.isEnabled() && this.noteContext.hasNoteList(); + return super.isEnabled() && this.noteContext?.hasNoteList(); } doRender() { @@ -50,13 +58,13 @@ export default class NoteListWidget extends NoteContextAwareWidget { // 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) { + if (this.note && this.isIntersecting && this.noteIdRefreshed === this.noteId && this.shownNoteId !== this.noteId) { this.shownNoteId = this.noteId; this.renderNoteList(this.note); } } - async renderNoteList(note) { + async renderNoteList(note: FNote) { const noteListRenderer = new NoteListRenderer(this.$content, note, note.getChildNoteIds()); await noteListRenderer.renderList(); } @@ -67,8 +75,8 @@ export default class NoteListWidget extends NoteContextAwareWidget { await super.refresh(); } - async refreshNoteListEvent({ noteId }) { - if (this.isNote(noteId)) { + async refreshNoteListEvent({ noteId }: EventData<"refreshNoteList">) { + if (this.isNote(noteId) && 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 * it is not intersected (visible) anymore. */ - noteDetailRefreshedEvent({ ntxId }) { + noteDetailRefreshedEvent({ ntxId }: EventData<"noteDetailRefreshed">) { if (!this.isNoteContext(ntxId)) { return; } @@ -88,14 +96,14 @@ export default class NoteListWidget extends NoteContextAwareWidget { setTimeout(() => this.checkRenderStatus(), 100); } - notesReloadedEvent({ noteIds }) { - if (noteIds.includes(this.noteId)) { + notesReloadedEvent({ noteIds }: EventData<"notesReloaded">) { + if (this.noteId && noteIds.includes(this.noteId)) { this.refresh(); } } - entitiesReloadedEvent({ loadResults }) { - if (loadResults.getAttributeRows().find((attr) => attr.noteId === this.noteId && ["viewType", "expanded", "pageSize"].includes(attr.name))) { + entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { + if (loadResults.getAttributeRows().find((attr) => attr.noteId === this.noteId && attr.name && ["viewType", "expanded", "pageSize"].includes(attr.name))) { this.shownNoteId = null; // force render this.checkRenderStatus();