22import React , { useEffect , useState } from "react" ;
33import { Button , Intent , Tabs , Tab , TabId } from "@blueprintjs/core" ;
44import { getFormattedConfigTree } from "~/utils/discourseConfigRef" ;
5- import FlagPanel from "roamjs-components/components/ConfigPanels/FlagPanel" ;
65import PageGroupsPanel from "./PageGroupPanel" ;
76import createBlock from "roamjs-components/writes/createBlock" ;
87import getPageUidByPageTitle from "roamjs-components/queries/getPageUidByPageTitle" ;
98import { DISCOURSE_CONFIG_PAGE_TITLE } from "~/utils/renderNodeConfigPage" ;
109import { createOrUpdateDiscourseEmbedding } from "~/utils/syncDgNodesToSupabase" ;
1110import { render as renderToast } from "roamjs-components/components/Toast" ;
11+ import { BlockPropFlagPanel } from "./components/BlockPropGlobalSettingPanels" ;
12+ import { getGlobalSetting } from "./utils/accessors" ;
1213
1314const SuggestiveModeSettings = ( ) => {
15+ // Keep old config tree for PageGroups (not yet migrated)
1416 const settings = getFormattedConfigTree ( ) ;
17+ const pageGroupsUid = settings . suggestiveMode . pageGroups . uid ;
1518
1619 const [ suggestiveModeUid , setSuggestiveModeUid ] = useState (
1720 settings . suggestiveMode . parentUid ,
1821 ) ;
19- const pageGroupsUid = settings . suggestiveMode . pageGroups . uid ;
2022
21- const [ includePageRelations , setIncludePageRelations ] = useState (
22- settings . suggestiveMode . includePageRelations . value ,
23+ // Track includePageRelations to control the disabled state of includeParentAndChildren
24+ const [ includePageRelations , setIncludePageRelations ] = useState ( ( ) =>
25+ getGlobalSetting < boolean > ( [
26+ "Suggestive Mode" ,
27+ "Include Current Page Relations" ,
28+ ] ) ,
2329 ) ;
2430
31+ // Keep this useEffect for PageGroups compatibility (old system)
2532 useEffect ( ( ) => {
2633 if ( suggestiveModeUid ) return ;
2734 void ( async ( ) => {
@@ -33,9 +40,6 @@ const SuggestiveModeSettings = () => {
3340 } ) ( ) ;
3441 } , [ suggestiveModeUid ] ) ;
3542
36- const effectiveSuggestiveModeUid =
37- suggestiveModeUid || settings . suggestiveMode . parentUid ;
38-
3943 const [ selectedTabId , setSelectedTabId ] = useState < TabId > ( "page-groups" ) ;
4044
4145 return (
@@ -64,35 +68,21 @@ const SuggestiveModeSettings = () => {
6468 panel = {
6569 < div className = "flex flex-col gap-4 p-1" >
6670 < div className = "sync-config-settings" >
67- < FlagPanel
71+ < BlockPropFlagPanel
6872 title = "Include Current Page Relations"
6973 description = "Include relations from pages referenced on the current page"
70- order = { 0 }
71- uid = { settings . suggestiveMode . includePageRelations . uid }
72- parentUid = { effectiveSuggestiveModeUid }
73- value = { includePageRelations }
74- options = { {
75- onChange : ( checked : boolean ) => {
76- setIncludePageRelations ( checked ) ;
77- } ,
78- } }
74+ settingKeys = { [ "Suggestive Mode" , "Include Current Page Relations" ] }
75+ onChange = { setIncludePageRelations }
7976 />
8077
81- < FlagPanel
78+ < BlockPropFlagPanel
8279 title = "Include Parent And Child Blocks"
8380 description = {
8481 includePageRelations
8582 ? "Include relations from parent and child blocks (automatically enabled when including page relations)"
8683 : "Include relations from parent and child blocks"
8784 }
88- order = { 1 }
89- uid = { settings . suggestiveMode . includeParentAndChildren . uid }
90- parentUid = { effectiveSuggestiveModeUid }
91- value = {
92- includePageRelations
93- ? true
94- : settings . suggestiveMode . includeParentAndChildren . value
95- }
85+ settingKeys = { [ "Suggestive Mode" , "Include Parent And Child Blocks" ] }
9686 disabled = { includePageRelations }
9787 />
9888 </ div >
0 commit comments