From 42546cc1402fe97fb21be72f14e965f2620b89e8 Mon Sep 17 00:00:00 2001 From: Michael Gartner Date: Thu, 16 Oct 2025 01:55:02 -0600 Subject: [PATCH] Enhance DiscourseContextOverlay and DiscourseNodeUtil components * Introduced opacity and color props to DiscourseContextOverlay for better customization. * Added an "Open in Sidebar" button in DiscourseNodeUtil to improve user interaction. * Updated styles to reflect new props and ensure consistent UI behavior. --- .../components/DiscourseContextOverlay.tsx | 69 ++++++++++++++++--- .../components/canvas/DiscourseNodeUtil.tsx | 27 +++++++- 2 files changed, 87 insertions(+), 9 deletions(-) diff --git a/apps/roam/src/components/DiscourseContextOverlay.tsx b/apps/roam/src/components/DiscourseContextOverlay.tsx index 1fec585a2..ba96edf55 100644 --- a/apps/roam/src/components/DiscourseContextOverlay.tsx +++ b/apps/roam/src/components/DiscourseContextOverlay.tsx @@ -58,14 +58,49 @@ const getOverlayInfo = async (tag: string): Promise => { } }; -type DiscourseContextOverlayProps = - | { id: string; tag: string; uid?: never } - | { id: string; uid: string; tag?: never } - | { id: string; tag: string; uid: string }; +const OPACITY_VALUES = [ + "5", + "10", + "15", + "20", + "25", + "30", + "35", + "40", + "45", + "50", + "55", + "60", + "65", + "70", + "75", + "80", + "85", + "90", + "95", + "100", +] as const; + +type OpacityValue = (typeof OPACITY_VALUES)[number]; + +type DiscourseContextOverlayBaseProps = { + id: string; + iconColor?: string; + textColor?: string; + opacity?: OpacityValue; +}; + +// need tag or uid +type DiscourseContextOverlayProps = DiscourseContextOverlayBaseProps & + ({ tag: string; uid?: never } | { tag?: never; uid: string }); + const DiscourseContextOverlay = ({ tag, id, uid, + iconColor, + textColor, + opacity = "100", }: DiscourseContextOverlayProps) => { const tagUid = useMemo(() => uid ?? getPageUidByPageTitle(tag), [uid, tag]); const [loading, setLoading] = useState(true); @@ -131,10 +166,28 @@ const DiscourseContextOverlay = ({ disabled={loading} >
- - {loading ? "-" : score} - - {loading ? "-" : refs} + + + {loading ? "-" : score} + + + + {loading ? "-" : refs} +
} diff --git a/apps/roam/src/components/canvas/DiscourseNodeUtil.tsx b/apps/roam/src/components/canvas/DiscourseNodeUtil.tsx index b5fd3190d..1658aeb75 100644 --- a/apps/roam/src/components/canvas/DiscourseNodeUtil.tsx +++ b/apps/roam/src/components/canvas/DiscourseNodeUtil.tsx @@ -27,6 +27,8 @@ import { useExtensionAPI } from "roamjs-components/components/ExtensionApiContex import getPageUidByPageTitle from "roamjs-components/queries/getPageUidByPageTitle"; import isLiveBlock from "roamjs-components/queries/isLiveBlock"; import updateBlock from "roamjs-components/writes/updateBlock"; +import openBlockInSidebar from "roamjs-components/writes/openBlockInSidebar"; +import { Button, Icon } from "@blueprintjs/core"; import createDiscourseNode from "~/utils/createDiscourseNode"; import { DiscourseNode } from "~/utils/getDiscourseNodes"; import { isPageUid } from "./Tldraw"; @@ -517,6 +519,26 @@ export class BaseDiscourseNodeUtil extends ShapeUtil { onPointerEnter={() => setOverlayMounted(true)} >
+ {/* Open in Sidebar Button */} +