From 2ab22e7b0ed5e1318560844f606f446d5789cb51 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 24 Feb 2025 12:39:40 +0200 Subject: [PATCH] fix(client): type errors due to command change --- src/public/app/components/app_context.ts | 21 +++++++++++++------ src/public/app/components/component.ts | 3 +-- src/public/app/menus/launcher_context_menu.ts | 4 ++-- src/public/app/menus/tree_context_menu.ts | 4 ++-- src/public/app/services/hoisted_note.ts | 6 +++--- src/routes/api/special_notes.ts | 5 +++-- src/services/special_notes.ts | 4 +++- 7 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/public/app/components/app_context.ts b/src/public/app/components/app_context.ts index 029182a86..408abd62d 100644 --- a/src/public/app/components/app_context.ts +++ b/src/public/app/components/app_context.ts @@ -56,7 +56,7 @@ export interface ContextMenuCommandData extends CommandData { } export interface NoteCommandData extends CommandData { - notePath: string; + notePath?: string; hoistedNoteId?: string; viewScope?: ViewScope; } @@ -79,6 +79,7 @@ export type CommandMappings = { ancestorNoteId?: string | null; }; closeTocCommand: CommandData; + closeHlt: CommandData; showLaunchBarSubtree: CommandData; showRevisions: CommandData; showOptions: CommandData & { @@ -113,6 +114,8 @@ export type CommandMappings = { openNoteInNewTab: CommandData; openNoteInNewSplit: CommandData; openNoteInNewWindow: CommandData; + openAboutDialog: CommandData; + hideFloatingButtons: {}; hideLeftPane: CommandData; showLeftPane: CommandData; hoistNote: CommandData & { noteId: string }; @@ -129,7 +132,7 @@ export type CommandMappings = { protectSubtree: ContextMenuCommandData; unprotectSubtree: ContextMenuCommandData; openBulkActionsDialog: ContextMenuCommandData | { - selectedOrActiveNoteIds: string[] + selectedOrActiveNoteIds?: string[] }; editBranchPrefix: ContextMenuCommandData; convertNoteToAttachment: ContextMenuCommandData; @@ -186,6 +189,7 @@ export type CommandMappings = { importMarkdownInline: CommandData; showPasswordNotSet: CommandData; showProtectedSessionPasswordDialog: CommandData; + showUploadAttachmentsDialog: CommandData & { noteId: string }; closeProtectedSessionPasswordDialog: CommandData; copyImageReferenceToClipboard: CommandData; copyImageToClipboard: CommandData; @@ -209,6 +213,7 @@ export type CommandMappings = { screen: Screen; }; closeTab: CommandData; + closeToc: CommandData; closeOtherTabs: CommandData; closeRightTabs: CommandData; closeAllTabs: CommandData; @@ -227,15 +232,20 @@ export type CommandMappings = { scrollContainerToCommand: CommandData & { position: number; }; - moveThisNoteSplit: CommandData & { - isMovingLeft: boolean; - }; + scrollToEnd: CommandData; + closeThisNoteSplit: CommandData; + moveThisNoteSplit: CommandData & { isMovingLeft: boolean; }; // Geomap deleteFromMap: { noteId: string }, openGeoLocation: { noteId: string, event: JQuery.MouseDownEvent } toggleZenMode: CommandData; + + updateAttributeList: CommandData & { attributes: Attribute[] }; + saveAttributes: CommandData; + reloadAttributes: CommandData; + refreshNoteList: CommandData & { noteId: string; }; }; type EventMappings = { @@ -336,7 +346,6 @@ type EventMappings = { showToc: { noteId: string; }; - scrollToEnd: { ntxId: string }; noteTypeMimeChanged: { noteId: string }; zenModeChanged: { isEnabled: boolean }; }; diff --git a/src/public/app/components/component.ts b/src/public/app/components/component.ts index ad35e911d..416449fc7 100644 --- a/src/public/app/components/component.ts +++ b/src/public/app/components/component.ts @@ -80,8 +80,7 @@ export class TypedComponent> { return promises.length > 0 ? Promise.all(promises) : null; } - triggerCommand(name: K, _data?: CommandMappings[K]): Promise | undefined | null { - const data = _data || {}; + triggerCommand(name: K, data?: CommandMappings[K]): Promise | undefined | null { const fun = (this as any)[`${name}Command`]; if (fun) { diff --git a/src/public/app/menus/launcher_context_menu.ts b/src/public/app/menus/launcher_context_menu.ts index bc219e591..3aa436632 100644 --- a/src/public/app/menus/launcher_context_menu.ts +++ b/src/public/app/menus/launcher_context_menu.ts @@ -21,8 +21,8 @@ export default class LauncherContextMenu implements SelectMenuItemEventListener< async show(e: PointerEvent | JQuery.TouchStartEvent | JQuery.ContextMenuEvent) { contextMenu.show({ - x: e.pageX, - y: e.pageY, + x: e.pageX ?? 0, + y: e.pageY ?? 0, items: await this.getMenuItems(), selectMenuItemHandler: (item, e) => this.selectMenuItemHandler(item) }); diff --git a/src/public/app/menus/tree_context_menu.ts b/src/public/app/menus/tree_context_menu.ts index c1bf3b07b..96872b484 100644 --- a/src/public/app/menus/tree_context_menu.ts +++ b/src/public/app/menus/tree_context_menu.ts @@ -31,8 +31,8 @@ export default class TreeContextMenu implements SelectMenuItemEventListener this.selectMenuItemHandler(item) }); diff --git a/src/public/app/services/hoisted_note.ts b/src/public/app/services/hoisted_note.ts index 597de9467..f41f08e06 100644 --- a/src/public/app/services/hoisted_note.ts +++ b/src/public/app/services/hoisted_note.ts @@ -1,5 +1,5 @@ import appContext from "../components/app_context.js"; -import treeService, { type Node } from "./tree.js"; +import treeService from "./tree.js"; import dialogService from "./dialog.js"; import froca from "./froca.js"; import type NoteContext from "../components/note_context.js"; @@ -19,11 +19,11 @@ async function unhoist() { } } -function isTopLevelNode(node: Node) { +function isTopLevelNode(node: Fancytree.FancytreeNode) { return isHoistedNode(node.getParent()); } -function isHoistedNode(node: Node) { +function isHoistedNode(node: Fancytree.FancytreeNode) { // even though check for 'root' should not be necessary, we keep it just in case return node.data.noteId === "root" || node.data.noteId === getHoistedNoteId(); } diff --git a/src/routes/api/special_notes.ts b/src/routes/api/special_notes.ts index cf339794b..b443f9ec3 100644 --- a/src/routes/api/special_notes.ts +++ b/src/routes/api/special_notes.ts @@ -3,7 +3,7 @@ import dateNoteService from "../../services/date_notes.js"; import sql from "../../services/sql.js"; import cls from "../../services/cls.js"; -import specialNotesService from "../../services/special_notes.js"; +import specialNotesService, { type LauncherType } from "../../services/special_notes.js"; import becca from "../../becca/becca.js"; import type { Request } from "express"; @@ -85,7 +85,8 @@ function getHoistedNote() { function createLauncher(req: Request) { return specialNotesService.createLauncher({ parentNoteId: req.params.parentNoteId, - launcherType: req.params.launcherType + // TODO: Validate the parameter + launcherType: req.params.launcherType as LauncherType }); } diff --git a/src/services/special_notes.ts b/src/services/special_notes.ts index c8dded954..11c0fd2bc 100644 --- a/src/services/special_notes.ts +++ b/src/services/special_notes.ts @@ -156,9 +156,11 @@ function createScriptLauncher(parentNoteId: string, forceNoteId?: string) { return note; } +export type LauncherType = "launcher" | "note" | "script" | "customWidget" | "spacer"; + interface LauncherConfig { parentNoteId: string; - launcherType: "launcher" | "note" | "script" | "customWidget" | "spacer"; + launcherType: LauncherType; noteId?: string; }