From cb0efe25f5d9b24f22f0c452eb00b9179b89defa Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 15 Dec 2025 08:24:59 +0200 Subject: [PATCH] feat(layout/note_actions): integrate save to note button --- .../widgets/FloatingButtonsDefinitions.tsx | 28 +++++++++++-------- .../src/widgets/ribbon/NoteActionsCustom.tsx | 11 ++++++++ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/apps/client/src/widgets/FloatingButtonsDefinitions.tsx b/apps/client/src/widgets/FloatingButtonsDefinitions.tsx index 496532c06..ecd7c9b92 100644 --- a/apps/client/src/widgets/FloatingButtonsDefinitions.tsx +++ b/apps/client/src/widgets/FloatingButtonsDefinitions.tsx @@ -1,5 +1,5 @@ import { BacklinkCountResponse, BacklinksResponse, SaveSqlConsoleResponse } from "@triliumnext/commons"; -import { VNode } from "preact"; +import { TargetedMouseEvent, VNode } from "preact"; import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "preact/hooks"; import appContext, { EventData, EventNames } from "../components/app_context"; @@ -191,23 +191,27 @@ function OpenTriliumApiDocsButton({ note }: FloatingButtonContext) { } function SaveToNoteButton({ note }: FloatingButtonContext) { - const isEnabled = note.mime === "text/x-sqlite;schema=trilium" && note.isHiddenCompletely(); + const isEnabled = !isNewLayout && note.mime === "text/x-sqlite;schema=trilium" && note.isHiddenCompletely(); return isEnabled && { - e.preventDefault(); - const { notePath } = await server.post("special-notes/save-sql-console", { sqlConsoleNoteId: note.noteId }); - if (notePath) { - toast.showMessage(t("code_buttons.sql_console_saved_message", { "note_path": await tree.getNotePathTitle(notePath) })); - // TODO: This hangs the navigation, for some reason. - //await ws.waitForMaxKnownEntityChangeId(); - await appContext.tabManager.getActiveContext()?.setNote(notePath); - } - }} + onClick={buildSaveSqlToNoteHandler(note)} />; } +export function buildSaveSqlToNoteHandler(note: FNote) { + return async (e: MouseEvent) => { + e.preventDefault(); + const { notePath } = await server.post("special-notes/save-sql-console", { sqlConsoleNoteId: note.noteId }); + if (notePath) { + toast.showMessage(t("code_buttons.sql_console_saved_message", { "note_path": await tree.getNotePathTitle(notePath) })); + // TODO: This hangs the navigation, for some reason. + //await ws.waitForMaxKnownEntityChangeId(); + await appContext.tabManager.getActiveContext()?.setNote(notePath); + } + }; +} + function RelationMapButtons({ note, isDefaultViewMode, triggerEvent }: FloatingButtonContext) { const isEnabled = (note.type === "relationMap" && isDefaultViewMode); return isEnabled && ( diff --git a/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx b/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx index d4f96b2d2..c041ad787 100644 --- a/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx +++ b/apps/client/src/widgets/ribbon/NoteActionsCustom.tsx @@ -7,6 +7,7 @@ import FNote from "../../entities/fnote"; import { t } from "../../services/i18n"; import { downloadFileNote, openNoteExternally } from "../../services/open"; import { ViewTypeOptions } from "../collections/interface"; +import { buildSaveSqlToNoteHandler } from "../FloatingButtonsDefinitions"; import ActionButton from "../react/ActionButton"; import { FormFileUploadActionButton } from "../react/FormFileUpload"; import { useNoteLabel, useNoteLabelBoolean, useNoteProperty, useTriliumOption } from "../react/hooks"; @@ -52,6 +53,7 @@ export default function NoteActionsCustom(props: NoteActionsCustomProps) { + @@ -184,3 +186,12 @@ function RunActiveNoteButton({ note }: NoteActionsCustomInnerProps) { triggerCommand="runActiveNote" />; } + +function SaveToNoteButton({ note }: NoteActionsCustomInnerProps) { + const isEnabled = note.mime === "text/x-sqlite;schema=trilium" && note.isHiddenCompletely(); + return isEnabled && ; +}