76 lines
2.5 KiB
TypeScript
76 lines
2.5 KiB
TypeScript
'use client'
|
|
|
|
import { useState, useEffect } from 'react'
|
|
import Link from 'next/link'
|
|
|
|
interface Category {
|
|
id: string
|
|
name: string
|
|
emoji: string
|
|
count: number
|
|
featured: boolean
|
|
}
|
|
|
|
export default function CategoriesPage() {
|
|
const [categories, setCategories] = useState<Category[]>([])
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
useEffect(() => {
|
|
fetch('/api/categories')
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
setCategories(data.categories || [])
|
|
setLoading(false)
|
|
})
|
|
}, [])
|
|
|
|
const featured = categories.filter(c => c.featured)
|
|
const regular = categories.filter(c => !c.featured)
|
|
|
|
return (
|
|
<div className="min-h-screen bg-gradient-to-b from-celo-dark to-black text-white p-4">
|
|
<div className="max-w-4xl mx-auto space-y-8">
|
|
<h1 className="text-3xl font-bold">📂 Categories</h1>
|
|
|
|
{loading ? (
|
|
<div className="text-center py-12">Loading...</div>
|
|
) : (
|
|
<>
|
|
{featured.length > 0 && (
|
|
<div>
|
|
<h2 className="text-xl font-semibold mb-4">⭐ Featured</h2>
|
|
<div className="grid grid-cols-2 md:grid-cols-3 gap-4">
|
|
{featured.map(cat => (
|
|
<Link key={cat.id} href={`/discover?category=${cat.id}`}>
|
|
<div className="bg-gradient-to-br from-celo-green/20 to-celo-yellow/20 rounded-xl p-6 hover:scale-105 transition">
|
|
<div className="text-4xl mb-2">{cat.emoji}</div>
|
|
<h3 className="font-bold">{cat.name}</h3>
|
|
<p className="text-sm text-gray-400 mt-1">{cat.count} polls</p>
|
|
</div>
|
|
</Link>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
<div>
|
|
<h2 className="text-xl font-semibold mb-4">All Categories</h2>
|
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
|
{regular.map(cat => (
|
|
<Link key={cat.id} href={`/discover?category=${cat.id}`}>
|
|
<div className="bg-white/10 rounded-xl p-4 hover:bg-white/20 transition">
|
|
<div className="text-3xl mb-2">{cat.emoji}</div>
|
|
<h3 className="font-semibold text-sm">{cat.name}</h3>
|
|
<p className="text-xs text-gray-400 mt-1">{cat.count} polls</p>
|
|
</div>
|
|
</Link>
|
|
))}
|
|
</div>
|
|
</div>
|
|
</>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|