11/* eslint-disable @typescript-eslint/naming-convention */
22import React , { useEffect , useState } from "react" ;
3- import { Button , Intent } from "@blueprintjs/core" ;
3+ import { Button , Intent , Tabs , Tab , TabId } from "@blueprintjs/core" ;
44import { getFormattedConfigTree } from "~/utils/discourseConfigRef" ;
55import FlagPanel from "roamjs-components/components/ConfigPanels/FlagPanel" ;
66import PageGroupsPanel from "./PageGroupPanel" ;
@@ -16,89 +16,122 @@ const SuggestiveModeSettings = () => {
1616 const [ suggestiveModeUid , setSuggestiveModeUid ] = useState (
1717 settings . suggestiveMode . parentUid ,
1818 ) ;
19- const [ pageGroupsUid , setPageGroupsUid ] = useState (
20- settings . suggestiveMode . pageGroups . uid ,
19+ const pageGroupsUid = settings . suggestiveMode . pageGroups . uid ;
20+
21+ const [ includePageRelations , setIncludePageRelations ] = useState (
22+ settings . suggestiveMode . includePageRelations . value ,
2123 ) ;
24+
2225 useEffect ( ( ) => {
23- if ( pageGroupsUid ) return ;
26+ if ( suggestiveModeUid ) return ;
2427 void ( async ( ) => {
2528 const smUid = await createBlock ( {
2629 parentUid : getPageUidByPageTitle ( DISCOURSE_CONFIG_PAGE_TITLE ) ,
2730 node : { text : "Suggestive Mode" } ,
2831 } ) ;
29- const pgUid = await createBlock ( {
30- parentUid : smUid ,
31- node : { text : "Page Groups" } ,
32- } ) ;
3332 setSuggestiveModeUid ( smUid ) ;
34- setPageGroupsUid ( pgUid ) ;
3533 } ) ( ) ;
36- } , [ pageGroupsUid ] ) ;
34+ } , [ suggestiveModeUid ] ) ;
3735
3836 const effectiveSuggestiveModeUid =
3937 suggestiveModeUid || settings . suggestiveMode . parentUid ;
4038
39+ const [ selectedTabId , setSelectedTabId ] = useState < TabId > ( "page-groups" ) ;
40+
4141 return (
42- < div className = "relative flex flex-col gap-4 p-1" >
43- < div className = "mt-4" >
44- < Button
45- icon = "cloud-upload"
46- text = { "Generate & Upload All Node Embeddings" }
47- onClick = { ( ) =>
48- void ( async ( ) => {
49- renderToast ( {
50- id : "discourse-embedding-start" ,
51- content :
52- "Creating and uploading your discourse node's embeddings to supabase" ,
53- intent : "primary" ,
54- timeout : 3000 ,
55- } ) ;
56- try {
57- await createOrUpdateDiscourseEmbedding ( ) ;
58- } catch ( e ) {
59- console . error ( "Failed to generate embeddings" , e ) ;
60- renderToast ( {
61- id : "discourse-embedding-error" ,
62- content : "Embedding generation failed. Check the console." ,
63- intent : "danger" ,
64- timeout : 5000 ,
65- } ) ;
66- }
67- } ) ( )
42+ < >
43+ < Tabs
44+ onChange = { ( id ) => setSelectedTabId ( id ) }
45+ selectedTabId = { selectedTabId }
46+ renderActiveTabPanelOnly = { true }
47+ >
48+ < Tab
49+ id = "page-groups"
50+ title = "Page Groups"
51+ panel = {
52+ < div className = "flex flex-col gap-4 p-1" >
53+ < PageGroupsPanel
54+ key = { pageGroupsUid }
55+ uid = { pageGroupsUid }
56+ initialGroups = { settings . suggestiveMode . pageGroups . groups }
57+ />
58+ </ div >
6859 }
69- intent = { Intent . PRIMARY }
70- className = { "mt-2" }
71- />
72- </ div >
73- < div className = "context-settings" >
74- < FlagPanel
75- title = "Include Current Page Relations"
76- description = "Include relations from pages referenced on the current page"
77- order = { 0 }
78- uid = { settings . suggestiveMode . includePageRelations . uid }
79- parentUid = { effectiveSuggestiveModeUid }
80- value = { settings . suggestiveMode . includePageRelations . value }
8160 />
61+ < Tab
62+ id = "sync-config"
63+ title = "Sync Config"
64+ panel = {
65+ < div className = "flex flex-col gap-4 p-1" >
66+ < div className = "sync-config-settings" >
67+ < FlagPanel
68+ title = "Include Current Page Relations"
69+ 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+ } }
79+ />
8280
83- { /* TODO: if "Include Current Page Relations" is checked "Include Parent and Child Blocks"
84- should be checked and disabled, use `selection` instead */ }
85- < FlagPanel
86- title = "Include Parent And Child Blocks"
87- description = "Include relations from parent and child blocks"
88- order = { 1 }
89- uid = { settings . suggestiveMode . includeParentAndChildren . uid }
90- parentUid = { effectiveSuggestiveModeUid }
91- value = { settings . suggestiveMode . includeParentAndChildren . value }
92- />
93- </ div >
94- < div className = "page-groups-settings" >
95- < PageGroupsPanel
96- key = { pageGroupsUid }
97- uid = { pageGroupsUid }
98- initialGroups = { settings . suggestiveMode . pageGroups . groups }
81+ < FlagPanel
82+ title = "Include Parent And Child Blocks"
83+ description = {
84+ includePageRelations
85+ ? "Include relations from parent and child blocks (automatically enabled when including page relations)"
86+ : "Include relations from parent and child blocks"
87+ }
88+ order = { 1 }
89+ uid = { settings . suggestiveMode . includeParentAndChildren . uid }
90+ parentUid = { effectiveSuggestiveModeUid }
91+ value = {
92+ includePageRelations
93+ ? true
94+ : settings . suggestiveMode . includeParentAndChildren . value
95+ }
96+ disabled = { includePageRelations }
97+ />
98+ </ div >
99+ < div className = "mt-4" >
100+ < Button
101+ icon = "cloud-upload"
102+ text = { "Generate & Upload All Node Embeddings" }
103+ onClick = { ( ) =>
104+ void ( async ( ) => {
105+ renderToast ( {
106+ id : "discourse-embedding-start" ,
107+ content :
108+ "Creating and uploading your discourse node's embeddings to supabase" ,
109+ intent : "primary" ,
110+ timeout : 3000 ,
111+ } ) ;
112+ try {
113+ await createOrUpdateDiscourseEmbedding ( ) ;
114+ } catch ( e ) {
115+ console . error ( "Failed to generate embeddings" , e ) ;
116+ renderToast ( {
117+ id : "discourse-embedding-error" ,
118+ content :
119+ "Embedding generation failed. Check the console." ,
120+ intent : "danger" ,
121+ timeout : 5000 ,
122+ } ) ;
123+ }
124+ } ) ( )
125+ }
126+ intent = { Intent . PRIMARY }
127+ className = { "mt-2" }
128+ />
129+ </ div >
130+ </ div >
131+ }
99132 />
100- </ div >
101- </ div >
133+ </ Tabs >
134+ </ >
102135 ) ;
103136} ;
104137
0 commit comments