Skip to content

Commit 6616549

Browse files
authored
Update page.tsx
1 parent c3a2106 commit 6616549

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

frontend/src/app/category-view/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const formattedBadge = (type: string) => {
2929
const CategoryView = () => {
3030
const [categories, setCategories] = useState<Category[]>([]);
3131
const [selectedCategoryIndex, setSelectedCategoryIndex] = useState<number | null>(null);
32+
const [currentScripts, setCurrentScripts] = useState<any[]>([]);
3233
const [logoIndices, setLogoIndices] = useState<{ [key: string]: number }>({});
3334
const router = useRouter();
3435

@@ -59,10 +60,12 @@ const CategoryView = () => {
5960

6061
const handleCategoryClick = (index: number) => {
6162
setSelectedCategoryIndex(index);
63+
setCurrentScripts(categories[index]?.scripts || []); // Update scripts for the selected category
6264
};
6365

6466
const handleBackClick = () => {
6567
setSelectedCategoryIndex(null);
68+
setCurrentScripts([]); // Clear scripts when going back
6669
};
6770

6871
const handleScriptClick = (scriptSlug: string) => {
@@ -76,6 +79,7 @@ const CategoryView = () => {
7679
? (selectedCategoryIndex - 1 + categories.length) % categories.length
7780
: (selectedCategoryIndex + 1) % categories.length;
7881
setSelectedCategoryIndex(newIndex);
82+
setCurrentScripts(categories[newIndex]?.scripts || []); // Update scripts for the new category
7983
}
8084
};
8185

@@ -151,7 +155,7 @@ const CategoryView = () => {
151155

152156
{/* Scripts Grid */}
153157
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-6">
154-
{categories[selectedCategoryIndex].scripts
158+
{currentScripts
155159
.sort((a, b) => a.name.localeCompare(b.name))
156160
.map((script) => (
157161
<Card

0 commit comments

Comments
 (0)