mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 07:38:53 +02:00
feat(react/floating_buttons): port save to note button
This commit is contained in:
parent
08db03800e
commit
2085d1bbba
@ -13,8 +13,11 @@ import attributes from "../services/attributes";
|
|||||||
import appContext from "../components/app_context";
|
import appContext from "../components/app_context";
|
||||||
import protected_session_holder from "../services/protected_session_holder";
|
import protected_session_holder from "../services/protected_session_holder";
|
||||||
import options from "../services/options";
|
import options from "../services/options";
|
||||||
import { AttributeRow } from "../services/load_results";
|
|
||||||
import { openInAppHelpFromUrl } from "../services/utils";
|
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 {
|
interface FloatingButtonContext {
|
||||||
parentComponent: Component;
|
parentComponent: Component;
|
||||||
@ -70,6 +73,10 @@ const FLOATING_BUTTON_DEFINITIONS: FloatingButtonDefinition[] = [
|
|||||||
{
|
{
|
||||||
component: OpenTriliumApiDocsButton,
|
component: OpenTriliumApiDocsButton,
|
||||||
isEnabled: ({ note }) => note.mime.startsWith("application/javascript;env=")
|
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
|
* Show button that displays floating button after click on close button
|
||||||
*/
|
*/
|
||||||
|
@ -17,16 +17,10 @@ const TPL = /*html*/`
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<button class="save-to-note-button floating-button btn" title="${t("code_buttons.save_to_note_button_title")}">
|
<button class="save-to-note-button floating-button btn" title="${}">
|
||||||
<span class="bx bx-save"></span>
|
|
||||||
</button>
|
</button>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
// TODO: Deduplicate with server.
|
|
||||||
interface SaveSqlConsoleResponse {
|
|
||||||
notePath: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class CodeButtonsWidget extends NoteContextAwareWidget {
|
export default class CodeButtonsWidget extends NoteContextAwareWidget {
|
||||||
|
|
||||||
private $openTriliumApiDocsButton!: JQuery<HTMLElement>;
|
private $openTriliumApiDocsButton!: JQuery<HTMLElement>;
|
||||||
@ -42,13 +36,7 @@ export default class CodeButtonsWidget extends NoteContextAwareWidget {
|
|||||||
this.$executeButton = this.$widget.find(".execute-button");
|
this.$executeButton = this.$widget.find(".execute-button");
|
||||||
this.$saveToNoteButton = this.$widget.find(".save-to-note-button");
|
this.$saveToNoteButton = this.$widget.find(".save-to-note-button");
|
||||||
this.$saveToNoteButton.on("click", async () => {
|
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);
|
keyboardActionService.updateDisplayedShortcuts(this.$widget);
|
||||||
@ -58,13 +46,4 @@ export default class CodeButtonsWidget extends NoteContextAwareWidget {
|
|||||||
super.doRender();
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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 { LBTPL_NOTE_LAUNCHER, LBTPL_CUSTOM_WIDGET, LBTPL_SPACER, LBTPL_SCRIPT } from "./hidden_subtree.js";
|
||||||
import { t } from "i18next";
|
import { t } from "i18next";
|
||||||
import { BNote } from "./backend_script_entrypoint.js";
|
import { BNote } from "./backend_script_entrypoint.js";
|
||||||
import { SaveSearchNoteResponse } from "@triliumnext/commons";
|
import { SaveSearchNoteResponse, SaveSqlConsoleResponse } from "@triliumnext/commons";
|
||||||
|
|
||||||
function getInboxNote(date: string) {
|
function getInboxNote(date: string) {
|
||||||
const workspaceNote = hoistedNoteService.getWorkspaceNote();
|
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) {
|
function createSearchNote(searchString: string, ancestorNoteId: string) {
|
||||||
|
@ -206,3 +206,5 @@ export interface CloneResponse {
|
|||||||
export interface ConvertToAttachmentResponse {
|
export interface ConvertToAttachmentResponse {
|
||||||
attachment: AttachmentRow;
|
attachment: AttachmentRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type SaveSqlConsoleResponse = CloneResponse;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user