File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { useMemo } from 'react'
22
33import { KBarResults , useMatches } from 'kbar'
4+ import type { ActionImpl } from 'kbar'
45
56import ResultItem from './ResultItem'
67
@@ -10,20 +11,29 @@ const Results = () => {
1011 const { results } = useMatches ( )
1112
1213 const flattened = useMemo ( ( ) => {
13- return results . reduce ( ( acc : any [ ] , curr : any ) => {
14- if ( typeof curr === 'string' ) {
15- acc . push ( curr )
16- } else {
17- acc . push ( curr . name )
18- acc . push ( ...curr . actions )
19- }
20- return acc
21- } , [ ] )
14+ const flattenActions = ( actions : ( string | ActionImpl ) [ ] ) => {
15+ return actions . reduce ( ( acc : any [ ] , curr : string | ActionImpl ) => {
16+ if ( typeof curr === 'string' ) {
17+ acc . push ( curr )
18+ } else {
19+ acc . push ( curr )
20+
21+ if ( curr . children && curr . children . length > 0 ) {
22+ acc . push ( ...flattenActions ( curr . children ) )
23+ }
24+ }
25+ return acc
26+ } , [ ] )
27+ }
28+
29+ return flattenActions ( results )
2230 } , [ results ] )
2331
2432 return (
2533 < KBarResults
26- items = { flattened . filter ( ( i : string ) => i !== NO_GROUP ) }
34+ items = { flattened . filter (
35+ ( i : any ) => typeof i !== 'string' || i !== NO_GROUP ,
36+ ) }
2737 onRender = { ( { item, active } ) =>
2838 typeof item === 'string' ? (
2939 < div className = "px-4 py-2 text-2xs uppercase text-gray-400 dark:text-gray-600 bg-white dark:bg-black-600" >
You can’t perform that action at this time.
0 commit comments