@@ -22,6 +22,7 @@ export default function AlgoliaSearchModal({ cRef }) {
22
22
const [ useTime , setUseTime ] = useState ( 0 )
23
23
const inputRef = useRef ( null )
24
24
const [ activeIndex , setActiveIndex ] = useState ( 0 )
25
+ const [ isLoading , setIsLoading ] = useState ( false )
25
26
useHotkeys ( 'ctrl+k' , ( e ) => {
26
27
e . preventDefault ( )
27
28
setIsModalOpen ( true )
@@ -105,14 +106,15 @@ export default function AlgoliaSearchModal({ cRef }) {
105
106
if ( ! query || query === '' ) {
106
107
return
107
108
}
108
-
109
+ setIsLoading ( true )
109
110
try {
110
111
const res = await index . search ( query , { page, hitsPerPage : 10 } )
111
112
const { hits, nbHits, nbPages, processingTimeMS } = res
112
113
setUseTime ( processingTimeMS )
113
114
setTotalPage ( nbPages )
114
115
setTotalHit ( nbHits )
115
116
setSearchResults ( hits )
117
+ setIsLoading ( false )
116
118
const doms = document . getElementById ( 'search-wrapper' ) . getElementsByClassName ( 'replace' )
117
119
118
120
setTimeout ( ( ) => {
@@ -175,12 +177,12 @@ export default function AlgoliaSearchModal({ cRef }) {
175
177
< div
176
178
id = "search-wrapper"
177
179
className = { `${ isModalOpen ? 'opacity-100' : 'invisible opacity-0 pointer-events-none'
178
- } z-30 fixed h-screen w-screen left-0 top-0 mt-12 flex items-start justify-center`}
180
+ } z-30 fixed h-screen w-screen left-0 top-0 sm: mt-12 flex items-start justify-center mt-0 `}
179
181
>
180
182
{ /* 模态框 */ }
181
183
< div
182
184
className = { `${ isModalOpen ? 'opacity-100' : 'invisible opacity-0 translate-y-10'
183
- } flex flex-col justify-between w-full min-h-[10rem] max-w-xl dark:bg-hexo-black-gray dark:border-gray-800 bg-white dark:bg- p-5 rounded-lg z-50 shadow border hover:border-blue-600 duration-300 transition-all `}
185
+ } flex flex-col justify-between w-full min-h-[10rem] h-full md:h-fit max-w-xl dark:bg-hexo-black-gray dark:border-gray-800 bg-white dark:bg- p-5 rounded-lg z-50 shadow border hover:border-blue-600 duration-300 transition-all `}
184
186
>
185
187
< div className = "flex justify-between items-center" >
186
188
< div className = "text-2xl text-blue-600 dark:text-yellow-600 font-bold" > 搜索</ div >
@@ -205,21 +207,23 @@ export default function AlgoliaSearchModal({ cRef }) {
205
207
< TagGroups />
206
208
</ div >
207
209
{
208
- searchResults . length === 0 && keyword && (
210
+ searchResults . length === 0 && keyword && ! isLoading && (
209
211
< div >
210
- < p className = " text-slate-600 text-center my-4 text-base" > 无法找到相关结果
212
+ < p className = " text-slate-600 text-center my-4 text-base" > 无法找到相关结果
211
213
< span
212
214
className = 'font-semibold'
213
215
> "{ keyword } "</ span > </ p >
214
216
</ div >
215
217
)
216
218
}
217
- < ul >
219
+ < ul className = 'flex-1 overflow-auto' >
218
220
{ searchResults . map ( ( result , index ) => (
219
221
< li key = { result . objectID }
220
222
onMouseEnter = { ( ) => setActiveIndex ( index ) }
221
223
onClick = { ( ) => onJumpSearchResult ( index ) }
222
- className = { `cursor-pointer replace my-2 p-2 duration-100 ${ activeIndex === index ? 'bg-blue-600 dark:bg-yellow-600' : '' } ` } >
224
+ className = { `cursor-pointer replace my-2 p-2 duration-100
225
+ rounded-lg
226
+ ${ activeIndex === index ? 'bg-blue-600 dark:bg-yellow-600' : '' } ` } >
223
227
< a
224
228
className = { `${ activeIndex === index ? ' text-white' : ' text-black dark:text-gray-300 ' } ` }
225
229
>
@@ -229,15 +233,15 @@ export default function AlgoliaSearchModal({ cRef }) {
229
233
) ) }
230
234
</ ul >
231
235
< Pagination totalPage = { totalPage } page = { page } switchPage = { switchPage } />
232
- < div className = 'flex items-center justify-between mt-2 text-sm dark:text-gray-300' >
236
+ < div className = 'flex items-center justify-between mt-2 sm: text-sm text-xs dark:text-gray-300' >
233
237
< div >
234
238
{ totalHit > 0 && (
235
239
< p >
236
240
共搜索到 { totalHit } 条结果,用时 { useTime } 毫秒
237
241
</ p >
238
242
) }
239
243
</ div >
240
- < div className = "text-gray-600 text-right" >
244
+ < div className = "text-gray-600 dark:text-gray-300 text-right" >
241
245
< span >
242
246
< i className = "fa-brands fa-algolia" > </ i > Algolia 提供搜索服务
243
247
</ span >
@@ -294,7 +298,7 @@ function Pagination(props) {
294
298
{ Array . from ( { length : totalPage } , ( _ , i ) => {
295
299
const classNames = page === i
296
300
? 'font-bold text-white bg-blue-600 dark:bg-yellow-600 rounded'
297
- : 'hover:text-blue-600 hover:font-bold'
301
+ : 'hover:text-blue-600 hover:font-bold dark:text-gray-300 '
298
302
299
303
return (
300
304
< div
0 commit comments