fix(split pane): hide the close button when no split panes exist

This commit is contained in:
SiriusXT
2025-11-17 09:24:18 +08:00
parent a22687e2d8
commit be19d1f5b5

View File

@@ -1,18 +1,20 @@
import { useEffect, useState } from "preact/hooks"; import { useEffect, useState } from "preact/hooks";
import { t } from "../../services/i18n"; import { t } from "../../services/i18n";
import ActionButton from "../react/ActionButton"; import ActionButton from "../react/ActionButton";
import { useNoteContext, useTriliumEvent } from "../react/hooks"; import { useNoteContext, useTriliumEvents } from "../react/hooks";
import appContext from "../../components/app_context";
export default function ClosePaneButton() { export default function ClosePaneButton() {
const { noteContext, ntxId, parentComponent } = useNoteContext(); const { noteContext, ntxId, parentComponent } = useNoteContext();
const [ isEnabled, setIsEnabled ] = useState(false); const [isEnabled, setIsEnabled] = useState(false);
function refresh() { function refresh() {
setIsEnabled(!!noteContext); const isMainOfSomeContext = appContext.tabManager.noteContexts.some(c => c.mainNtxId === ntxId);
setIsEnabled(!!(noteContext && (!!noteContext.mainNtxId || isMainOfSomeContext)));
} }
useTriliumEvent("noteContextReorder", refresh); useTriliumEvents(["noteContextRemoved", "noteContextReorder", "newNoteContextCreated"], refresh);
useEffect(refresh, [ ntxId ]); useEffect(refresh, [ntxId]);
return ( return (
<ActionButton <ActionButton