celo-poll/components/TrendingPolls.tsx
2025-12-08 16:31:30 +03:00

54 lines
1.7 KiB
TypeScript

'use client'
import { useEffect, useState } from 'react'
import { TrendingUp } from 'lucide-react'
import Link from 'next/link'
import { Poll } from '@/types'
export default function TrendingPolls() {
const [polls, setPolls] = useState<Poll[]>([])
const [loading, setLoading] = useState(true)
useEffect(() => {
fetch('/api/polls?filter=trending')
.then(r => r.json())
.then(data => {
setPolls(data.polls?.slice(0, 3) || [])
setLoading(false)
})
}, [])
if (loading) return null
return (
<div className="bg-white/5 rounded-xl p-4 border border-white/10">
<div className="flex items-center gap-2 mb-4">
<TrendingUp className="text-celo-yellow" size={20} />
<h2 className="text-lg font-bold">🔥 Trending Now</h2>
</div>
<div className="space-y-3">
{polls.map(poll => (
<Link key={poll.id} href={`/poll/${poll.id}`}>
<div className="bg-white/5 rounded-lg p-3 hover:bg-white/10 transition">
<div className="flex items-start justify-between">
<div className="flex-1">
<p className="text-sm font-medium">{poll.emoji} {poll.question}</p>
<div className="flex gap-3 mt-2 text-xs text-gray-400">
<span>👥 {poll.totalVotes}</span>
<span>💰 {poll.totalAmount.toFixed(2)} cUSD</span>
</div>
</div>
</div>
</div>
</Link>
))}
</div>
<Link href="/discover" className="block mt-4 text-center text-sm text-celo-green hover:underline">
View all polls →
</Link>
</div>
)
}