@@ -32,6 +32,7 @@ import {
3232 isQueryBlockRef ,
3333 type LeftSidebarConfig ,
3434 type LeftSidebarPersonalSectionConfig ,
35+ getGlobalSectionFoldedMarkerText ,
3536 mergeGlobalSectionWithAccessor ,
3637 mergePersonalSectionsWithAccessor ,
3738} from "~/utils/getLeftSidebarSettings" ;
@@ -51,7 +52,6 @@ import {
5152 PERSONAL_KEYS ,
5253 GLOBAL_KEYS ,
5354 LEFT_SIDEBAR_KEYS ,
54- LEFT_SIDEBAR_SETTINGS_KEYS ,
5555} from "~/components/settings/utils/settingKeys" ;
5656import type { LeftSidebarGlobalSettings } from "~/components/settings/utils/zodSchema" ;
5757import { createBlock } from "roamjs-components/writes" ;
@@ -617,53 +617,45 @@ const PersonalSections = ({
617617
618618const GlobalSection = ( {
619619 config,
620+ folded,
621+ leftSidebarUid,
620622 onGlobalChildrenReorder,
621623 onloadArgs,
622624} : {
623625 config : LeftSidebarConfig [ "global" ] ;
626+ folded : boolean ;
627+ leftSidebarUid : string ;
624628 onGlobalChildrenReorder : ( oldIndex : number , newIndex : number ) => void ;
625629 onloadArgs : OnloadArgs ;
626630} ) => {
627- const [ isOpen , setIsOpen ] = useState < boolean > ( ! config . settings ?. folded . value ) ;
631+ const [ isOpen , setIsOpen ] = useState < boolean > ( ! folded ) ;
628632 const isTogglingRef = useRef ( false ) ;
629633 if ( ! config . children ?. length ) return null ;
630- const isCollapsable = config . settings ?. collapsable . value ;
631634
632635 const handleToggle = async ( ) => {
633- if ( ! isCollapsable || ! config . settings ) return ;
634636 if ( isTogglingRef . current ) return ;
635637 isTogglingRef . current = true ;
636638 try {
637- const settings = config . settings ;
638639 const nextIsOpen = ! isOpen ;
639640 setIsOpen ( nextIsOpen ) ;
641+ const markerText = getGlobalSectionFoldedMarkerText (
642+ window . roamAlphaAPI . user . uid ( ) || "" ,
643+ ) ;
640644 if ( nextIsOpen ) {
641- const children = getBasicTreeByParentUid ( settings . uid ) ;
645+ const children = getBasicTreeByParentUid ( leftSidebarUid ) ;
642646 await Promise . all (
643647 children
644- . filter ( ( c ) => c . text === "Folded" )
648+ . filter ( ( c ) => c . text === markerText )
645649 . map ( ( c ) => deleteBlock ( c . uid ) ) ,
646650 ) ;
647- settings . folded . uid = undefined ;
648- settings . folded . value = false ;
649651 } else {
650- const newUid = window . roamAlphaAPI . util . generateUID ( ) ;
651652 await createBlock ( {
652- parentUid : settings . uid ,
653- node : { text : "Folded" , uid : newUid } ,
653+ parentUid : leftSidebarUid ,
654+ node : { text : markerText } ,
654655 } ) ;
655- settings . folded . uid = newUid ;
656- settings . folded . value = true ;
657656 }
658657 refreshConfigTree ( ) ;
659- setGlobalSetting (
660- [
661- GLOBAL_KEYS . leftSidebar ,
662- LEFT_SIDEBAR_KEYS . settings ,
663- LEFT_SIDEBAR_SETTINGS_KEYS . folded ,
664- ] ,
665- ! nextIsOpen ,
666- ) ;
658+ setPersonalSetting ( [ PERSONAL_KEYS . globalSectionFolded ] , ! nextIsOpen ) ;
667659 } finally {
668660 isTogglingRef . current = false ;
669661 }
@@ -690,18 +682,12 @@ const GlobalSection = ({
690682 >
691683 < div className = "flex w-full items-center justify-between" >
692684 < span > GLOBAL</ span >
693- { isCollapsable && (
694- < span className = "sidebar-title-button-chevron p-1" >
695- < Icon icon = { isOpen ? "chevron-down" : "chevron-right" } />
696- </ span >
697- ) }
685+ < span className = "sidebar-title-button-chevron p-1" >
686+ < Icon icon = { isOpen ? "chevron-down" : "chevron-right" } />
687+ </ span >
698688 </ div >
699689 </ div >
700- { isCollapsable ? (
701- < Collapse isOpen = { isOpen } > { children } </ Collapse >
702- ) : (
703- children
704- ) }
690+ < Collapse isOpen = { isOpen } > { children } </ Collapse >
705691 </ >
706692 ) ;
707693} ;
@@ -718,6 +704,9 @@ const buildConfig = (snapshot?: SettingsSnapshot): LeftSidebarConfig => {
718704 : getPersonalSetting <
719705 ReturnType < typeof getPersonalSettings > [ typeof PERSONAL_KEYS . leftSidebar ]
720706 > ( [ PERSONAL_KEYS . leftSidebar ] ) ;
707+ const globalSectionFoldedValue = snapshot
708+ ? snapshot . personalSettings [ PERSONAL_KEYS . globalSectionFolded ]
709+ : getPersonalSetting < boolean > ( [ PERSONAL_KEYS . globalSectionFolded ] ) ;
721710
722711 // Read UIDs from old system (needed for fold CRUD during dual-write)
723712 const oldConfig = getCurrentLeftSidebarConfig ( ) ;
@@ -727,6 +716,10 @@ const buildConfig = (snapshot?: SettingsSnapshot): LeftSidebarConfig => {
727716 favoritesMigrated : oldConfig . favoritesMigrated ,
728717 sidebarMigrated : oldConfig . sidebarMigrated ,
729718 global : mergeGlobalSectionWithAccessor ( oldConfig . global , globalValues ) ,
719+ globalSectionFolded : {
720+ uid : oldConfig . globalSectionFolded . uid ,
721+ value : globalSectionFoldedValue ?? oldConfig . globalSectionFolded . value ,
722+ } ,
730723 personal : {
731724 uid : oldConfig . personal . uid ,
732725 sections : mergePersonalSectionsWithAccessor (
@@ -916,6 +909,8 @@ const LeftSidebarView = ({
916909 < FavoritesPopover onloadArgs = { onloadArgs } />
917910 < GlobalSection
918911 config = { config . global }
912+ folded = { config . globalSectionFolded . value }
913+ leftSidebarUid = { config . uid }
919914 onGlobalChildrenReorder = { reorderGlobalChildren }
920915 onloadArgs = { onloadArgs }
921916 />
0 commit comments