ENG-1549: Add convert existing page to discourse node command#987
Open
ENG-1549: Add convert existing page to discourse node command#987
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
mdroidian
requested changes
May 5, 2026
| createOverride?: (args: { | ||
| formattedTitle: string; | ||
| configPageUid: string; | ||
| }) => Promise<string | void>; |
| const configPageUid = selectedNodeType?.type ?? ""; | ||
| const overrideUid = createOverride | ||
| ? await createOverride({ formattedTitle, configPageUid }) | ||
| : undefined; |
Member
There was a problem hiding this comment.
Could we just do a single const:
const overrideUid = createOverride
? await createOverride({ formattedTitle, configPageUid })
: await createDiscourseNode({
text: formattedTitle,
configPageUid,
extensionAPI,
imageUrl,
});
Comment on lines
+169
to
+205
| const nodeTree = getFullTreeByParentUid(configPageUid).children; | ||
| const templateNode = getSubTree({ tree: nodeTree, key: "template" }); | ||
| if (templateNode.children.length > 0) { | ||
| const hasSmartBlockSyntax = ( | ||
| node: Parameters<typeof stripUid>[0][0], | ||
| ): boolean => { | ||
| if (node.text.includes("<%")) return true; | ||
| if (node.children) return node.children.some(hasSmartBlockSyntax); | ||
| return false; | ||
| }; | ||
| const useSmartBlocks = hasSmartBlockSyntax(templateNode); | ||
|
|
||
| if (useSmartBlocks && window.roamjs?.extension?.smartblocks) { | ||
| void window.roamjs.extension.smartblocks?.triggerSmartblock({ | ||
| srcUid: templateNode.uid, | ||
| targetUid: pageUid, | ||
| }); | ||
| } else { | ||
| if (useSmartBlocks) { | ||
| renderToast({ | ||
| content: | ||
| "This template requires SmartBlocks. Enable SmartBlocks in Roam Depot to use this template.", | ||
| id: "smartblocks-extension-disabled", | ||
| intent: "warning", | ||
| }); | ||
| } | ||
| const existingChildren = | ||
| getFullTreeByParentUid(pageUid).children || []; | ||
| const lastOrder = existingChildren.length; | ||
| await Promise.all( | ||
| stripUid(templateNode.children).map((node, order) => | ||
| createBlock({ | ||
| node, | ||
| order: lastOrder + order, | ||
| parentUid: pageUid, | ||
| }), | ||
| ), |
Member
There was a problem hiding this comment.
This looks like code that is used elsewhere. Can we DRY it?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://www.loom.com/share/ace42b9d8d66415b9143d4d4a164cfc1