Skip to content
Merged
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
44 changes: 18 additions & 26 deletions apps/roam/src/components/canvas/DiscourseNodeUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { getSetting } from "~/utils/extensionSettings";
import DiscourseContextOverlay from "~/components/DiscourseContextOverlay";
import { getDiscourseNodeColors } from "~/utils/getDiscourseNodeColors";
import { render as renderToast } from "roamjs-components/components/Toast";
import { RenderRoamBlockString } from "~/utils/roamReactComponents";

const escapeRegExp = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");

Expand Down Expand Up @@ -445,10 +446,6 @@ export class BaseDiscourseNodeUtil extends BaseBoxShapeUtil<DiscourseNodeShape>

const isEditing = this.editor.getEditingShapeId() === shape.id;
// eslint-disable-next-line react-hooks/rules-of-hooks
const contentRef = useRef<HTMLDivElement>(null);
// eslint-disable-next-line react-hooks/rules-of-hooks
const [loaded, setLoaded] = useState("");
// eslint-disable-next-line react-hooks/rules-of-hooks
const [overlayMounted, setOverlayMounted] = useState(false);
// eslint-disable-next-line react-hooks/rules-of-hooks
const dialogRenderedRef = useRef(false);
Expand Down Expand Up @@ -479,24 +476,9 @@ export class BaseDiscourseNodeUtil extends BaseBoxShapeUtil<DiscourseNodeShape>
return null;
}, [shape.type, shape.props.uid]);

// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
if (
shape.props.uid !== loaded &&
!isPageUid(shape.props.uid) &&
contentRef.current &&
isLiveBlock(shape.props.uid)
) {
window.roamAlphaAPI.ui.components.renderBlock({
el: contentRef.current,
uid: shape.props.uid,
});
// TODO: resize shape props once this is rendered
setLoaded(shape.props.uid);
}
}, [setLoaded, loaded, contentRef, shape.props.uid]);

const { backgroundColor, textColor } = this.getColors();
const showEmbeddedRoamBlock =
!isPageUid(shape.props.uid) && isLiveBlock(shape.props.uid);

// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
Expand Down Expand Up @@ -737,7 +719,6 @@ export class BaseDiscourseNodeUtil extends BaseBoxShapeUtil<DiscourseNodeShape>
) : null}

<div
ref={contentRef}
className="relative"
style={{
...DEFAULT_STYLE_PROPS,
Expand All @@ -760,10 +741,21 @@ export class BaseDiscourseNodeUtil extends BaseBoxShapeUtil<DiscourseNodeShape>
/>
</div>
)}
{alias
? new RegExp(alias).exec(shape.props.title)?.[1] ||
shape.props.title
: shape.props.title}
{showEmbeddedRoamBlock ? (
<div className="w-full min-w-0">
<RenderRoamBlockString
key={shape.props.uid}
string={
getTextByBlockUid(shape.props.uid) || shape.props.title
}
Comment thread
mdroidian marked this conversation as resolved.
/>
</div>
) : alias ? (
new RegExp(alias).exec(shape.props.title)?.[1] ||
shape.props.title
) : (
shape.props.title
)}
</div>
</div>
</HTMLContainer>
Expand Down
Loading