11import React , { useCallback , useEffect , useMemo , useState , memo } from "react" ;
22import { Button , ButtonGroup , Collapse } from "@blueprintjs/core" ;
3- import FlagPanel from "roamjs-components/components/ConfigPanels/FlagPanel" ;
3+ import { GlobalFlagPanel } from "~/components/settings/components/BlockPropSettingPanels" ;
4+ import { setGlobalSetting } from "~/components/settings/utils/accessors" ;
45import AutocompleteInput from "roamjs-components/components/AutocompleteInput" ;
56import getAllPageNames from "roamjs-components/queries/getAllPageNames" ;
67import createBlock from "roamjs-components/writes/createBlock" ;
@@ -19,6 +20,8 @@ import getPageTitleByPageUid from "roamjs-components/queries/getPageTitleByPageU
1920import getTextByBlockUid from "roamjs-components/queries/getTextByBlockUid" ;
2021import posthog from "posthog-js" ;
2122
23+ const pagesToUids = ( pages : RoamBasicNode [ ] ) => pages . map ( ( p ) => p . text ) ;
24+
2225const PageItem = memo (
2326 ( {
2427 page,
@@ -160,6 +163,7 @@ const LeftSidebarGlobalSectionsContent = ({
160163 newPages . splice ( newIndex , 0 , removed ) ;
161164
162165 setPages ( newPages ) ;
166+ setGlobalSetting ( [ "Left sidebar" , "Children" ] , pagesToUids ( newPages ) ) ;
163167
164168 if ( childrenUid ) {
165169 const order = direction === "down" ? newIndex + 1 : newIndex ;
@@ -201,7 +205,13 @@ const LeftSidebarGlobalSectionsContent = ({
201205 children : [ ] ,
202206 } ;
203207
204- setPages ( ( prev ) => [ ...prev , newPage ] ) ;
208+ const updatedPages = [ ...pages , newPage ] ;
209+ setPages ( updatedPages ) ;
210+ setGlobalSetting (
211+ [ "Left sidebar" , "Children" ] ,
212+ pagesToUids ( updatedPages ) ,
213+ ) ;
214+
205215 setNewPageInput ( "" ) ;
206216 setAutocompleteKey ( ( prev ) => prev + 1 ) ;
207217 posthog . capture ( "Left Sidebar Global Settings: Page Added" , {
@@ -219,19 +229,28 @@ const LeftSidebarGlobalSectionsContent = ({
219229 [ childrenUid , pages ] ,
220230 ) ;
221231
222- const removePage = useCallback ( async ( page : RoamBasicNode ) => {
223- try {
224- await deleteBlock ( page . uid ) ;
225- setPages ( ( prev ) => prev . filter ( ( p ) => p . uid !== page . uid ) ) ;
226- refreshAndNotify ( ) ;
227- } catch ( error ) {
228- renderToast ( {
229- content : "Failed to remove page" ,
230- intent : "danger" ,
231- id : "remove-page-error" ,
232- } ) ;
233- }
234- } , [ ] ) ;
232+ const removePage = useCallback (
233+ async ( page : RoamBasicNode ) => {
234+ try {
235+ await deleteBlock ( page . uid ) ;
236+ const updatedPages = pages . filter ( ( p ) => p . uid !== page . uid ) ;
237+ setPages ( updatedPages ) ;
238+ setGlobalSetting (
239+ [ "Left sidebar" , "Children" ] ,
240+ pagesToUids ( updatedPages ) ,
241+ ) ;
242+
243+ refreshAndNotify ( ) ;
244+ } catch ( error ) {
245+ renderToast ( {
246+ content : "Failed to remove page" ,
247+ intent : "danger" ,
248+ id : "remove-page-error" ,
249+ } ) ;
250+ }
251+ } ,
252+ [ pages ] ,
253+ ) ;
235254
236255 const handlePageInputChange = useCallback ( ( value : string ) => {
237256 setNewPageInput ( value ) ;
@@ -263,21 +282,24 @@ const LeftSidebarGlobalSectionsContent = ({
263282 border : "1px solid rgba(51, 51, 51, 0.2)" ,
264283 } }
265284 >
266- < FlagPanel
285+ < GlobalFlagPanel
267286 title = "Folded"
268287 description = "If children are present, start with global section collapsed in left sidebar"
288+ settingKeys = { [ "Left sidebar" , "Settings" , "Folded" ] }
289+ initialValue = { globalSection . settings ?. folded ?. value || false }
269290 order = { 0 }
270291 uid = { globalSection . settings ?. folded ?. uid || "" }
271292 parentUid = { globalSection . settings ?. uid || "" }
272293 disabled = { ! globalSection . children ?. length }
273294 />
274- < FlagPanel
295+ < GlobalFlagPanel
275296 title = "Collapsable"
276297 description = "Make global section collapsable"
298+ settingKeys = { [ "Left sidebar" , "Settings" , "Collapsable" ] }
299+ initialValue = { globalSection . settings ?. collapsable ?. value || false }
277300 order = { 1 }
278301 uid = { globalSection . settings ?. collapsable ?. uid || "" }
279302 parentUid = { globalSection . settings ?. uid || "" }
280- value = { globalSection . settings ?. collapsable ?. value || false }
281303 />
282304 </ div >
283305
0 commit comments