add sponsors section in home page and stack builder

This commit is contained in:
Aman Varshney
2025-05-14 20:28:07 +05:30
parent 7af3ce48ef
commit ae825b39dd
5 changed files with 230 additions and 43 deletions

View File

@@ -1,59 +1,139 @@
"use client"; "use client";
import { motion } from "motion/react"; import type { Sponsor } from "@/lib/types";
import Image from "next/image"; import Image from "next/image";
import { useEffect, useState } from "react";
export default function SponsorsSection() { export default function SponsorsSection() {
const sectionVariants = { const [sponsors, setSponsors] = useState<Sponsor[]>([]);
hidden: { opacity: 0, y: 30 }, const [loadingSponsors, setLoadingSponsors] = useState(true);
visible: { const [sponsorError, setSponsorError] = useState<string | null>(null);
opacity: 1,
y: 0, useEffect(() => {
transition: { duration: 0.6, ease: "easeOut" }, fetch(
}, "https://cdn.jsdelivr.net/gh/amanvarshney01/sponsors/sponsorkit/sponsors.json",
}; )
.then((res) => {
if (!res.ok) throw new Error("Failed to fetch sponsors");
return res.json();
})
.then((data) => {
setSponsors(Array.isArray(data) ? data : []);
setLoadingSponsors(false);
})
.catch(() => {
setSponsorError("Could not load sponsors");
setLoadingSponsors(false);
});
}, []);
return ( return (
<motion.section <section className="relative z-10 mx-auto w-full max-w-7xl px-4 py-16 sm:px-6 sm:py-24 lg:px-8">
className="relative z-10 mx-auto w-full max-w-7xl space-y-12 px-4 py-16 sm:px-6 sm:py-24 lg:space-y-16 lg:px-8" <div className="mb-10 text-center">
initial="hidden"
whileInView="visible"
viewport={{ once: true, amount: 0.2 }}
variants={sectionVariants}
>
<div className="text-center">
<h2 className="font-bold font-mono text-3xl text-foreground tracking-tight sm:text-4xl lg:text-5xl"> <h2 className="font-bold font-mono text-3xl text-foreground tracking-tight sm:text-4xl lg:text-5xl">
<span className="text-primary">Sponsors</span> <span className="text-primary">Sponsors</span>
</h2> </h2>
<p className="mx-auto mt-2 max-w-xl text-base text-muted-foreground">
Thank you to our sponsors for supporting this project!
</p>
</div> </div>
{loadingSponsors ? (
<motion.div <div className="flex animate-pulse items-center justify-center py-8 text-muted-foreground text-sm">
className="flex justify-center" Loading sponsors...
initial={{ opacity: 0, scale: 0.9 }} </div>
whileInView={{ opacity: 1, scale: 1 }} ) : sponsorError ? (
viewport={{ once: true, amount: 0.5 }} <div className="flex items-center justify-center py-8 text-destructive text-sm">
transition={{ duration: 0.5, delay: 0.2 }} {sponsorError}
> </div>
<Image ) : sponsors.length === 0 ? (
src="https://cdn.jsdelivr.net/gh/amanvarshney01/sponsors/sponsorkit/sponsors.svg" <div className="flex items-center justify-center py-8 text-muted-foreground text-sm">
alt="Sponsors" No sponsors yet.{" "}
width={1000} <a
height={500} href="https://github.com/sponsors/AmanVarshney01"
className="h-auto max-w-full md:max-w-2xl" target="_blank"
style={{ colorScheme: "light" }} rel="noopener noreferrer"
/> className="ml-2 text-primary underline"
</motion.div> >
Become a Sponsor
<div className="text-center"> </a>
</div>
) : (
<div className="fade-in-sponsors flex flex-wrap justify-center gap-8">
{sponsors.map((entry) => {
const since = new Date(entry.createdAt).toLocaleDateString();
const title = `@${entry.sponsor.login}\n${entry.sponsor.type}${
entry.isOneTime ? " (One-time)" : " (Monthly)"
}\n${entry.tierName ? `${entry.tierName}\n` : ""}Since: ${since}`;
return (
<a
key={entry.sponsor.login}
href={entry.sponsor.websiteUrl || entry.sponsor.linkUrl}
target="_blank"
rel="noopener noreferrer"
className={
"group relative flex flex-col items-center gap-2 rounded-xl border border-border bg-background/80 px-6 py-5 shadow-sm transition-all duration-200 hover:scale-105 hover:border-primary hover:shadow-lg"
}
title={title}
style={{ minWidth: 140, maxWidth: 180 }}
>
<div className="relative">
<Image
src={entry.sponsor.avatarUrl}
alt={entry.sponsor.name || entry.sponsor.login}
width={64}
height={64}
className="rounded-full border-2 border-border bg-background transition-colors group-hover:border-primary"
unoptimized
/>
</div>
<span className="break-all text-center font-mono text-foreground text-xs">
{entry.sponsor.name || entry.sponsor.login}
</span>
{entry.tierName && (
<span className="text-center text-[11px] text-muted-foreground">
{entry.tierName}
</span>
)}
<span className="text-center text-[11px] text-muted-foreground">
{entry.monthlyDollars > 0
? `$${entry.monthlyDollars} / mo`
: entry.isOneTime && entry.monthlyDollars > 0
? `$${entry.monthlyDollars} one-time`
: "Supporter"}
</span>
<span className="text-center text-[10px] text-muted-foreground">
{entry.isOneTime ? "One-time" : "Monthly"}
</span>
</a>
);
})}
</div>
)}
<div className="mt-12 text-center">
<a <a
href="https://github.com/sponsors/AmanVarshney01" href="https://github.com/sponsors/AmanVarshney01"
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
className="inline-flex items-center gap-2 rounded-md border border-primary/50 bg-primary/10 px-4 py-2 font-mono text-primary text-sm transition-colors hover:bg-primary/20" className="inline-flex items-center gap-2 rounded-lg border-2 border-primary bg-primary/10 px-8 py-3 font-mono text-lg text-primary shadow-md transition-all hover:scale-105 hover:bg-primary/20 hover:shadow-lg"
> >
<svg
className="mr-2 h-5 w-5"
fill="none"
stroke="currentColor"
strokeWidth="2"
viewBox="0 0 24 24"
>
<title>Heart in Circle</title>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M12 8c-1.657 0-3 1.343-3 3 0 2.25 3 5 3 5s3-2.75 3-5c0-1.657-1.343-3-3-3z"
/>
<circle cx="12" cy="11" r="9" />
</svg>
Become a Sponsor Become a Sponsor
</a> </a>
</div> </div>
</motion.section> </section>
); );
} }

View File

@@ -16,6 +16,7 @@ import {
isStackDefault, isStackDefault,
} from "@/lib/constant"; } from "@/lib/constant";
import { stackParsers, stackQueryStatesOptions } from "@/lib/stack-url-state"; import { stackParsers, stackQueryStatesOptions } from "@/lib/stack-url-state";
import type { Sponsor } from "@/lib/types";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { import {
Check, Check,
@@ -890,6 +891,9 @@ const StackBuilder = () => {
const [, setLastChanges] = useState< const [, setLastChanges] = useState<
Array<{ category: string; message: string }> Array<{ category: string; message: string }>
>([]); >([]);
const [sponsors, setSponsors] = useState<Sponsor[]>([]);
const [loadingSponsors, setLoadingSponsors] = useState(true);
const [sponsorError, setSponsorError] = useState<string | null>(null);
const sectionRefs = useRef<Record<string, HTMLElement | null>>({}); const sectionRefs = useRef<Record<string, HTMLElement | null>>({});
const contentRef = useRef<HTMLDivElement>(null); const contentRef = useRef<HTMLDivElement>(null);
@@ -1416,6 +1420,24 @@ const StackBuilder = () => {
setProjectNameError(validateProjectName(stack.projectName || "")); setProjectNameError(validateProjectName(stack.projectName || ""));
}, [stack.projectName]); }, [stack.projectName]);
useEffect(() => {
fetch(
"https://cdn.jsdelivr.net/gh/amanvarshney01/sponsors/sponsorkit/sponsors.json",
)
.then((res) => {
if (!res.ok) throw new Error("Failed to fetch sponsors");
return res.json();
})
.then((data) => {
setSponsors(Array.isArray(data) ? data : []);
setLoadingSponsors(false);
})
.catch(() => {
setSponsorError("Could not load sponsors");
setLoadingSponsors(false);
});
}, []);
const handleTechSelect = ( const handleTechSelect = (
category: keyof typeof TECH_OPTIONS, category: keyof typeof TECH_OPTIONS,
techId: string, techId: string,
@@ -1873,6 +1895,75 @@ const StackBuilder = () => {
); );
})} })}
<div className="h-10" /> <div className="h-10" />
{/* Sponsors Section */}
<section className="mt-12 mb-8">
<div className="mb-6 text-center">
<h2 className="font-bold font-mono text-2xl text-foreground tracking-tight">
<span className="text-primary">Sponsors</span>
</h2>
</div>
{loadingSponsors ? (
<div className="flex items-center justify-center py-8 text-muted-foreground text-sm">
Loading sponsors...
</div>
) : sponsorError ? (
<div className="flex items-center justify-center py-8 text-destructive text-sm">
{sponsorError}
</div>
) : sponsors.length === 0 ? (
<div className="flex items-center justify-center py-8 text-muted-foreground text-sm">
No sponsors yet.{" "}
<a
href="https://github.com/sponsors/AmanVarshney01"
target="_blank"
rel="noopener noreferrer"
className="ml-2 text-primary underline"
>
Become a Sponsor
</a>
</div>
) : (
<div className="flex flex-wrap justify-center gap-6">
{sponsors.map((entry) => (
<a
key={entry.sponsor.login}
href={entry.sponsor.websiteUrl || entry.sponsor.linkUrl}
target="_blank"
rel="noopener noreferrer"
className="flex flex-col items-center gap-2 rounded-lg border border-border bg-muted/30 px-4 py-3 shadow-sm transition-transform hover:scale-105 hover:border-primary"
title={entry.sponsor.name}
>
<Image
src={entry.sponsor.avatarUrl}
alt={entry.sponsor.name}
width={56}
height={56}
className="rounded-full border border-border bg-background"
unoptimized
/>
<span className="font-mono text-foreground text-xs">
{entry.sponsor.name || entry.sponsor.login}
</span>
{entry.tierName && (
<span className="text-[10px] text-muted-foreground">
{entry.tierName}
</span>
)}
</a>
))}
</div>
)}
<div className="mt-8 text-center">
<a
href="https://github.com/sponsors/AmanVarshney01"
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-2 rounded-md border border-primary/50 bg-primary/10 px-4 py-2 font-mono text-primary text-sm transition-colors hover:bg-primary/20"
>
Become a Sponsor
</a>
</div>
</section>
</main> </main>
</ScrollArea> </ScrollArea>
</div> </div>

View File

@@ -2,13 +2,12 @@
import ShinyText from "@/app/(home)/_components/shiny-text"; import ShinyText from "@/app/(home)/_components/shiny-text";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { motion } from "motion/react"; import { motion } from "motion/react";
import React from "react";
import CodeContainer from "./_components/code-container"; import CodeContainer from "./_components/code-container";
import CustomizableSection from "./_components/customizable-section"; import CustomizableSection from "./_components/customizable-section";
import Footer from "./_components/footer"; import Footer from "./_components/footer";
import Navbar from "./_components/navbar"; import Navbar from "./_components/navbar";
import NpmPackage from "./_components/npm-package"; import NpmPackage from "./_components/npm-package";
// import SponsorsSection from "./_components/SponsorsSection"; import SponsorsSection from "./_components/sponsors-section";
import Testimonials from "./_components/testimonials"; import Testimonials from "./_components/testimonials";
export default function HomePage() { export default function HomePage() {
@@ -161,7 +160,7 @@ export default function HomePage() {
<Testimonials /> <Testimonials />
</motion.div> </motion.div>
{/* <motion.div <motion.div
className="w-full" className="w-full"
initial="hidden" initial="hidden"
whileInView="visible" whileInView="visible"
@@ -169,7 +168,7 @@ export default function HomePage() {
variants={sectionVariants} variants={sectionVariants}
> >
<SponsorsSection /> <SponsorsSection />
</motion.div> */} </motion.div>
</main> </main>
<Footer /> <Footer />
</> </>

View File

@@ -30,3 +30,20 @@ export interface TechEdge {
type?: string; type?: string;
animated?: boolean; animated?: boolean;
} }
export interface Sponsor {
sponsor: {
login: string;
name: string;
avatarUrl: string;
websiteUrl?: string;
linkUrl: string;
type: string;
};
isOneTime: boolean;
monthlyDollars: number;
privacyLevel: string;
tierName: string;
createdAt: string;
provider: string;
}

View File

@@ -14,7 +14,7 @@
}, },
"apps/cli": { "apps/cli": {
"name": "create-better-t-stack", "name": "create-better-t-stack",
"version": "2.10.0", "version": "2.10.1",
"bin": { "bin": {
"create-better-t-stack": "dist/index.js", "create-better-t-stack": "dist/index.js",
}, },