Skip to content

Commit 515ab4b

Browse files
committed
fix: category filter
1 parent 2e5a2e0 commit 515ab4b

File tree

3 files changed

+80
-41
lines changed

3 files changed

+80
-41
lines changed

apps/www/app/page.tsx

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getHooks } from "@/lib/get-hooks";
55
import { ScrollArea } from "@workspace/ui/components/scroll-area";
66
import { Anchor } from "lucide-react";
77
import { Separator } from "@workspace/ui/components/separator";
8+
import { CaterogyButton } from "@/components/category-button";
89

910
export const metadata: Metadata = {
1011
title: "useHooks - React Hooks Library",
@@ -118,56 +119,54 @@ export default async function HomePage() {
118119
<div className="flex flex-wrap justify-center gap-4">
119120
{Array.from(new Set(hooks.map((hook) => hook.category))).map(
120121
(category, index) => (
121-
<div
122+
<CaterogyButton
122123
key={category}
123-
className="animate-in fade-in-0 slide-in-from-bottom-4"
124-
style={{ animationDelay: `${1500 + index * 100}ms` }}
125-
>
126-
<div className="rounded-full bg-primary/10 px-4 py-2 text-sm font-medium transition-colors hover:bg-primary/20">
127-
{category}
128-
<span className="ml-2 text-xs text-muted-foreground">
129-
(
130-
{
131-
hooks.filter((hook) => hook.category === category)
132-
.length
133-
}
134-
)
135-
</span>
136-
</div>
137-
</div>
124+
category={category}
125+
index={index}
126+
hooks={hooks}
127+
/>
138128
)
139129
)}
140130
</div>
141131
</div>
142132

143-
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
144-
{hooks.map((hook, index) => (
145-
<div
146-
className={`container mx-auto py-12 transition-all duration-200 hover:scale-105 animate-in fade-in-0 slide-in-from-bottom-4`}
147-
style={{
148-
animationDelay: `${2100 + index * 100}ms`,
149-
}}
150-
key={hook.name}
151-
>
152-
<Link
153-
href={`/docs/${hook.name}`}
154-
className="block transition-colors duration-200 hover:text-primary"
155-
>
156-
<h1 className="text-4xl font-bold mb-2 transition-colors duration-200">
157-
{hook.name}
158-
</h1>
159-
</Link>
160-
<span className="inline-block bg-gray-200 dark:bg-gray-700 text-sm px-2 py-1 rounded mb-8 transition-all duration-200 hover:bg-primary/20">
161-
{hook.category}
162-
</span>
133+
{Array.from(new Set(hooks.map((hook) => hook.category))).map(
134+
(category) => (
135+
<div key={category} id={category}>
136+
<h3 className="text-2xl font-bold mt-16 mb-8">{category}</h3>
137+
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
138+
{hooks
139+
.filter((hook) => hook.category === category)
140+
.map((hook, index) => (
141+
<div
142+
className={`container mx-auto py-12 transition-all duration-200 hover:scale-105 animate-in fade-in-0 slide-in-from-bottom-4`}
143+
style={{
144+
animationDelay: `${2100 + index * 100}ms`,
145+
}}
146+
key={hook.name}
147+
>
148+
<Link
149+
href={`/docs/${hook.name}`}
150+
className="block transition-colors duration-200 hover:text-primary"
151+
>
152+
<h1 className="text-4xl font-bold mb-2 transition-colors duration-200">
153+
{hook.title}
154+
</h1>
155+
</Link>
156+
<span className="inline-block bg-gray-200 dark:bg-gray-700 text-sm px-2 py-1 rounded mb-8 transition-all duration-200 hover:bg-primary/20">
157+
{hook.category}
158+
</span>
163159

164-
<div className="mb-8">
165-
<h2 className="text-2xl font-bold mb-4">Description</h2>
166-
<p className="text-lg">{hook.description}</p>
160+
<div className="mb-8">
161+
<h2 className="text-2xl font-bold mb-4">Description</h2>
162+
<p className="text-lg">{hook.description}</p>
163+
</div>
164+
</div>
165+
))}
167166
</div>
168167
</div>
169-
))}
170-
</div>
168+
)
169+
)}
171170

172171
<Separator
173172
className="my-10 animate-in fade-in-0 duration-1000"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"use client";
2+
3+
import { Button } from "@workspace/ui/components/button";
4+
5+
export function CaterogyButton({
6+
category,
7+
hooks,
8+
index,
9+
}: {
10+
category: string;
11+
hooks: any;
12+
index: number;
13+
}) {
14+
return (
15+
<Button
16+
key={category}
17+
onClick={() => {
18+
const element = document.getElementById(category);
19+
element?.scrollIntoView({ behavior: "smooth" });
20+
}}
21+
className="animate-in fade-in-0 slide-in-from-bottom-4 cursor-pointer"
22+
variant="outline"
23+
style={{ animationDelay: `${1500 + index * 100}ms` }}
24+
>
25+
<div className="px-4 py-2 text-sm font-medium">
26+
{category}
27+
<span className="ml-2 text-xs text-muted-foreground">
28+
(
29+
{
30+
hooks.filter(
31+
(hook: { category: string }) => hook.category === category
32+
).length
33+
}
34+
)
35+
</span>
36+
</div>
37+
</Button>
38+
);
39+
}

apps/www/lib/get-hooks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useFetch } from "@/hooks/use-fetch";
22

33
export type HookMeta = {
44
name: string;
5+
title: string;
56
description: string;
67
category: string;
78
examples: [{ name: string; description: string }];

0 commit comments

Comments
 (0)