Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions apps/roam/src/utils/initializeObserversAndListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,24 @@ import {
findBlockElementFromSelection,
} from "~/utils/renderTextSelectionPopup";
import { renderNodeTagPopupButton } from "./renderNodeTagPopup";
import { formatHexColor } from "~/components/settings/DiscourseNodeCanvasSettings";

let discourseNodes: DiscourseNode[] = [];
let discourseTagSet: Set<string> = new Set();
let discourseTagToStyle: Record<string, { color: string }> = {};

const refreshDiscourseNodeCache = () => {
discourseNodes = getDiscourseNodes();
discourseTagSet = new Set(
discourseNodes.flatMap((n) => (n.tag ? [n.tag.toLowerCase()] : [])),
discourseTagToStyle = discourseNodes.reduce(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should reuse the existing refreshConfigTree. No need to re-invent the wheel 😀

(acc, n) => {
if (n.tag && n.canvasSettings?.color) {
const color = formatHexColor(n.canvasSettings.color);
acc[n.tag.toLowerCase()] = {
color,
};
}
return acc;
},
{} as Record<string, { color: string }>,
);
};

Expand Down Expand Up @@ -115,8 +125,12 @@ export const initObservers = async ({
callback: (s: HTMLSpanElement) => {
const tag = s.getAttribute("data-tag");
if (tag) {
if (discourseTagSet.has(tag.toLowerCase())) {
const style = discourseTagToStyle[tag.toLowerCase()];
if (style) {
renderNodeTagPopupButton(s, discourseNodes, onloadArgs.extensionAPI);
s.style.color = style.color;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we put this color/style directly on the Blueprint button? That way it would all be in one place. Also, we could use tailwind/classes as much as possible so users could adjust the styles themselves.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry which button? We have to add the color the node tag in the block right?

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, my bad. I was thinking of the popover.

s.style.padding = "2px 4px";
s.style.borderRadius = "4px";
}
}
},
Expand Down