@@ -4,17 +4,14 @@ import { createPage, createBlock } from "roamjs-components/writes";
44import setBlockProps from "~/utils/setBlockProps" ;
55import getBlockProps from "~/utils/getBlockProps" ;
66import type { json } from "~/utils/getBlockProps" ;
7- import INITIAL_NODE_VALUES from "~/data/defaultDiscourseNodes" ;
87import DEFAULT_RELATIONS_BLOCK_PROPS from "~/components/settings/data/defaultRelationsBlockProps" ;
9- import { getAllDiscourseNodes } from "./accessors" ;
10- import {
11- DiscourseNodeSchema ,
12- getTopLevelBlockPropsConfig ,
13- } from "~/components/settings/utils/zodSchema" ;
14- import {
15- DG_BLOCK_PROP_SETTINGS_PAGE_TITLE ,
16- DISCOURSE_NODE_PAGE_PREFIX ,
17- } from "./zodSchema" ;
8+ import { getTopLevelBlockPropsConfig } from "~/components/settings/utils/zodSchema" ;
9+ import { DG_BLOCK_PROP_SETTINGS_PAGE_TITLE } from "./zodSchema" ;
10+ // TODO: Re-enable when initDiscourseNodePages is uncommented
11+ // import INITIAL_NODE_VALUES from "~/data/defaultDiscourseNodes";
12+ // import { getAllDiscourseNodes } from "./accessors";
13+ // import { DiscourseNodeSchema } from "~/components/settings/utils/zodSchema";
14+ // import { DISCOURSE_NODE_PAGE_PREFIX } from "./zodSchema";
1815import toFlexRegex from "roamjs-components/util/toFlexRegex" ;
1916
2017const ensurePageExists = async ( pageTitle : string ) : Promise < string > => {
@@ -113,61 +110,65 @@ const initSettingsPageBlocks = async (): Promise<Record<string, string>> => {
113110 return blockMap ;
114111} ;
115112
116- const hasNonDefaultNodes = ( ) : boolean => {
117- return getAllDiscourseNodes ( ) . some ( ( node ) => node . backedBy !== "default" ) ;
118- } ;
119-
120- const initSingleDiscourseNode = async (
121- node : ( typeof INITIAL_NODE_VALUES ) [ number ] ,
122- ) : Promise < { label : string ; pageUid : string } | null > => {
123- if ( ! node . text ) return null ;
124-
125- const pageUid = await ensurePageExists (
126- `${ DISCOURSE_NODE_PAGE_PREFIX } ${ node . text } ` ,
127- ) ;
128- const existingProps = getBlockProps ( pageUid ) ;
129-
130- if ( ! existingProps || Object . keys ( existingProps ) . length === 0 ) {
131- const nodeData = DiscourseNodeSchema . parse ( {
132- text : node . text ,
133- type : node . type ,
134- format : node . format || "" ,
135- shortcut : node . shortcut || "" ,
136- tag : node . tag || "" ,
137- graphOverview : node . graphOverview ?? false ,
138- canvasSettings : node . canvasSettings || { } ,
139- backedBy : "default" ,
140- } ) ;
141-
142- setBlockProps ( pageUid , nodeData , false ) ;
143- }
144-
145- return { label : node . text , pageUid } ;
146- } ;
147-
148- const initDiscourseNodePages = async ( ) : Promise < Record < string , string > > => {
149- if ( hasNonDefaultNodes ( ) ) {
150- const existingNodes = getAllDiscourseNodes ( ) ;
151- const nodePageUids : Record < string , string > = { } ;
152- for ( const node of existingNodes ) {
153- nodePageUids [ node . text ] = node . type ;
154- }
155- return nodePageUids ;
156- }
157-
158- const results = await Promise . all (
159- INITIAL_NODE_VALUES . map ( ( node ) => initSingleDiscourseNode ( node ) ) ,
160- ) ;
161-
162- const nodePageUids : Record < string , string > = { } ;
163- for ( const result of results ) {
164- if ( result ) {
165- nodePageUids [ result . label ] = result . pageUid ;
166- }
167- }
168-
169- return nodePageUids ;
170- } ;
113+ // TODO: Enable once we start reading discourse nodes from block props.
114+ // Currently initializeDiscourseNodes() (called earlier in index.ts) already
115+ // creates the node pages, so these are unused.
116+ //
117+ // const hasNonDefaultNodes = (): boolean => {
118+ // return getAllDiscourseNodes().some((node) => node.backedBy !== "default");
119+ // };
120+ //
121+ // const initSingleDiscourseNode = async (
122+ // node: (typeof INITIAL_NODE_VALUES)[number],
123+ // ): Promise<{ label: string; pageUid: string } | null> => {
124+ // if (!node.text) return null;
125+ //
126+ // const pageUid = await ensurePageExists(
127+ // `${DISCOURSE_NODE_PAGE_PREFIX}${node.text}`,
128+ // );
129+ // const existingProps = getBlockProps(pageUid);
130+ //
131+ // if (!existingProps || Object.keys(existingProps).length === 0) {
132+ // const nodeData = DiscourseNodeSchema.parse({
133+ // text: node.text,
134+ // type: node.type,
135+ // format: node.format || "",
136+ // shortcut: node.shortcut || "",
137+ // tag: node.tag || "",
138+ // graphOverview: node.graphOverview ?? false,
139+ // canvasSettings: node.canvasSettings || {},
140+ // backedBy: "default",
141+ // });
142+ //
143+ // setBlockProps(pageUid, nodeData, false);
144+ // }
145+ //
146+ // return { label: node.text, pageUid };
147+ // };
148+ //
149+ // const initDiscourseNodePages = async (): Promise<Record<string, string>> => {
150+ // if (hasNonDefaultNodes()) {
151+ // const existingNodes = getAllDiscourseNodes();
152+ // const nodePageUids: Record<string, string> = {};
153+ // for (const node of existingNodes) {
154+ // nodePageUids[node.text] = node.type;
155+ // }
156+ // return nodePageUids;
157+ // }
158+ //
159+ // const results = await Promise.all(
160+ // INITIAL_NODE_VALUES.map((node) => initSingleDiscourseNode(node)),
161+ // );
162+ //
163+ // const nodePageUids: Record<string, string> = {};
164+ // for (const result of results) {
165+ // if (result) {
166+ // nodePageUids[result.label] = result.pageUid;
167+ // }
168+ // }
169+ //
170+ // return nodePageUids;
171+ // };
171172
172173/**
173174 * Replace placeholder relation keys (_INFO-rel, etc.) in the Global blockprops
@@ -244,6 +245,9 @@ export type InitSchemaResult = {
244245
245246export const initSchema = async ( ) : Promise < InitSchemaResult > => {
246247 const blockUids = await initSettingsPageBlocks ( ) ;
247- const nodePageUids = await initDiscourseNodePages ( ) ;
248- return { blockUids, nodePageUids } ;
248+ // TODO: Enable once we start reading discourse nodes from block props.
249+ // Currently initializeDiscourseNodes() (called earlier in index.ts) already
250+ // creates the node pages, so this just duplicates work.
251+ // const nodePageUids = await initDiscourseNodePages();
252+ return { blockUids, nodePageUids : { } } ;
249253} ;
0 commit comments