"use client"; import { useQuery } from "@tanstack/react-query"; import { ExternalLink, Share2, Tag, Users } from "lucide-react"; import { http, toUserError } from "@/lib/api"; import { Panel } from "@/components/panel"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import type { Contributor } from "@/lib/types"; export type SocialLink = { name: string; url: string }; export type CommunityPayload = { socials: SocialLink[]; contributors: Contributor[]; }; function ContributorAvatar({ contributor }: { contributor: Contributor }) { if (contributor.avatar) { return ( {contributor.name} { (e.currentTarget as HTMLImageElement).style.display = "none"; (e.currentTarget.nextElementSibling as HTMLElement | null)?.removeAttribute("hidden"); }} /> ); } const initials = contributor.name .split(" ") .map((w) => w[0]) .slice(0, 2) .join("") .toUpperCase(); return ( {initials} ); } export function CommunityPanel() { const { data, isLoading, isError, error, refetch } = useQuery({ queryKey: ["community"], queryFn: () => http.get("/api/community"), }); if (isLoading) { return (
); } if (isError) { return (

{toUserError(error)}

); } const socials = data?.socials ?? []; const contributors = data?.contributors ?? []; return (
{/* Social links */} } tint="bg-primary/15 text-primary" > {socials.length === 0 ? (

هنوز شبکه‌ای ثبت نشده است.

) : ( )}
{/* Contributors */} } tint="bg-emerald-500/15 text-emerald-600 dark:text-emerald-400" > {contributors.length === 0 ? (

اطلاعات مشارکت‌کنندگان هنوز ثبت نشده است.

) : (
    {contributors.map((c, i) => (
  • {c.url ? ( {c.name} ) : ( {c.name} )} {c.role && ( {c.role} )}
    {c.bio &&

    {c.bio}

    } {c.contributions.length > 0 && (
    {c.contributions.map((cat) => ( {cat} ))}
    )}
  • ))}
)}
); }