From 383ea6ff33a6bbaf8e12f14e8552544cc994c699 Mon Sep 17 00:00:00 2001 From: Aman Varshney Date: Sat, 30 Aug 2025 17:56:00 +0530 Subject: [PATCH] feat(web): update sponsors logic --- .../(home)/_components/sponsors-section.tsx | 277 ++++++++---------- apps/web/src/app/(home)/page.tsx | 5 +- .../src/components/special-sponsor-banner.tsx | 49 +--- apps/web/src/lib/sponsor-utils.ts | 154 ++-------- apps/web/src/lib/sponsors.ts | 35 +++ apps/web/src/lib/types.ts | 42 ++- packages/backend/convex/_generated/api.d.ts | 2 - packages/backend/convex/schema.ts | 18 -- packages/backend/convex/sponsors.ts | 30 -- test-conservative-calculation.js | 0 test-lifetime-fix.js | 0 test-sponsor-calculations.js | 0 12 files changed, 230 insertions(+), 382 deletions(-) create mode 100644 apps/web/src/lib/sponsors.ts delete mode 100644 packages/backend/convex/sponsors.ts create mode 100644 test-conservative-calculation.js create mode 100644 test-lifetime-fix.js create mode 100644 test-sponsor-calculations.js diff --git a/apps/web/src/app/(home)/_components/sponsors-section.tsx b/apps/web/src/app/(home)/_components/sponsors-section.tsx index c487350..2ada4c2 100644 --- a/apps/web/src/app/(home)/_components/sponsors-section.tsx +++ b/apps/web/src/app/(home)/_components/sponsors-section.tsx @@ -11,60 +11,29 @@ import { 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"; - -type SponsorEntry = { - sponsor: { - login: string; - name: string; - avatarUrl: string; - websiteUrl?: string; - linkUrl: string; - customLogoUrl?: string; - type: string; - }; - isOneTime: boolean; - monthlyDollars: number; - privacyLevel: string; - tierName: string; - createdAt: string; - provider: string; -}; +import type { SponsorsData } from "@/lib/types"; export default function SponsorsSection({ - sponsors, + sponsorsData, }: { - sponsors: Array; + sponsorsData: SponsorsData; }) { const [showPastSponsors, setShowPastSponsors] = useState(false); - const sponsorsData = - sponsors.map((sponsor) => ({ - ...sponsor, - sponsor: { - ...sponsor.sponsor, - customLogoUrl: sponsor.sponsor.customLogoUrl || "", - }, - })) || []; - - const visibleSponsors = filterVisibleSponsors(sponsorsData); - const sortedSponsors = sortSponsors(visibleSponsors); - const currentSponsors = filterCurrentSponsors(sortedSponsors); - const pastSponsors = filterPastSponsors(sortSponsors(sponsorsData)); - const specialSponsors = sortSpecialSponsors( - filterSpecialSponsors(currentSponsors), - ); + const allCurrentSponsors = [ + ...sponsorsData.specialSponsors, + ...sponsorsData.sponsors, + ]; + const visibleSponsors = filterVisibleSponsors(allCurrentSponsors); + const pastSponsors = sponsorsData.pastSponsors; + const specialSponsors = sortSpecialSponsors(sponsorsData.specialSponsors); return (
@@ -117,15 +86,11 @@ export default function SponsorsSection({
{specialSponsors.map((entry, index) => { - const since = new Date(entry.createdAt).toLocaleDateString( - undefined, - { year: "numeric", month: "short" }, - ); const sponsorUrl = getSponsorUrl(entry); return (
@@ -135,7 +100,7 @@ export default function SponsorsSection({
SPECIAL - SINCE {since.toUpperCase()} + {entry.sinceWhen.toUpperCase()}
@@ -143,11 +108,8 @@ export default function SponsorsSection({
{entry.sponsor.name

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

- {entry.tierName && ( + {shouldShowLifetimeTotal(entry) ? ( + <> + {entry.tierName && ( +

+ {entry.tierName} +

+ )} +

+ Total: {entry.formattedAmount} +

+ + ) : (

{entry.tierName}

)} - {shouldShowLifetimeTotal(entry) && ( -

- Total: ${calculateLifetimeContribution(entry)} -

- )}
- {entry.sponsor.login} + {entry.githubId} - {(entry.sponsor.websiteUrl || - entry.sponsor.linkUrl) && ( + {entry.websiteUrl && ( )} - {currentSponsors.filter((s) => !isSpecialSponsor(s)).length > 0 && ( + {sponsorsData.sponsors.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()} -
+ {sponsorsData.sponsors.map((entry, index) => { + const sponsorUrl = getSponsorUrl(entry); + return ( +
+ )} @@ -330,16 +290,12 @@ export default function SponsorsSection({ {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 (
@@ -355,7 +311,7 @@ export default function SponsorsSection({
{wasSpecial && SPECIAL} {wasSpecial && } - SINCE {since.toUpperCase()} + {entry.sinceWhen.toUpperCase()}
@@ -363,11 +319,8 @@ export default function SponsorsSection({
{entry.sponsor.name

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

- {entry.tierName && ( + {shouldShowLifetimeTotal(entry) ? ( + <> + {entry.tierName && ( +

+ {entry.tierName} +

+ )} +

+ Total: {entry.formattedAmount} +

+ + ) : (

{entry.tierName}

)} - {!entry.isOneTime && ( -

- Total: $ - {calculateLifetimeContribution(entry)} -

- )}
- {entry.sponsor.login} + {entry.githubId} - {(entry.sponsor.websiteUrl || - entry.sponsor.linkUrl) && ( + {entry.websiteUrl && ( ({ @@ -31,7 +32,7 @@ export default async function HomePage() { - +