Skip to content

Commit cd7e227

Browse files
committed
address review
1 parent 30de848 commit cd7e227

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

apps/roam/src/components/settings/components/EphemeralBlocksPanel.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const serializeBlockTree = (children: TreeNode[]): RoamNodeType[] =>
2020
.sort((a, b) => a.order - b.order)
2121
.map((child) => ({
2222
text: child.text,
23+
...(child.heading && { heading: child.heading as 0 | 1 | 2 | 3 }),
24+
...(child.open === false && { open: false }),
2325
...(child.children.length > 0 && {
2426
children: serializeBlockTree(child.children),
2527
}),
@@ -49,24 +51,29 @@ const DualWriteBlocksPanel = ({
4951

5052
useEffect(() => {
5153
const el = containerRef.current;
52-
if (!el) return;
54+
if (!el || !uid) return;
55+
56+
const pattern = "[:block/string :block/order {:block/children ...}]";
57+
const entityId = `[:block/uid "${uid}"]`;
58+
const callback = () => handleChange();
59+
60+
const registerPullWatch = () => {
61+
pullWatchArgsRef.current = [pattern, entityId, callback];
62+
window.roamAlphaAPI.data.addPullWatch(pattern, entityId, callback);
63+
};
5364

5465
if (!getFirstChildUidByBlockUid(uid)) {
5566
void createBlock({ node: { text: " " }, parentUid: uid }).then(() => {
5667
el.innerHTML = "";
5768
void window.roamAlphaAPI.ui.components.renderBlock({ uid, el });
69+
registerPullWatch();
5870
});
5971
} else {
6072
el.innerHTML = "";
6173
void window.roamAlphaAPI.ui.components.renderBlock({ uid, el });
74+
registerPullWatch();
6275
}
6376

64-
const pattern = "[:block/string :block/order {:block/children ...}]";
65-
const entityId = `[:block/uid "${uid}"]`;
66-
const callback = () => handleChange();
67-
pullWatchArgsRef.current = [pattern, entityId, callback];
68-
window.roamAlphaAPI.data.addPullWatch(pattern, entityId, callback);
69-
7077
return () => {
7178
window.clearTimeout(debounceRef.current);
7279
if (pullWatchArgsRef.current) {

0 commit comments

Comments
 (0)