73 lines
2.5 KiB
TypeScript
73 lines
2.5 KiB
TypeScript
'use client'
|
|
|
|
import { useState, useEffect } from 'react'
|
|
import Link from 'next/link'
|
|
import { TrendingUp, Flame } from 'lucide-react'
|
|
import { Poll } from '@/types'
|
|
|
|
export default function TrendingPage() {
|
|
const [polls, setPolls] = useState<Poll[]>([])
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
useEffect(() => {
|
|
const loadPolls = () => {
|
|
fetch('/api/trending')
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
setPolls(data.polls || [])
|
|
setLoading(false)
|
|
})
|
|
}
|
|
|
|
loadPolls()
|
|
const interval = setInterval(loadPolls, 30000)
|
|
return () => clearInterval(interval)
|
|
}, [])
|
|
|
|
return (
|
|
<div className="min-h-screen bg-gradient-to-b from-celo-dark to-black text-white p-4">
|
|
<div className="max-w-2xl mx-auto space-y-6">
|
|
<div className="flex items-center gap-3">
|
|
<Flame className="text-orange-500" size={32} />
|
|
<h1 className="text-3xl font-bold">Trending Now</h1>
|
|
</div>
|
|
|
|
<p className="text-gray-400">Hot polls with the most recent activity</p>
|
|
|
|
{loading ? (
|
|
<div className="text-center py-12">Loading...</div>
|
|
) : polls.length === 0 ? (
|
|
<div className="text-center py-12 text-gray-400">
|
|
<p>No trending polls right now</p>
|
|
</div>
|
|
) : (
|
|
<div className="space-y-4">
|
|
{polls.map((poll, idx) => (
|
|
<Link key={poll.id} href={`/poll/${poll.id}`}>
|
|
<div className="bg-white/10 rounded-xl p-4 hover:bg-white/15 transition border-l-4 border-orange-500">
|
|
<div className="flex items-start gap-4">
|
|
<div className="text-2xl font-bold text-orange-500">#{idx + 1}</div>
|
|
<div className="flex-1">
|
|
<h3 className="text-lg font-semibold">{poll.emoji} {poll.question}</h3>
|
|
{poll.description && (
|
|
<p className="text-sm text-gray-400 mt-1">{poll.description}</p>
|
|
)}
|
|
<div className="flex gap-4 mt-3 text-sm text-gray-400">
|
|
<span className="flex items-center gap-1">
|
|
<TrendingUp size={14} />
|
|
{poll.totalVotes} votes
|
|
</span>
|
|
<span>馃挵 {poll.totalAmount.toFixed(2)} cUSD</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Link>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|