From 761ac680a35a15b3a1dc633cf236c8df39dac824 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 19 Jan 2025 20:53:52 +0200 Subject: [PATCH] chore(client/ts): port note_paths --- src/public/app/entities/fnote.ts | 10 +++--- src/public/app/services/load_results.ts | 1 + .../{note_paths.js => note_paths.ts} | 33 +++++++++++-------- 3 files changed, 26 insertions(+), 18 deletions(-) rename src/public/app/widgets/ribbon_widgets/{note_paths.js => note_paths.ts} (84%) diff --git a/src/public/app/entities/fnote.ts b/src/public/app/entities/fnote.ts index 4da479d16..7be1d1121 100644 --- a/src/public/app/entities/fnote.ts +++ b/src/public/app/entities/fnote.ts @@ -37,10 +37,10 @@ const NOTE_TYPE_ICONS = { */ type NoteType = "file" | "image" | "search" | "noteMap" | "launcher" | "doc" | "contentWidget" | "text" | "relationMap" | "render" | "canvas" | "mermaid" | "book" | "webView" | "code" | "mindMap"; -interface NotePathRecord { +export interface NotePathRecord { isArchived: boolean; isInHoistedSubTree: boolean; - isSearch: boolean; + isSearch?: boolean; notePath: string[]; isHidden: boolean; } @@ -401,14 +401,14 @@ class FNote { return notePaths; } - getSortedNotePathRecords(hoistedNoteId = "root") { + getSortedNotePathRecords(hoistedNoteId = "root"): NotePathRecord[] { const isHoistedRoot = hoistedNoteId === "root"; - const notePaths = this.getAllNotePaths().map((path) => ({ + const notePaths: NotePathRecord[] = this.getAllNotePaths().map((path) => ({ notePath: path, isInHoistedSubTree: isHoistedRoot || path.includes(hoistedNoteId), isArchived: path.some((noteId) => froca.notes[noteId].isArchived), - isSearch: path.find((noteId) => froca.notes[noteId].type === "search"), + isSearch: path.some((noteId) => froca.notes[noteId].type === "search"), isHidden: path.includes("_hidden") })); diff --git a/src/public/app/services/load_results.ts b/src/public/app/services/load_results.ts index 27b3b1eb9..137d1b7be 100644 --- a/src/public/app/services/load_results.ts +++ b/src/public/app/services/load_results.ts @@ -9,6 +9,7 @@ interface NoteRow { } interface BranchRow { + noteId?: string; branchId: string; componentId: string; parentNoteId?: string; diff --git a/src/public/app/widgets/ribbon_widgets/note_paths.js b/src/public/app/widgets/ribbon_widgets/note_paths.ts similarity index 84% rename from src/public/app/widgets/ribbon_widgets/note_paths.js rename to src/public/app/widgets/ribbon_widgets/note_paths.ts index cabf4f39d..cae48bd4d 100644 --- a/src/public/app/widgets/ribbon_widgets/note_paths.js +++ b/src/public/app/widgets/ribbon_widgets/note_paths.ts @@ -2,6 +2,9 @@ import NoteContextAwareWidget from "../note_context_aware_widget.js"; import treeService from "../../services/tree.js"; import linkService from "../../services/link.js"; import { t } from "../../services/i18n.js"; +import type FNote from "../../entities/fnote.js"; +import type { NotePathRecord } from "../../entities/fnote.js"; +import type { EventData } from "../../components/app_context.js"; const TPL = `
@@ -11,32 +14,36 @@ const TPL = ` max-height: 300px; overflow-y: auto; } - + .note-path-list { margin-top: 10px; } - + .note-path-list .path-current { font-weight: bold; } - + .note-path-list .path-archived { color: var(--muted-text-color) !important; } - + .note-path-list .path-search { font-style: italic; } - +
- + - +
`; export default class NotePathsWidget extends NoteContextAwareWidget { + + private $notePathIntro!: JQuery; + private $notePathList!: JQuery; + get name() { return "notePaths"; } @@ -59,13 +66,12 @@ export default class NotePathsWidget extends NoteContextAwareWidget { this.$notePathIntro = this.$widget.find(".note-path-intro"); this.$notePathList = this.$widget.find(".note-path-list"); - this.$widget.on("show.bs.dropdown", () => this.renderDropdown()); } - async refreshWithNote(note) { + async refreshWithNote(note: FNote) { this.$notePathList.empty(); - if (this.noteId === "root") { + if (!this.note || this.noteId === "root") { this.$notePathList.empty().append(await this.getRenderedPath("root")); return; @@ -90,7 +96,7 @@ export default class NotePathsWidget extends NoteContextAwareWidget { this.$notePathList.empty().append(...renderedPaths); } - async getRenderedPath(notePath, notePathRecord = null) { + async getRenderedPath(notePath: string, notePathRecord: NotePathRecord | null = null) { const title = await treeService.getNotePathTitle(notePath); const $noteLink = await linkService.createLink(notePath, { title }); @@ -128,8 +134,9 @@ export default class NotePathsWidget extends NoteContextAwareWidget { return $("
  • ").append($noteLink); } - entitiesReloadedEvent({ loadResults }) { - if (loadResults.getBranchRows().find((branch) => branch.noteId === this.noteId) || loadResults.isNoteReloaded(this.noteId)) { + entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { + if (loadResults.getBranchRows().find((branch) => branch.noteId === this.noteId) || + (this.noteId != null && loadResults.isNoteReloaded(this.noteId))) { this.refresh(); } }