import { ChevronDown, ChevronUp, Github, Globe, Heart, Star, Terminal, } from "lucide-react"; import Image from "next/image"; // import Link from "next/link"; import { useEffect, useState } from "react"; import { filterCurrentSponsors, filterPastSponsors, filterRegularSponsors, filterSpecialSponsors, formatSponsorUrl, getSponsorUrl, isSpecialSponsor, sortSpecialSponsors, sortSponsors, } from "@/lib/sponsor-utils"; import type { Sponsor } from "@/lib/types"; export default function SponsorsSection() { const [sponsors, setSponsors] = useState([]); const [loadingSponsors, setLoadingSponsors] = useState(true); const [sponsorError, setSponsorError] = useState(null); const [showPastSponsors, setShowPastSponsors] = useState(false); useEffect(() => { fetch("https://sponsors.amanv.dev/sponsors.json") .then((res) => { if (!res.ok) throw new Error("Failed to fetch sponsors"); return res.json(); }) .then((data) => { const sponsorsData = Array.isArray(data) ? data : []; const sortedSponsors = sortSponsors(sponsorsData); setSponsors(sortedSponsors); setLoadingSponsors(false); }) .catch(() => { setSponsorError("Could not load sponsors"); setLoadingSponsors(false); }); }, []); const currentSponsors = filterCurrentSponsors(sponsors); const pastSponsors = filterPastSponsors(sponsors); const specialSponsors = sortSpecialSponsors( filterSpecialSponsors(currentSponsors), ); const regularSponsors = filterRegularSponsors(currentSponsors); return (
SPONSORS_DATABASE.JSON
[{loadingSponsors ? "LOADING..." : sponsors.length} RECORDS]
{loadingSponsors ? (
LOADING_SPONSORS.SH
) : sponsorError ? (
ERROR: {sponsorError}
) : sponsors.length === 0 ? (
NO_SPONSORS_FOUND.NULL
$ Be the first to support this project!
) : (
{specialSponsors.length > 0 && (
{specialSponsors.map((entry, index) => { const since = new Date(entry.createdAt).toLocaleDateString( undefined, { year: "numeric", month: "short" }, ); const sponsorUrl = getSponsorUrl(entry); return (
SPECIAL SINCE {since.toUpperCase()}
{entry.sponsor.name

{entry.sponsor.name || entry.sponsor.login}

{entry.tierName && (

{entry.tierName}

)}
{entry.sponsor.login} {(entry.sponsor.websiteUrl || entry.sponsor.linkUrl) && ( {formatSponsorUrl(sponsorUrl)} )}
); })}
)} {regularSponsors.length > 0 && (
{regularSponsors.map((entry, index) => { const since = new Date(entry.createdAt).toLocaleDateString( undefined, { year: "numeric", month: "short" }, ); return (
SINCE {since.toUpperCase()}
{entry.sponsor.name

{entry.sponsor.name || entry.sponsor.login}

{entry.tierName && (

{entry.tierName}

)}
); })}
)} {pastSponsors.length > 0 && (
{showPastSponsors && (
{pastSponsors.map((entry, index) => { const since = new Date(entry.createdAt).toLocaleDateString( undefined, { year: "numeric", month: "short" }, ); const wasSpecial = isSpecialSponsor(entry); const sponsorUrl = getSponsorUrl(entry); return (
{wasSpecial ? ( ) : ( )}
{wasSpecial && SPECIAL} {wasSpecial && } SINCE {since.toUpperCase()}
{entry.sponsor.name

{entry.sponsor.name || entry.sponsor.login}

{entry.tierName && (

{entry.tierName}

)}
{entry.sponsor.login} {(entry.sponsor.websiteUrl || entry.sponsor.linkUrl) && ( {formatSponsorUrl(sponsorUrl)} )}
); })}
)}
)}
)}
); }