"use client"; import type { api } from "@better-t-stack/backend/convex/_generated/api"; import { type Preloaded, usePreloadedQuery } from "convex/react"; import { ChevronDown, ChevronUp, Github, Globe, Heart, Star, Terminal, } from "lucide-react"; import Image from "next/image"; import { useState } from "react"; import { calculateLifetimeContribution, filterCurrentSponsors, filterPastSponsors, filterSpecialSponsors, filterVisibleSponsors, formatSponsorUrl, getSponsorUrl, isSpecialSponsor, shouldShowLifetimeTotal, sortSpecialSponsors, sortSponsors, } from "@/lib/sponsor-utils"; export default function SponsorsSection({ preloadedSponsors, }: { preloadedSponsors: Preloaded; }) { const sponsorsData = usePreloadedQuery(preloadedSponsors); const [showPastSponsors, setShowPastSponsors] = useState(false); const sponsors = sponsorsData.map((sponsor) => ({ ...sponsor, sponsor: { ...sponsor.sponsor, customLogoUrl: sponsor.sponsor.customLogoUrl || "", }, })) || []; const visibleSponsors = filterVisibleSponsors(sponsors); const sortedSponsors = sortSponsors(visibleSponsors); const currentSponsors = filterCurrentSponsors(sortedSponsors); const pastSponsors = filterPastSponsors(sortSponsors(sponsors)); const specialSponsors = sortSpecialSponsors( filterSpecialSponsors(currentSponsors), ); return (
SPONSORS_DATABASE.JSON
[{visibleSponsors.length} RECORDS]
{visibleSponsors.length === 0 ? (
NO_SPONSORS_FOUND.NULL
$ Be the first to support this project!
BECOME_SPONSOR.SH
) : (
{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}

)} {shouldShowLifetimeTotal(entry) && (

Total: ${calculateLifetimeContribution(entry)}

)}
{entry.sponsor.login} {(entry.sponsor.websiteUrl || entry.sponsor.linkUrl) && ( {formatSponsorUrl(sponsorUrl)} )}
); })}
)} {currentSponsors.filter((s) => !isSpecialSponsor(s)).length > 0 && (
{currentSponsors .filter((s) => !isSpecialSponsor(s)) .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}

)} {shouldShowLifetimeTotal(entry) && (

Total: $ {calculateLifetimeContribution(entry)}

)}
); })}
)} {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.isOneTime && (

Total: $ {calculateLifetimeContribution(entry)}

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