trilium/apps/client/src/widgets/buttons/close_pane_button.tsx
SiriusXT be19d1f5b5
Some checks are pending
Checks / main (push) Waiting to run
fix(split pane): hide the close button when no split panes exist
2025-11-17 09:24:18 +08:00

34 lines
1.3 KiB
TypeScript

import { useEffect, useState } from "preact/hooks";
import { t } from "../../services/i18n";
import ActionButton from "../react/ActionButton";
import { useNoteContext, useTriliumEvents } from "../react/hooks";
import appContext from "../../components/app_context";
export default function ClosePaneButton() {
const { noteContext, ntxId, parentComponent } = useNoteContext();
const [isEnabled, setIsEnabled] = useState(false);
function refresh() {
const isMainOfSomeContext = appContext.tabManager.noteContexts.some(c => c.mainNtxId === ntxId);
setIsEnabled(!!(noteContext && (!!noteContext.mainNtxId || isMainOfSomeContext)));
}
useTriliumEvents(["noteContextRemoved", "noteContextReorder", "newNoteContextCreated"], refresh);
useEffect(refresh, [ntxId]);
return (
<ActionButton
icon="bx bx-x"
text={t("close_pane_button.close_this_pane")}
className={!isEnabled ? "hidden-ext" : ""}
onClick={(e) => {
// to avoid split pane container detecting click within the pane which would try to activate this
// pane (which is being removed)
e.stopPropagation();
parentComponent?.triggerCommand("closeThisNoteSplit", { ntxId: parentComponent.getClosestNtxId() });
}}
/>
)
}