@@ -45,6 +45,7 @@ export type LeftSidebarConfig = {
4545 favoritesMigrated : BooleanSetting ;
4646 sidebarMigrated : BooleanSetting ;
4747 global : LeftSidebarGlobalSectionConfig ;
48+ allPersonalSections : AllUsersPersonalSections ;
4849 personal : {
4950 uid : string ;
5051 sections : LeftSidebarPersonalSectionConfig [ ] ;
@@ -125,14 +126,22 @@ const getPersonalSectionSettings = (
125126 } ;
126127} ;
127128
129+ export type AllUsersPersonalSections = {
130+ [ userUid : string ] : {
131+ uid : string ;
132+ sections : LeftSidebarPersonalSectionConfig [ ] ;
133+ } ;
134+ } ;
135+
128136export const getLeftSidebarPersonalSectionConfig = (
129137 leftSidebarChildren : RoamBasicNode [ ] ,
138+ userUid ?: string ,
130139) : { uid : string ; sections : LeftSidebarPersonalSectionConfig [ ] } => {
131- const userUid = window . roamAlphaAPI . user . uid ( ) ;
140+ const targetUserUid = userUid ?? window . roamAlphaAPI . user . uid ( ) ;
132141
133142 const personalLeftSidebarNode = getSubTree ( {
134143 tree : leftSidebarChildren ,
135- key : userUid + "/Personal-Section" ,
144+ key : targetUserUid + "/Personal-Section" ,
136145 } ) ;
137146
138147 if ( personalLeftSidebarNode . uid === "" ) {
@@ -173,7 +182,23 @@ export const getLeftSidebarPersonalSectionConfig = (
173182 sections,
174183 } ;
175184} ;
185+ export const getAllLeftSidebarPersonalSectionConfigs = (
186+ leftSidebarChildren : RoamBasicNode [ ] ,
187+ ) : AllUsersPersonalSections => {
188+ const result : AllUsersPersonalSections = { } ;
189+
190+ leftSidebarChildren
191+ . filter ( ( node ) => node . text . endsWith ( "/Personal-Section" ) )
192+ . forEach ( ( node ) => {
193+ const userUid = node . text . replace ( "/Personal-Section" , "" ) ;
194+ result [ userUid ] = getLeftSidebarPersonalSectionConfig (
195+ leftSidebarChildren ,
196+ userUid ,
197+ ) ;
198+ } ) ;
176199
200+ return result ;
201+ } ;
177202export const getLeftSidebarSettings = (
178203 globalTree : RoamBasicNode [ ] ,
179204) : LeftSidebarConfig => {
@@ -184,6 +209,9 @@ export const getLeftSidebarSettings = (
184209 const leftSidebarChildren = leftSidebarNode ?. children || [ ] ;
185210 const global = getLeftSidebarGlobalSectionConfig ( leftSidebarChildren ) ;
186211 const personal = getLeftSidebarPersonalSectionConfig ( leftSidebarChildren ) ;
212+ // TODO: remove this on complete migration task [ENG-1171: Remove `migrateLeftSideBarSettings`](https://linear.app/discourse-graphs/issue/ENG-1171/remove-migrateleftsidebarsettings)
213+ const allPersonalSections =
214+ getAllLeftSidebarPersonalSectionConfigs ( leftSidebarChildren ) ;
187215 const favoritesMigrated = getUidAndBooleanSetting ( {
188216 tree : leftSidebarChildren ,
189217 text : "Favorites Migrated" ,
@@ -198,5 +226,6 @@ export const getLeftSidebarSettings = (
198226 sidebarMigrated,
199227 global,
200228 personal,
229+ allPersonalSections,
201230 } ;
202231} ;
0 commit comments