@@ -7,15 +7,16 @@ import {
77 Icon ,
88 ControlGroup ,
99} from "@blueprintjs/core" ;
10- import React , { useState , useMemo } from "react" ;
11- import getBasicTreeByParentUid from "roamjs-components/queries/getBasicTreeByParentUid" ;
12- import getSettingValueFromTree from "roamjs-components/util/getSettingValueFromTree" ;
10+ import React , { useState } from "react" ;
1311import setInputSetting from "roamjs-components/util/setInputSetting" ;
1412import {
1513 DiscourseNodeFlagPanel ,
1614 DiscourseNodeTextPanel ,
1715} from "./components/BlockPropSettingPanels" ;
18- import { setDiscourseNodeSetting } from "~/components/settings/utils/accessors" ;
16+ import {
17+ getDiscourseNodeSetting ,
18+ setDiscourseNodeSetting ,
19+ } from "~/components/settings/utils/accessors" ;
1920
2021export const formatHexColor = ( color : string ) => {
2122 if ( ! color ) return "" ;
@@ -36,20 +37,35 @@ const DiscourseNodeCanvasSettings = ({
3637 nodeType : string ;
3738 uid : string ;
3839} ) => {
39- const tree = useMemo ( ( ) => getBasicTreeByParentUid ( uid ) , [ uid ] ) ;
4040 const [ color , setColor ] = useState < string > ( ( ) => {
41- const color = getSettingValueFromTree ( { tree, key : "color" } ) ;
41+ const color =
42+ getDiscourseNodeSetting < string > ( nodeType , [ "canvasSettings" , "color" ] ) ??
43+ "" ;
4244 return formatHexColor ( color ) ;
4345 } ) ;
44- const alias = getSettingValueFromTree ( { tree, key : "alias" } ) ;
45- const [ queryBuilderAlias , setQueryBuilderAlias ] = useState < string > ( ( ) =>
46- getSettingValueFromTree ( { tree, key : "query-builder-alias" } ) ,
46+ const alias =
47+ getDiscourseNodeSetting < string > ( nodeType , [ "canvasSettings" , "alias" ] ) ??
48+ "" ;
49+ const [ queryBuilderAlias , setQueryBuilderAlias ] = useState < string > (
50+ ( ) =>
51+ getDiscourseNodeSetting < string > ( nodeType , [
52+ "canvasSettings" ,
53+ "query-builder-alias" ,
54+ ] ) ?? "" ,
4755 ) ;
4856 const [ isKeyImage , setIsKeyImage ] = useState (
49- ( ) => getSettingValueFromTree ( { tree, key : "key-image" } ) === "true" ,
57+ ( ) =>
58+ getDiscourseNodeSetting < boolean > ( nodeType , [
59+ "canvasSettings" ,
60+ "key-image" ,
61+ ] ) ?? false ,
5062 ) ;
51- const [ keyImageOption , setKeyImageOption ] = useState ( ( ) =>
52- getSettingValueFromTree ( { tree, key : "key-image-option" } ) ,
63+ const [ keyImageOption , setKeyImageOption ] = useState (
64+ ( ) =>
65+ getDiscourseNodeSetting < string > ( nodeType , [
66+ "canvasSettings" ,
67+ "key-image-option" ,
68+ ] ) ?? "" ,
5369 ) ;
5470
5571 return (
0 commit comments