Skip to content

Commit 2282e7a

Browse files
committed
Merge remote-tracking branch 'origin/main' into search-modal-qol
2 parents 7049686 + 3777808 commit 2282e7a

2 files changed

Lines changed: 116 additions & 33 deletions

File tree

app/components/SearchModal.tsx

Lines changed: 97 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const Hit = ({ hit, isFocused }: { hit: any; isFocused?: boolean }) => {
150150
alt={framework.label}
151151
className="w-4"
152152
/>
153-
{framework.label}
153+
{capitalize(framework.label)}
154154
</div>
155155
</div>
156156
)
@@ -160,13 +160,13 @@ const Hit = ({ hit, isFocused }: { hit: any; isFocused?: boolean }) => {
160160
)
161161
}
162162

163-
function CustomRefinementList() {
163+
function LibraryRefinement() {
164164
const subpathname = useRouterState({
165165
select: (state) => state.location.pathname.split('/')[1],
166166
})
167167

168168
const { items, refine } = useRefinementList({
169-
attribute: '_tags',
169+
attribute: 'library',
170170
limit: 50,
171171
sortBy: ['isRefined:desc', 'count:desc', 'name:asc'],
172172
})
@@ -185,27 +185,99 @@ function CustomRefinementList() {
185185

186186
return (
187187
<div className="overflow-x-auto scrollbar-hide">
188-
<div className="flex gap-2 p-4 min-w-max">
189-
{items.map((item) => {
190-
const library = libraries.find((l) => l.id === item.value)
188+
<div className="flex items-center gap-2 p-2 min-w-max">
189+
<span className="text-xs font-medium text-gray-500 dark:text-gray-400 whitespace-nowrap">
190+
Libraries:
191+
</span>
192+
<div className="flex gap-1.5">
193+
{items.map((item) => {
194+
const library = libraries.find((l) => l.id === item.value)
195+
196+
return (
197+
<button
198+
key={item.value}
199+
onClick={() => refine(item.value)}
200+
className={twMerge(
201+
'px-2 py-0.5 text-xs rounded-full transition-colors font-bold text-white',
202+
item.isRefined
203+
? library
204+
? library.bgStyle
205+
: 'bg-black dark:bg-white'
206+
: 'bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700'
207+
)}
208+
>
209+
{item.label} ({item.count.toLocaleString()})
210+
</button>
211+
)
212+
})}
213+
</div>
214+
</div>
215+
</div>
216+
)
217+
}
191218

192-
return (
193-
<button
194-
key={item.value}
195-
onClick={() => refine(item.value)}
196-
className={twMerge(
197-
'px-3 py-1 text-sm rounded-full transition-colors font-bold text-white',
198-
item.isRefined
199-
? library
200-
? library.bgStyle
201-
: 'bg-black dark:bg-white'
202-
: 'bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700'
203-
)}
204-
>
205-
{capitalize(item.label)} ({item.count.toLocaleString()})
206-
</button>
207-
)
208-
})}
219+
function FrameworkRefinement() {
220+
const subpathname = useRouterState({
221+
select: (state) => {
222+
const path = state.location.pathname
223+
const frameworkIndex = path.indexOf('/framework/')
224+
if (frameworkIndex !== -1) {
225+
return path.split('/')[
226+
path.split('/').indexOf('framework') + 1
227+
] as string
228+
}
229+
return null
230+
},
231+
})
232+
233+
const { items, refine } = useRefinementList({
234+
attribute: 'framework',
235+
limit: 50,
236+
sortBy: ['isRefined:desc', 'count:desc', 'name:asc'],
237+
})
238+
239+
React.useEffect(() => {
240+
if (!subpathname) return
241+
242+
const isAlreadyRefined = items.some(
243+
(item) => item.value === subpathname && item.isRefined
244+
)
245+
246+
const framework = frameworkOptions.find((f) => f.value === subpathname)
247+
248+
if (!isAlreadyRefined && framework) {
249+
refine(subpathname)
250+
}
251+
}, [items, refine, subpathname])
252+
253+
return (
254+
<div className="overflow-x-auto scrollbar-hide">
255+
<div className="flex items-center gap-2 p-2 min-w-max">
256+
<span className="text-xs font-medium text-gray-500 dark:text-gray-400 whitespace-nowrap">
257+
Frameworks:
258+
</span>
259+
<div className="flex gap-1.5">
260+
{items.map((item) => {
261+
const framework = frameworkOptions.find(
262+
(f) => f.value === item.value
263+
)
264+
265+
return (
266+
<button
267+
key={item.value}
268+
onClick={() => refine(item.value)}
269+
className={twMerge(
270+
'px-2 py-0.5 text-xs rounded-full transition-colors font-bold text-white',
271+
item.isRefined
272+
? framework?.color || 'bg-black dark:bg-white'
273+
: 'bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700'
274+
)}
275+
>
276+
{capitalize(item.label)} ({item.count.toLocaleString()})
277+
</button>
278+
)
279+
})}
280+
</div>
209281
</div>
210282
</div>
211283
)
@@ -384,7 +456,8 @@ function SearchResults({ focusedIndex }: { focusedIndex: number }) {
384456

385457
return (
386458
<>
387-
<CustomRefinementList />
459+
<LibraryRefinement />
460+
<FrameworkRefinement />
388461
<div
389462
className="max-h-[80vh] lg:max-h-[60vh] overflow-y-auto"
390463
role="listbox"

app/libraries/index.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,25 @@ import { pacerProject } from './pacer'
2020
// import { optimisticProject } from './optimistic'
2121

2222
export const frameworkOptions = [
23-
{ label: 'React', value: 'react', logo: reactLogo },
24-
{ label: 'Preact', value: 'preact', logo: preactLogo },
25-
{ label: 'Vue', value: 'vue', logo: vueLogo },
26-
{ label: 'Angular', value: 'angular', logo: angularLogo },
27-
{ label: 'Solid', value: 'solid', logo: solidLogo },
28-
{ label: 'Lit', value: 'lit', logo: litLogo },
29-
{ label: 'Svelte', value: 'svelte', logo: svelteLogo },
30-
{ label: 'Qwik', value: 'qwik', logo: qwikLogo },
31-
{ label: 'Vanilla', value: 'vanilla', logo: jsLogo },
23+
{ label: 'React', value: 'react', logo: reactLogo, color: 'bg-blue-500' },
24+
{ label: 'Preact', value: 'preact', logo: preactLogo, color: 'bg-blue-400' },
25+
{ label: 'Vue', value: 'vue', logo: vueLogo, color: 'bg-green-500' },
26+
{
27+
label: 'Angular',
28+
value: 'angular',
29+
logo: angularLogo,
30+
color: 'bg-red-500',
31+
},
32+
{ label: 'Solid', value: 'solid', logo: solidLogo, color: 'bg-blue-600' },
33+
{ label: 'Lit', value: 'lit', logo: litLogo, color: 'bg-orange-500' },
34+
{
35+
label: 'Svelte',
36+
value: 'svelte',
37+
logo: svelteLogo,
38+
color: 'bg-orange-600',
39+
},
40+
{ label: 'Qwik', value: 'qwik', logo: qwikLogo, color: 'bg-purple-500' },
41+
{ label: 'Vanilla', value: 'vanilla', logo: jsLogo, color: 'bg-yellow-500' },
3242
] as const
3343

3444
export type Framework = (typeof frameworkOptions)[number]['value']

0 commit comments

Comments
 (0)