import Layout from "@/components/Layout"; import { useAuth } from "@/contexts/AuthContext"; import { useEffect, useMemo, useState } from "react"; import { useNavigate } from "react-router-dom"; import LoadingScreen from "@/components/LoadingScreen"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; import { aethexSocialService } from "@/lib/aethex-social-service"; import { UserPlus, UserCheck } from "lucide-react"; export default function Network() { const { user, profile, loading } = useAuth(); const navigate = useNavigate(); const [isLoading, setIsLoading] = useState(true); const [recommended, setRecommended] = useState([]); const [following, setFollowing] = useState([]); useEffect(() => { if (!loading && !user) { navigate("/login", { replace: true }); return; } if (!user) return; const load = async () => { setIsLoading(true); try { const recs = await aethexSocialService.listRecommended(user.id, 12); setRecommended(recs); const flw = await aethexSocialService.getFollowing(user.id); setFollowing(flw); } finally { setIsLoading(false); } }; load(); }, [user, loading, navigate]); const isFollowing = (id: string) => following.includes(id); const toggleFollow = async (targetId: string) => { if (!user) return; if (isFollowing(targetId)) { await aethexSocialService.unfollowUser(user.id, targetId); setFollowing((s) => s.filter((x) => x !== targetId)); } else { await aethexSocialService.followUser(user.id, targetId); setFollowing((s) => Array.from(new Set([...s, targetId]))); } }; if (loading || isLoading) { return ( ); } if (!user) return null; return (
{/* Public Profile */}
{profile?.full_name?.[0] || user.email?.[0]?.toUpperCase()}

{profile?.full_name || user.email?.split("@")[0]}

{profile?.role || "Member"}

Level {profile?.level || 1} {(profile as any)?.experience_level || "beginner"}
{profile?.bio && (

{profile.bio}

)}
Recommendations People who align with your interests {recommended.slice(0, 3).map((r) => (
{(r.full_name || r.username || "U")[0]}
{r.full_name || r.username}
{r.bio?.slice(0, 40) || "Member"}
))} {recommended.length === 0 && (
No recommendations yet.
)}
{/* Discover People */}
Discover People Connect with creators, clients, and members {recommended.map((r) => (
{(r.full_name || r.username || "U")[0]}
{r.full_name || r.username}
{r.bio?.slice(0, 80) || "Member"}
))} {recommended.length === 0 && (
No people found yet.
)}
); }