@@ -158,13 +158,13 @@ const Hit = ({ hit, isFocused }: { hit: any; isFocused?: boolean }) => {
158
158
)
159
159
}
160
160
161
- function CustomRefinementList ( ) {
161
+ function LibraryRefinement ( ) {
162
162
const subpathname = useRouterState ( {
163
163
select : ( state ) => state . location . pathname . split ( '/' ) [ 1 ] ,
164
164
} )
165
165
166
166
const { items, refine } = useRefinementList ( {
167
- attribute : '_tags ' ,
167
+ attribute : 'library ' ,
168
168
limit : 50 ,
169
169
sortBy : [ 'isRefined:desc' , 'count:desc' , 'name:asc' ] ,
170
170
} )
@@ -183,27 +183,99 @@ function CustomRefinementList() {
183
183
184
184
return (
185
185
< div className = "overflow-x-auto scrollbar-hide" >
186
- < div className = "flex gap-2 p-4 min-w-max" >
187
- { items . map ( ( item ) => {
188
- const library = libraries . find ( ( l ) => l . id === item . value )
189
-
190
- return (
191
- < button
192
- key = { item . value }
193
- onClick = { ( ) => refine ( item . value ) }
194
- className = { twMerge (
195
- 'px-3 py-1 text-sm rounded-full transition-colors font-bold text-white' ,
196
- item . isRefined
197
- ? library
198
- ? library . bgStyle
199
- : 'bg-black dark:bg-white'
200
- : 'bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700'
201
- ) }
202
- >
203
- { item . label } ({ item . count . toLocaleString ( ) } )
204
- </ button >
205
- )
206
- } ) }
186
+ < div className = "flex items-center gap-2 p-2 min-w-max" >
187
+ < span className = "text-xs font-medium text-gray-500 dark:text-gray-400 whitespace-nowrap" >
188
+ Libraries:
189
+ </ span >
190
+ < div className = "flex gap-1.5" >
191
+ { items . map ( ( item ) => {
192
+ const library = libraries . find ( ( l ) => l . id === item . value )
193
+
194
+ return (
195
+ < button
196
+ key = { item . value }
197
+ onClick = { ( ) => refine ( item . value ) }
198
+ className = { twMerge (
199
+ 'px-2 py-0.5 text-xs rounded-full transition-colors font-bold text-white' ,
200
+ item . isRefined
201
+ ? library
202
+ ? library . bgStyle
203
+ : 'bg-black dark:bg-white'
204
+ : 'bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700'
205
+ ) }
206
+ >
207
+ { item . label } ({ item . count . toLocaleString ( ) } )
208
+ </ button >
209
+ )
210
+ } ) }
211
+ </ div >
212
+ </ div >
213
+ </ div >
214
+ )
215
+ }
216
+
217
+ function FrameworkRefinement ( ) {
218
+ const subpathname = useRouterState ( {
219
+ select : ( state ) => {
220
+ const path = state . location . pathname
221
+ const frameworkIndex = path . indexOf ( '/framework/' )
222
+ if ( frameworkIndex !== - 1 ) {
223
+ return path . split ( '/' ) [
224
+ path . split ( '/' ) . indexOf ( 'framework' ) + 1
225
+ ] as string
226
+ }
227
+ return null
228
+ } ,
229
+ } )
230
+
231
+ const { items, refine } = useRefinementList ( {
232
+ attribute : 'framework' ,
233
+ limit : 50 ,
234
+ sortBy : [ 'isRefined:desc' , 'count:desc' , 'name:asc' ] ,
235
+ } )
236
+
237
+ React . useEffect ( ( ) => {
238
+ if ( ! subpathname ) return
239
+
240
+ const isAlreadyRefined = items . some (
241
+ ( item ) => item . value === subpathname && item . isRefined
242
+ )
243
+
244
+ const framework = frameworkOptions . find ( ( f ) => f . value === subpathname )
245
+
246
+ if ( ! isAlreadyRefined && framework ) {
247
+ refine ( subpathname )
248
+ }
249
+ } , [ subpathname ] )
250
+
251
+ return (
252
+ < div className = "overflow-x-auto scrollbar-hide" >
253
+ < div className = "flex items-center gap-2 p-2 min-w-max" >
254
+ < span className = "text-xs font-medium text-gray-500 dark:text-gray-400 whitespace-nowrap" >
255
+ Frameworks:
256
+ </ span >
257
+ < div className = "flex gap-1.5" >
258
+ { items . map ( ( item ) => {
259
+ const framework = frameworkOptions . find (
260
+ ( f ) => f . value === item . value
261
+ )
262
+
263
+ return (
264
+ < button
265
+ key = { item . value }
266
+ onClick = { ( ) => refine ( item . value ) }
267
+ className = { twMerge (
268
+ 'px-2 py-0.5 text-xs rounded-full transition-colors font-bold text-white' ,
269
+ item . isRefined
270
+ ? framework ?. color || 'bg-black dark:bg-white'
271
+ : 'bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700'
272
+ ) }
273
+ >
274
+ { item . label } ({ item . count . toLocaleString ( ) } )
275
+ </ button >
276
+ )
277
+ } ) }
278
+ </ div >
207
279
</ div >
208
280
</ div >
209
281
)
@@ -382,7 +454,8 @@ function SearchResults({ focusedIndex }: { focusedIndex: number }) {
382
454
383
455
return (
384
456
< >
385
- < CustomRefinementList />
457
+ < LibraryRefinement />
458
+ < FrameworkRefinement />
386
459
< div
387
460
className = "max-h-[60vh] overflow-y-auto"
388
461
role = "listbox"
0 commit comments