File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -94,25 +94,32 @@ const getLocationFromHash = (): Location | null => {
9494 return null ;
9595} ;
9696
97+ const extractFirstString = ( { result } : { result : unknown } ) : string | null => {
98+ if ( ! Array . isArray ( result ) || ! Array . isArray ( result [ 0 ] ) ) return null ;
99+ const firstValue = result [ 0 ] [ 0 ] ;
100+ return typeof firstValue === "string" ? firstValue : null ;
101+ } ;
102+
97103const queryPageTitle = async ( { uid } : { uid : string } ) : Promise < string | null > => {
98- const pageResult = await window . roamAlphaAPI . q < [ [ string ] ] > ( `
104+ const pageResult = await window . roamAlphaAPI . q ( `
99105 [:find ?title
100106 :where [?e :block/uid "${ uid } "]
101107 [?e :node/title ?title]]
102108 ` ) ;
103109
104- return pageResult ?. [ 0 ] ?. [ 0 ] || null ;
110+ return extractFirstString ( { result : pageResult } ) ;
105111} ;
106112
107113const queryBlockString = async ( { uid } : { uid : string } ) : Promise < string | null > => {
108- const blockResult = await window . roamAlphaAPI . q < [ [ string ] ] > ( `
114+ const blockResult = await window . roamAlphaAPI . q ( `
109115 [:find ?string
110116 :where [?e :block/uid "${ uid } "]
111117 [?e :block/string ?string]]
112118 ` ) ;
113119
114- if ( ! blockResult ?. length ) return null ;
115- return blockResult [ 0 ] [ 0 ] || "(empty block)" ;
120+ const blockString = extractFirstString ( { result : blockResult } ) ;
121+ if ( blockString === null ) return null ;
122+ return blockString || "(empty block)" ;
116123} ;
117124
118125const getBreadcrumbItemByUid = async ( { uid } : { uid : string } ) : Promise < BreadcrumbItem | null > => {
You can’t perform that action at this time.
0 commit comments