From b9b5c13d9c5929d34c1b476cdd5d45a494c83e05 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 9 Nov 2025 21:14:28 +0200 Subject: [PATCH] fix(client): ribbon adapter not working --- apps/client/src/widgets/ribbon/Ribbon.tsx | 2 +- .../ribbon/components/StandaloneRibbonAdapter.tsx | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/apps/client/src/widgets/ribbon/Ribbon.tsx b/apps/client/src/widgets/ribbon/Ribbon.tsx index 48c3c3f13..78cec9aca 100644 --- a/apps/client/src/widgets/ribbon/Ribbon.tsx +++ b/apps/client/src/widgets/ribbon/Ribbon.tsx @@ -146,7 +146,7 @@ function RibbonTab({ icon, title, active, onClick, toggleCommand }: { icon: stri ) } -async function shouldShowTab(showConfig: boolean | ((context: TitleContext) => Promise | boolean | null | undefined), context: TitleContext) { +export async function shouldShowTab(showConfig: boolean | ((context: TitleContext) => Promise | boolean | null | undefined), context: TitleContext) { if (showConfig === null || showConfig === undefined) return true; if (typeof showConfig === "boolean") return showConfig; if ("then" in showConfig) return await showConfig(context); diff --git a/apps/client/src/widgets/ribbon/components/StandaloneRibbonAdapter.tsx b/apps/client/src/widgets/ribbon/components/StandaloneRibbonAdapter.tsx index 54a0f1af0..1fbdd5d63 100644 --- a/apps/client/src/widgets/ribbon/components/StandaloneRibbonAdapter.tsx +++ b/apps/client/src/widgets/ribbon/components/StandaloneRibbonAdapter.tsx @@ -1,8 +1,9 @@ import { ComponentChildren } from "preact"; import { useNoteContext } from "../../react/hooks"; -import { TabContext, TitleContext } from "../ribbon-interface"; +import { TabContext } from "../ribbon-interface"; import { useEffect, useMemo, useState } from "preact/hooks"; import { RIBBON_TAB_DEFINITIONS } from "../RibbonDefinition"; +import { shouldShowTab } from "../Ribbon"; interface StandaloneRibbonAdapterProps { component: (props: TabContext) => ComponentChildren; @@ -16,10 +17,11 @@ export default function StandaloneRibbonAdapter({ component }: StandaloneRibbonA const Component = component; const { note, ntxId, hoistedNoteId, notePath, noteContext, componentId } = useNoteContext(); const definition = useMemo(() => RIBBON_TAB_DEFINITIONS.find(def => def.content === component), [ component ]); - const [ shown, setShown ] = useState(unwrapShown(definition?.show, { note })); + const [ shown, setShown ] = useState(false); useEffect(() => { - setShown(unwrapShown(definition?.show, { note })); + if (!definition) return; + shouldShowTab(definition.show, { note, noteContext }).then(setShown); }, [ note ]); return ( @@ -35,9 +37,3 @@ export default function StandaloneRibbonAdapter({ component }: StandaloneRibbonA /> ); } - -function unwrapShown(value: boolean | ((context: TitleContext) => boolean | null | undefined) | undefined, context: TitleContext) { - if (!value) return true; - if (typeof value === "boolean") return value; - return !!value(context); -}