@@ -50,6 +50,10 @@ const FileSearch = ({
50
50
} ) => {
51
51
const { query, refine : setQuery } = useSearchBox ( ) ;
52
52
const { hits } = useHits ( ) as { hits : AlgoliaEditorFileHit [ ] } ;
53
+ console . log ( hits . map ( hit => hit . __position ) ) ;
54
+ if ( ! hits . find ( hit => hit . id === 'none' ) ) {
55
+ hits . push ( { id : 'none' } as AlgoliaEditorFileHit ) ; // blank hit
56
+ }
53
57
return (
54
58
< div >
55
59
< div className = "flex items-center p-2" >
@@ -70,26 +74,40 @@ const FileSearch = ({
70
74
< div >
71
75
< SearchResultsContainer >
72
76
< div className = "max-h-[20rem] overflow-y-auto border-t divide-y divide-gray-200 border-gray-200 dark:divide-gray-700 dark:border-gray-700" >
73
- { hits . map ( hit => (
74
- < button
75
- className = "block hover:bg-blue-100 dark:hover:bg-gray-700 py-3 px-5 transition focus:outline-none w-full text-left"
76
- key = { hit . id }
77
- onClick = { ( ) => onSelect ( hit ) }
78
- >
79
- < h3 className = "text-gray-600 dark:text-gray-200 font-medium" >
80
- < Highlight hit = { hit } attribute = "title" /> (
81
- { hit . kind === 'module' ? 'Module' : 'Solution' } )
82
- </ h3 >
83
- < SearchResultDescription className = "text-gray-700 dark:text-gray-400 text-sm" >
84
- < Highlight hit = { hit } attribute = "id" /> -{ ' ' }
85
- { hit . path == null ? (
86
- 'Create New Internal Solution'
87
- ) : (
88
- < Highlight hit = { hit } attribute = "path" />
89
- ) }
90
- </ SearchResultDescription >
91
- </ button >
92
- ) ) }
77
+ { hits . length
78
+ ? hits . map ( hit => (
79
+ < button
80
+ className = "block hover:bg-blue-100 dark:hover:bg-gray-700 py-3 px-5 transition focus:outline-none w-full text-left"
81
+ key = { hit . id }
82
+ onClick = { ( ) => {
83
+ let trueHit = hit ;
84
+ if ( hit . id === 'none' ) {
85
+ trueHit = {
86
+ path : prompt ( 'path?' ) ,
87
+ } as AlgoliaEditorFileHit ;
88
+ }
89
+ if ( trueHit . path ) onSelect ( trueHit ) ;
90
+ } }
91
+ >
92
+ < h3 className = "text-gray-600 dark:text-gray-200 font-medium" >
93
+ { hit . title ? (
94
+ < Highlight hit = { hit } attribute = "title" />
95
+ ) : (
96
+ 'Add New Problem'
97
+ ) } { ' ' }
98
+ ({ hit . kind === 'module' ? 'Module' : 'Solution' } )
99
+ </ h3 >
100
+ < SearchResultDescription className = "text-gray-700 dark:text-gray-400 text-sm" >
101
+ < Highlight hit = { hit } attribute = "id" /> -{ ' ' }
102
+ { hit . path == null ? (
103
+ 'Create New Internal Solution'
104
+ ) : (
105
+ < Highlight hit = { hit } attribute = "path" />
106
+ ) }
107
+ </ SearchResultDescription >
108
+ </ button >
109
+ ) )
110
+ : 'test' }
93
111
</ div >
94
112
< div className = "px-5 py-3 border-t border-gray-200 dark:border-gray-700" >
95
113
< PoweredBy theme = "dark" />
0 commit comments