mirror of
https://github.com/zadam/trilium.git
synced 2025-12-17 05:39:55 +01:00
feat(layout/note_actions): integrate save to note button
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { BacklinkCountResponse, BacklinksResponse, SaveSqlConsoleResponse } from "@triliumnext/commons";
|
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 { useCallback, useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
|
||||||
|
|
||||||
import appContext, { EventData, EventNames } from "../components/app_context";
|
import appContext, { EventData, EventNames } from "../components/app_context";
|
||||||
@@ -191,11 +191,16 @@ function OpenTriliumApiDocsButton({ note }: FloatingButtonContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function SaveToNoteButton({ 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 && <FloatingButton
|
return isEnabled && <FloatingButton
|
||||||
icon="bx bx-save"
|
icon="bx bx-save"
|
||||||
text={t("code_buttons.save_to_note_button_title")}
|
text={t("code_buttons.save_to_note_button_title")}
|
||||||
onClick={async (e) => {
|
onClick={buildSaveSqlToNoteHandler(note)}
|
||||||
|
/>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildSaveSqlToNoteHandler(note: FNote) {
|
||||||
|
return async (e: MouseEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const { notePath } = await server.post<SaveSqlConsoleResponse>("special-notes/save-sql-console", { sqlConsoleNoteId: note.noteId });
|
const { notePath } = await server.post<SaveSqlConsoleResponse>("special-notes/save-sql-console", { sqlConsoleNoteId: note.noteId });
|
||||||
if (notePath) {
|
if (notePath) {
|
||||||
@@ -204,8 +209,7 @@ function SaveToNoteButton({ note }: FloatingButtonContext) {
|
|||||||
//await ws.waitForMaxKnownEntityChangeId();
|
//await ws.waitForMaxKnownEntityChangeId();
|
||||||
await appContext.tabManager.getActiveContext()?.setNote(notePath);
|
await appContext.tabManager.getActiveContext()?.setNote(notePath);
|
||||||
}
|
}
|
||||||
}}
|
};
|
||||||
/>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function RelationMapButtons({ note, isDefaultViewMode, triggerEvent }: FloatingButtonContext) {
|
function RelationMapButtons({ note, isDefaultViewMode, triggerEvent }: FloatingButtonContext) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import FNote from "../../entities/fnote";
|
|||||||
import { t } from "../../services/i18n";
|
import { t } from "../../services/i18n";
|
||||||
import { downloadFileNote, openNoteExternally } from "../../services/open";
|
import { downloadFileNote, openNoteExternally } from "../../services/open";
|
||||||
import { ViewTypeOptions } from "../collections/interface";
|
import { ViewTypeOptions } from "../collections/interface";
|
||||||
|
import { buildSaveSqlToNoteHandler } from "../FloatingButtonsDefinitions";
|
||||||
import ActionButton from "../react/ActionButton";
|
import ActionButton from "../react/ActionButton";
|
||||||
import { FormFileUploadActionButton } from "../react/FormFileUpload";
|
import { FormFileUploadActionButton } from "../react/FormFileUpload";
|
||||||
import { useNoteLabel, useNoteLabelBoolean, useNoteProperty, useTriliumOption } from "../react/hooks";
|
import { useNoteLabel, useNoteLabelBoolean, useNoteProperty, useTriliumOption } from "../react/hooks";
|
||||||
@@ -52,6 +53,7 @@ export default function NoteActionsCustom(props: NoteActionsCustomProps) {
|
|||||||
<RunActiveNoteButton {...innerProps } />
|
<RunActiveNoteButton {...innerProps } />
|
||||||
<SwitchSplitOrientationButton {...innerProps} />
|
<SwitchSplitOrientationButton {...innerProps} />
|
||||||
<ToggleReadOnlyButton {...innerProps} />
|
<ToggleReadOnlyButton {...innerProps} />
|
||||||
|
<SaveToNoteButton {...innerProps} />
|
||||||
<RefreshButton {...innerProps} />
|
<RefreshButton {...innerProps} />
|
||||||
<CopyReferenceToClipboardButton {...innerProps} />
|
<CopyReferenceToClipboardButton {...innerProps} />
|
||||||
<NoteActionsCustomInner {...innerProps} />
|
<NoteActionsCustomInner {...innerProps} />
|
||||||
@@ -184,3 +186,12 @@ function RunActiveNoteButton({ note }: NoteActionsCustomInnerProps) {
|
|||||||
triggerCommand="runActiveNote"
|
triggerCommand="runActiveNote"
|
||||||
/>;
|
/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function SaveToNoteButton({ note }: NoteActionsCustomInnerProps) {
|
||||||
|
const isEnabled = note.mime === "text/x-sqlite;schema=trilium" && note.isHiddenCompletely();
|
||||||
|
return isEnabled && <ActionButton
|
||||||
|
icon="bx bx-save"
|
||||||
|
text={t("code_buttons.save_to_note_button_title")}
|
||||||
|
onClick={buildSaveSqlToNoteHandler(note)}
|
||||||
|
/>;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user