Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(react/floating_buttons): port save to note button
Elian Doran2085d1bbba27
diff --git a/apps/client/src/widgets/FloatingButtons.tsx b/apps/client/src/widgets/FloatingButtons.tsxindex a2f3769fd9..0f36c8a496 100644--- a/apps/client/src/widgets/FloatingButtons.tsx+++ b/apps/client/src/widgets/FloatingButtons.tsx@@ -13,8 +13,11 @@ import attributes from "../services/attributes";import appContext from "../components/app_context";import protected_session_holder from "../services/protected_session_holder";import options from "../services/options";-import { AttributeRow } from "../services/load_results";import { openInAppHelpFromUrl } from "../services/utils";+import toast from "../services/toast";+import server from "../services/server";+import { SaveSqlConsoleResponse } from "@triliumnext/commons";+import tree from "../services/tree";interface FloatingButtonContext {parentComponent: Component;@@ -70,6 +73,10 @@ const FLOATING_BUTTON_DEFINITIONS: FloatingButtonDefinition[] = [{component: OpenTriliumApiDocsButton,isEnabled: ({ note }) => note.mime.startsWith("application/javascript;env=")+ },+ {+ component: SaveToNoteButton,+ isEnabled: ({ note }) => note.mime === "text/x-sqlite;schema=trilium" && note.isHiddenCompletely()}];@@ -238,6 +245,23 @@ function OpenTriliumApiDocsButton({ note }: FloatingButtonContext) {/>}+function SaveToNoteButton({ note }: FloatingButtonContext) {+ return <ActionButton+ icon="bx bx-save"+ text={t("code_buttons.save_to_note_button_title")}+ onClick={async (e) => {+ e.preventDefault();+ const { notePath } = await server.post<SaveSqlConsoleResponse>("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);+ }+ }}+ />+}+/*** Show button that displays floating button after click on close button*/diff --git a/apps/client/src/widgets/floating_buttons/code_buttons.ts b/apps/client/src/widgets/floating_buttons/code_buttons.tsindex c64fe7183d..aab467c9d2 100644--- a/apps/client/src/widgets/floating_buttons/code_buttons.ts+++ b/apps/client/src/widgets/floating_buttons/code_buttons.ts@@ -17,16 +17,10 @@ const TPL = /*html*/`}</style>- <button class="save-to-note-button floating-button btn" title="${t("code_buttons.save_to_note_button_title")}">- <span class="bx bx-save"></span>+ <button class="save-to-note-button floating-button btn" title="${}"></button></div>`;-// TODO: Deduplicate with server.-interface SaveSqlConsoleResponse {- notePath: string;-}-export default class CodeButtonsWidget extends NoteContextAwareWidget {private $openTriliumApiDocsButton!: JQuery<HTMLElement>;@@ -42,13 +36,7 @@ export default class CodeButtonsWidget extends NoteContextAwareWidget {this.$executeButton = this.$widget.find(".execute-button");this.$saveToNoteButton = this.$widget.find(".save-to-note-button");this.$saveToNoteButton.on("click", async () => {- const { notePath } = await server.post<SaveSqlConsoleResponse>("special-notes/save-sql-console", { sqlConsoleNoteId: this.noteId });-- await ws.waitForMaxKnownEntityChangeId();-- await appContext.tabManager.getActiveContext()?.setNote(notePath);- toastService.showMessage(t("code_buttons.sql_console_saved_message", { notePath: await treeService.getNotePathTitle(notePath) }));});keyboardActionService.updateDisplayedShortcuts(this.$widget);@@ -58,13 +46,4 @@ export default class CodeButtonsWidget extends NoteContextAwareWidget {super.doRender();}- async refreshWithNote(note: FNote) {- this.$saveToNoteButton.toggle(note.mime === "text/x-sqlite;schema=trilium" && note.isHiddenCompletely());- }-- async noteTypeMimeChangedEvent({ noteId }: EventData<"noteTypeMimeChanged">) {- if (this.isNote(noteId)) {- await this.refresh();- }- }}diff --git a/apps/server/src/services/special_notes.ts b/apps/server/src/services/special_notes.tsindex d4c37d7643..4f6d76781c 100644--- a/apps/server/src/services/special_notes.ts+++ b/apps/server/src/services/special_notes.ts@@ -10,7 +10,7 @@ import SearchContext from "./search/search_context.js";import { LBTPL_NOTE_LAUNCHER, LBTPL_CUSTOM_WIDGET, LBTPL_SPACER, LBTPL_SCRIPT } from "./hidden_subtree.js";import { t } from "i18next";import { BNote } from "./backend_script_entrypoint.js";-import { SaveSearchNoteResponse } from "@triliumnext/commons";+import { SaveSearchNoteResponse, SaveSqlConsoleResponse } from "@triliumnext/commons";function getInboxNote(date: string) {const workspaceNote = hoistedNoteService.getWorkspaceNote();@@ -67,7 +67,7 @@ async function saveSqlConsole(sqlConsoleNoteId: string) {}}- return result;+ return result satisfies SaveSqlConsoleResponse;}function createSearchNote(searchString: string, ancestorNoteId: string) {diff --git a/packages/commons/src/lib/server_api.ts b/packages/commons/src/lib/server_api.tsindex 966e344181..0a9d36227e 100644--- a/packages/commons/src/lib/server_api.ts+++ b/packages/commons/src/lib/server_api.ts@@ -206,3 +206,5 @@ export interface CloneResponse {export interface ConvertToAttachmentResponse {attachment: AttachmentRow;}++export type SaveSqlConsoleResponse = CloneResponse;