2025-12-08 16:31:30 +03:00

178 lines
7.0 KiB
TypeScript

'use client'
import { useState, useEffect } from 'react'
import { useParams } from 'next/navigation'
import { Trophy, TrendingUp, Zap, Calendar } from 'lucide-react'
import Link from 'next/link'
import FollowButton from '@/components/social/FollowButton'
interface UserProfile {
fid: string
username: string
displayName?: string
pfpUrl?: string
bio?: string
totalVotes: number
totalWins: number
totalEarnings: number
winRate: number
streak: number
joinedAt: number
isFollowing?: boolean
followerCount: number
followingCount: number
}
interface Activity {
id: string
type: 'vote' | 'comment' | 'poll_created'
pollId: string
pollQuestion: string
timestamp: number
won?: boolean
amount?: number
}
export default function ProfilePage() {
const params = useParams()
const fid = params.fid as string
const [profile, setProfile] = useState<UserProfile | null>(null)
const [activity, setActivity] = useState<Activity[]>([])
const [tab, setTab] = useState<'activity' | 'polls' | 'achievements'>('activity')
const [loading, setLoading] = useState(true)
useEffect(() => {
Promise.all([
fetch(`/api/user/${fid}`).then(r => r.json()),
fetch(`/api/user/${fid}/activity`).then(r => r.json())
]).then(([profileData, activityData]) => {
setProfile(profileData)
setActivity(activityData.activity || [])
setLoading(false)
})
}, [fid])
if (loading) return <div className="min-h-screen bg-gradient-to-b from-celo-dark to-black text-white p-4 flex items-center justify-center">Loading...</div>
if (!profile) return <div className="min-h-screen bg-gradient-to-b from-celo-dark to-black text-white p-4 flex items-center justify-center">User not found</div>
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-6">
<div className="bg-white/10 rounded-xl p-6">
<div className="flex items-start gap-4">
{profile.pfpUrl && (
<img src={profile.pfpUrl} alt={profile.username} className="w-20 h-20 rounded-full" />
)}
<div className="flex-1">
<h1 className="text-2xl font-bold">{profile.displayName || profile.username}</h1>
<p className="text-gray-400">@{profile.username}</p>
{profile.bio && <p className="mt-2 text-gray-300">{profile.bio}</p>}
<div className="flex gap-4 mt-3 text-sm">
<Link href={`/profile/${fid}/followers`} className="hover:underline">
<span className="font-semibold">{profile.followerCount}</span> followers
</Link>
<Link href={`/profile/${fid}/following`} className="hover:underline">
<span className="font-semibold">{profile.followingCount}</span> following
</Link>
</div>
</div>
<FollowButton targetFid={fid} showCount />
</div>
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 mt-6">
<div className="bg-white/5 rounded-lg p-4">
<div className="text-2xl font-bold text-celo-green">{profile.totalVotes}</div>
<div className="text-sm text-gray-400">Total Votes</div>
</div>
<div className="bg-white/5 rounded-lg p-4">
<div className="flex items-center gap-2">
<Trophy className="text-celo-yellow" size={20} />
<span className="text-2xl font-bold">{profile.totalWins}</span>
</div>
<div className="text-sm text-gray-400">Wins</div>
</div>
<div className="bg-white/5 rounded-lg p-4">
<div className="flex items-center gap-2">
<TrendingUp className="text-celo-green" size={20} />
<span className="text-2xl font-bold">{profile.winRate}%</span>
</div>
<div className="text-sm text-gray-400">Win Rate</div>
</div>
<div className="bg-white/5 rounded-lg p-4">
<div className="flex items-center gap-2">
<Zap className="text-celo-yellow" size={20} />
<span className="text-2xl font-bold">{profile.streak}๐Ÿ”ฅ</span>
</div>
<div className="text-sm text-gray-400">Streak</div>
</div>
</div>
<div className="mt-4 text-center bg-celo-green/20 rounded-lg p-3">
<div className="text-2xl font-bold text-celo-green">{profile.totalEarnings.toFixed(2)} cUSD</div>
<div className="text-sm text-gray-400">Total Earnings</div>
</div>
</div>
<div className="flex gap-2 border-b border-white/10">
<button
onClick={() => setTab('activity')}
className={`px-4 py-2 ${tab === 'activity' ? 'border-b-2 border-celo-green text-celo-green' : 'text-gray-400'}`}
>
Activity
</button>
<button
onClick={() => setTab('polls')}
className={`px-4 py-2 ${tab === 'polls' ? 'border-b-2 border-celo-green text-celo-green' : 'text-gray-400'}`}
>
Polls Created
</button>
<button
onClick={() => setTab('achievements')}
className={`px-4 py-2 ${tab === 'achievements' ? 'border-b-2 border-celo-green text-celo-green' : 'text-gray-400'}`}
>
Achievements
</button>
</div>
{tab === 'activity' && (
<div className="space-y-3">
{activity.map(item => (
<Link key={item.id} href={`/poll/${item.pollId}`}>
<div className="bg-white/10 rounded-xl p-4 hover:bg-white/20 transition">
<div className="flex items-start justify-between">
<div className="flex-1">
<div className="flex items-center gap-2 text-sm text-gray-400">
<span>{item.type === 'vote' ? '๐Ÿ—ณ๏ธ Voted' : item.type === 'comment' ? '๐Ÿ’ฌ Commented' : '๐Ÿ“Š Created poll'}</span>
<span>โ€ข</span>
<span>{new Date(item.timestamp).toLocaleDateString()}</span>
</div>
<p className="mt-1 font-medium">{item.pollQuestion}</p>
{item.won !== undefined && (
<div className={`mt-2 text-sm ${item.won ? 'text-celo-green' : 'text-red-400'}`}>
{item.won ? `โœ… Won ${item.amount?.toFixed(2)} cUSD` : 'โŒ Lost'}
</div>
)}
</div>
</div>
</div>
</Link>
))}
</div>
)}
{tab === 'polls' && (
<div className="text-center py-12 text-gray-400">
No polls created yet
</div>
)}
{tab === 'achievements' && (
<div className="text-center py-12 text-gray-400">
Achievements coming soon
</div>
)}
</div>
</div>
)
}