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

78 lines
2.6 KiB
TypeScript

'use client'
import { useState, useEffect } from 'react'
import { useParams } from 'next/navigation'
import Link from 'next/link'
import { ArrowLeft } from 'lucide-react'
import FollowButton from '@/components/social/FollowButton'
interface User {
fid: string
username: string
pfpUrl?: string
}
export default function FollowingPage() {
const params = useParams()
const fid = params.fid as string
const [following, setFollowing] = useState<User[]>([])
const [loading, setLoading] = useState(true)
useEffect(() => {
fetch(`/api/user/${fid}/following`)
.then(r => r.json())
.then(async data => {
const followingFids = data.following || []
const users = await Promise.all(
followingFids.map(async (followingFid: string) => {
const res = await fetch(`/api/user/${followingFid}`)
return res.json()
})
)
setFollowing(users)
setLoading(false)
})
}, [fid])
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-4">
<Link href={`/profile/${fid}`} className="text-gray-400 hover:text-white">
<ArrowLeft size={24} />
</Link>
<h1 className="text-2xl font-bold">Following</h1>
</div>
{loading ? (
<div className="text-center py-12">Loading...</div>
) : following.length === 0 ? (
<div className="text-center py-12 text-gray-400">
<p>Not following anyone yet</p>
</div>
) : (
<div className="space-y-3">
{following.map(user => (
<div key={user.fid} className="bg-white/10 rounded-xl p-4 flex items-center justify-between">
<Link href={`/profile/${user.fid}`} className="flex items-center gap-3 flex-1">
{user.pfpUrl ? (
<img src={user.pfpUrl} alt={user.username} className="w-12 h-12 rounded-full" />
) : (
<div className="w-12 h-12 rounded-full bg-celo-green/20 flex items-center justify-center">
{user.username?.[0]?.toUpperCase()}
</div>
)}
<div>
<p className="font-semibold">{user.username || `User ${user.fid}`}</p>
</div>
</Link>
<FollowButton targetFid={user.fid} />
</div>
))}
</div>
)}
</div>
</div>
)
}