Skip to content

Build your personal knowledge base with Trilium Notes

feat(react/floating_buttons): port open Trilium API docs

Elian Doran08db03800e17
diff --git a/apps/client/src/widgets/FloatingButtons.tsx b/apps/client/src/widgets/FloatingButtons.tsx
index 5ecae1b15b..a2f3769fd9 100644
--- a/apps/client/src/widgets/FloatingButtons.tsx
+++ b/apps/client/src/widgets/FloatingButtons.tsx
@@ -14,6 +14,7 @@ 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";
interface FloatingButtonContext {
parentComponent: Component;
@@ -65,6 +66,10 @@ const FLOATING_BUTTON_DEFINITIONS: FloatingButtonDefinition[] = [
{
component: RunActiveNoteButton,
isEnabled: ({ note }) => note.mime.startsWith("application/javascript") || note.mime === "text/x-sqlite;schema=trilium"
+ },
+ {
+ component: OpenTriliumApiDocsButton,
+ isEnabled: ({ note }) => note.mime.startsWith("application/javascript;env=")
}
];
@@ -225,6 +230,14 @@ function RunActiveNoteButton() {
/>
}
+function OpenTriliumApiDocsButton({ note }: FloatingButtonContext) {
+ return <ActionButton
+ icon="bx bx-help-circle"
+ text={t("code_buttons.trilium_api_docs_button_title")}
+ onClick={() => openInAppHelpFromUrl(note.mime.endsWith("frontend") ? "Q2z6av6JZVWm" : "MEtfsqa5VwNi")}
+ />
+}
+
/**
* 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.ts
index 712d1d9eea..c64fe7183d 100644
--- a/apps/client/src/widgets/floating_buttons/code_buttons.ts
+++ b/apps/client/src/widgets/floating_buttons/code_buttons.ts
@@ -17,10 +17,6 @@ const TPL = /*html*/`
}
</style>
- <button class="trilium-api-docs-button floating-button btn" title="${t("code_buttons.trilium_api_docs_button_title")}">
- <span class="bx bx-help-circle"></span>
- </button>
-
<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>
@@ -42,16 +38,6 @@ export default class CodeButtonsWidget extends NoteContextAwareWidget {
doRender() {
this.$widget = $(TPL);
- this.$openTriliumApiDocsButton = this.$widget.find(".trilium-api-docs-button");
- this.$openTriliumApiDocsButton.on("click", () => {
- toastService.showMessage(t("code_buttons.opening_api_docs_message"));
-
- if (this.note?.mime.endsWith("frontend")) {
- window.open("https://triliumnext.github.io/Notes/Script%20API/interfaces/Frontend_Script_API.Api.html", "_blank");
- } else {
- window.open("https://triliumnext.github.io/Notes/Script%20API/interfaces/Backend_Script_API.Api.html", "_blank");
- }
- });
this.$executeButton = this.$widget.find(".execute-button");
this.$saveToNoteButton = this.$widget.find(".save-to-note-button");
@@ -74,8 +60,6 @@ export default class CodeButtonsWidget extends NoteContextAwareWidget {
async refreshWithNote(note: FNote) {
this.$saveToNoteButton.toggle(note.mime === "text/x-sqlite;schema=trilium" && note.isHiddenCompletely());
-
- this.$openTriliumApiDocsButton.toggle(note.mime.startsWith("application/javascript;env="));
}
async noteTypeMimeChangedEvent({ noteId }: EventData<"noteTypeMimeChanged">) {