import { useState, useMemo } from 'react'; import Header from '@/components/Header'; import Footer from '@/components/Footer'; import { FollowingList } from '@/components/ui/following-card'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from '@/components/ui/alert-dialog'; import { Post } from '@opchan/core'; import { Trash2, Users, FileText, } from 'lucide-react'; import { useAuth, useContent } from '@/hooks'; import PostCard from '@/components/PostCard'; const FollowingPage = () => { const { currentUser } = useAuth(); const { following, posts, unfollowUser, clearAllFollowing } = useContent(); const [activeTab, setActiveTab] = useState<'following' | 'feed'>('following'); // Get posts from followed users const followedAddresses = useMemo( () => following.map(f => f.followedAddress), [following] ); const followingPosts = useMemo( () => posts.filter(post => followedAddresses.includes(post.authorAddress)), [posts, followedAddresses] ); // Sort posts by timestamp (newest first) const sortedFollowingPosts = useMemo( () => [...followingPosts].sort((a, b) => b.timestamp - a.timestamp), [followingPosts] ); // Redirect to login if not authenticated if (!currentUser) { return (

Authentication Required

Please connect your wallet to view your following list.

); } const handleUnfollow = async (followedAddress: string) => { await unfollowUser(followedAddress); }; const handleClearAll = async () => { await clearAllFollowing(); }; return (
{/* Header Section */}

Following

{following.length > 0 && ( Unfollow All Users Are you sure you want to unfollow all users? This action cannot be undone. Cancel Unfollow All )}

Manage the users you follow and see their posts in your personalized feed.

{/* Stats */} {following.length > 0 && (
{following.length} Following {followingPosts.length} Posts
)} {/* Tabs */} setActiveTab(value as 'following' | 'feed') } className="w-full" > Following ({following.length}) Feed ({followingPosts.length}) {followingPosts.length === 0 ? (

No posts from followed users

{following.length === 0 ? 'Follow some users to see their posts here.' : 'The users you follow haven\'t posted anything yet.'}

) : (
{sortedFollowingPosts.map(post => ( ))}
)}
); }; export default FollowingPage;