@@ -30,7 +30,6 @@ import type {
3030 LeftSidebarConfig ,
3131 LeftSidebarPersonalSectionConfig ,
3232} from "~/utils/getLeftSidebarSettings" ;
33- import type { BooleanSetting } from "~/utils/getExportSettings" ;
3433import { createBlock } from "roamjs-components/writes" ;
3534import deleteBlock from "roamjs-components/writes/deleteBlock" ;
3635import getTextByBlockUid from "roamjs-components/queries/getTextByBlockUid" ;
@@ -41,6 +40,8 @@ import { OnloadArgs } from "roamjs-components/types";
4140import renderOverlay from "roamjs-components/util/renderOverlay" ;
4241import getBasicTreeByParentUid from "roamjs-components/queries/getBasicTreeByParentUid" ;
4342import { DISCOURSE_CONFIG_PAGE_TITLE } from "~/utils/renderNodeConfigPage" ;
43+ import getPageTitleByPageUid from "roamjs-components/queries/getPageTitleByPageUid" ;
44+ import { migrateLeftSidebarSettings } from "~/utils/migrateLeftSidebarSettings" ;
4445
4546const parseReference = ( text : string ) => {
4647 const extracted = extractRef ( text ) ;
@@ -56,10 +57,10 @@ const truncate = (s: string, max: number | undefined): string => {
5657 return s . length > max ? `${ s . slice ( 0 , max ) } ...` : s ;
5758} ;
5859
59- const openTarget = async ( e : React . MouseEvent , sectionTitle : string ) => {
60+ const openTarget = async ( e : React . MouseEvent , targetUid : string ) => {
6061 e . preventDefault ( ) ;
6162 e . stopPropagation ( ) ;
62- const target = parseReference ( sectionTitle ) ;
63+ const target = parseReference ( targetUid ) ;
6364 if ( target . type === "block" ) {
6465 if ( e . shiftKey ) {
6566 await openBlockInSidebar ( target . uid ) ;
@@ -71,16 +72,16 @@ const openTarget = async (e: React.MouseEvent, sectionTitle: string) => {
7172 return ;
7273 }
7374
74- const uid = getPageUidByPageTitle ( sectionTitle ) ;
75- if ( ! uid ) return ;
7675 if ( e . shiftKey ) {
7776 await window . roamAlphaAPI . ui . rightSidebar . addWindow ( {
7877 // @ts -expect-error - todo test
7978 // eslint-disable-next-line @typescript-eslint/naming-convention
80- window : { type : "outline" , "block-uid" : uid } ,
79+ window : { type : "outline" , "block-uid" : targetUid } ,
8180 } ) ;
8281 } else {
83- await window . roamAlphaAPI . ui . mainWindow . openPage ( { page : { uid } } ) ;
82+ await window . roamAlphaAPI . ui . mainWindow . openPage ( {
83+ page : { uid : targetUid } ,
84+ } ) ;
8485 }
8586} ;
8687
@@ -127,7 +128,11 @@ const SectionChildren = ({
127128 { childrenNodes . map ( ( child ) => {
128129 const ref = parseReference ( child . text ) ;
129130 const alias = child . alias ?. value ;
130- const label = alias || truncate ( ref . display , truncateAt ) ;
131+ const display =
132+ ref . type === "page"
133+ ? getPageTitleByPageUid ( ref . display )
134+ : getTextByBlockUid ( ref . uid ) ;
135+ const label = alias || truncate ( display , truncateAt ) ;
131136 const onClick = ( e : React . MouseEvent ) => {
132137 return void openTarget ( e , child . text ) ;
133138 } ;
@@ -184,7 +189,7 @@ const PersonalSectionItem = ({
184189 onClick = { ( ) => {
185190 if ( ( section . children ?. length || 0 ) > 0 ) {
186191 handleChevronClick ( ) ;
187- }
192+ }
188193 } }
189194 >
190195 { ( blockText || titleRef . display ) . toUpperCase ( ) }
@@ -410,13 +415,13 @@ const LeftSidebarView = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
410415} ;
411416
412417const migrateFavorites = async ( ) => {
413- const configPageUid = getPageUidByPageTitle ( DISCOURSE_CONFIG_PAGE_TITLE ) ;
414- if ( ! configPageUid ) return ;
415-
416418 const config = getFormattedConfigTree ( ) . leftSidebar ;
417419
418420 if ( config . favoritesMigrated . value ) return ;
419421
422+ const configPageUid = getPageUidByPageTitle ( DISCOURSE_CONFIG_PAGE_TITLE ) ;
423+ if ( ! configPageUid ) return ;
424+
420425 let leftSidebarUid = config . uid ;
421426 if ( leftSidebarUid ) {
422427 const leftSidebarTree = getBasicTreeByParentUid ( leftSidebarUid ) ;
@@ -434,11 +439,13 @@ const migrateFavorites = async () => {
434439 }
435440
436441 const results = window . roamAlphaAPI . q ( `
437- [:find ?title
442+ [:find ?uid
438443 :where [?e :page/sidebar]
439- [?e :node/title ?title ]]
444+ [?e :block/uid ?uid ]]
440445 ` ) ;
441- const titles = ( results as string [ ] [ ] ) . map ( ( [ title ] ) => title ) ;
446+ const favorites = ( results as string [ ] [ ] ) . map ( ( [ uid ] ) => ( {
447+ uid,
448+ } ) ) ;
442449
443450 if ( ! leftSidebarUid ) {
444451 const tree = getBasicTreeByParentUid ( configPageUid ) ;
@@ -482,13 +489,13 @@ const migrateFavorites = async () => {
482489 }
483490
484491 const childrenTree = getBasicTreeByParentUid ( childrenUid ) ;
485- const existingTitles = new Set ( childrenTree . map ( ( c ) => c . text ) ) ;
486- const newTitles = titles . filter ( ( t ) => ! existingTitles . has ( t ) ) ;
492+ const existingTexts = new Set ( childrenTree . map ( ( c ) => c . text ) ) ;
493+ const newFavorites = favorites . filter ( ( { uid } ) => ! existingTexts . has ( uid ) ) ;
487494
488- if ( newTitles . length > 0 ) {
495+ if ( newFavorites . length > 0 ) {
489496 await Promise . all (
490- newTitles . map ( ( text ) =>
491- createBlock ( { parentUid : childrenUid , node : { text } } ) ,
497+ newFavorites . map ( ( { uid } ) =>
498+ createBlock ( { parentUid : childrenUid , node : { text : uid } } ) ,
492499 ) ,
493500 ) ;
494501 refreshAndNotify ( ) ;
@@ -511,6 +518,7 @@ export const mountLeftSidebar = async (
511518 let root = wrapper . querySelector ( `#${ id } ` ) as HTMLDivElement ;
512519 if ( ! root ) {
513520 await migrateFavorites ( ) ;
521+ await migrateLeftSidebarSettings ( ) ;
514522 wrapper . innerHTML = "" ;
515523 root = document . createElement ( "div" ) ;
516524 root . id = id ;
0 commit comments