From 372d34cc624fd925190eabdbd062e24d85a1623f Mon Sep 17 00:00:00 2001 From: anonymousratwastaken Date: Sat, 24 Oct 2026 10:49:44 +0100 Subject: [PATCH] Replace donate page wave background with glow - Add DonateGlow WebGL gradient that shifts colour per donation intent and rank - Drive donate steps from URL query params so browser back/forward work - Clear pending checkout session when an answer changes - Remove the unused wave-pattern canvas background --- src/app/donate/page.tsx | 112 +++++++--- src/components/donate-glow.tsx | 349 ++++++++++++++++++++++++++++++++ src/components/wave-pattern.tsx | 112 ---------- 3 files changed, 436 insertions(+), 137 deletions(-) create mode 100644 src/components/donate-glow.tsx delete mode 100644 src/components/wave-pattern.tsx diff --git a/src/app/donate/page.tsx b/src/app/donate/page.tsx index ab1b98c..de15eed 100644 --- a/src/app/donate/page.tsx +++ b/src/app/donate/page.tsx @@ -1,6 +1,7 @@ "use client"; -import { useEffect, useMemo, useState } from "react"; +import { Suspense, useEffect, useMemo, useState } from "react"; import Link from "next/link"; +import { useSearchParams } from "next/navigation"; import { loadStripe, type Appearance } from "@stripe/stripe-js"; import { CheckoutElementsProvider, @@ -15,11 +16,12 @@ import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { TIERS, tierForAmount, upgradePrice } from "@/lib/donations"; import { TopBar } from "@/components/top-bar"; -import WaveBackground from "@/components/wave-pattern"; +import { DonateGlow, type GlowTheme } from "@/components/donate-glow"; const stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY ?? ""); const DRAFT_KEY = "frg-donate-draft-v1"; +const PAYMENT_STEP = "payment"; type Answers = { intent: string; @@ -351,20 +353,56 @@ function StepShell({ title, description, error, children }: { ); } +const TIER_GLOW: Record = { iron: "iron", gold: "gold", diamond: "diamond", patron: "purple" }; + +// Green until a choice is made, then a colour per intent, then per rank. +function glowFor(ans: Answers, step: string): GlowTheme { + const rankColour = step !== "intent" ? TIER_GLOW[ans.intent === "upgrade" ? ans.upgradeTo : ans.rank] : undefined; + switch (ans.intent) { + case "rank": return rankColour ?? "lime"; + case "upgrade": return rankColour ?? "teal"; + case "patron": return "purple"; + case "custom": return "blue"; + default: return "green"; + } +} + export default function DonatePage() { + return ( + }> + + + ); +} + +// The URL is the source of truth for where the visitor is: /donate is the +// landing screen and /donate?step= is a step, so browser back/forward +// walk the flow. +function DonateFlow() { + const stepParam = useSearchParams().get("step"); const [ans, setAns] = useState(EMPTY_ANSWERS); const [restored, setRestored] = useState(false); const [pending, setPending] = useState(null); - const [started, setStarted] = useState(false); - const [stepIdx, setStepIdx] = useState(0); const [error, setError] = useState(null); const [submitting, setSubmitting] = useState(false); const set = (patch: Partial) => { setError(null); + // A checkout session no longer matches once an answer changes. + setPending(null); setAns((a) => ({ ...a, ...patch })); }; + // Each navigation is its own history entry. The depth is kept in + // history.state so the Back button can pop an entry we pushed, instead of + // piling new ones on top, and falls back to replacing on a deep link. + function go(name: string | null, mode: "push" | "replace" = "push") { + const url = name ? `/donate?step=${name}` : "/donate"; + const depth: number = window.history.state?.donateDepth ?? 0; + if (mode === "push") window.history.pushState({ donateDepth: depth + 1 }, "", url); + else window.history.replaceState({ donateDepth: depth }, "", url); + } + useEffect(() => { try { const raw = localStorage.getItem(DRAFT_KEY); @@ -409,8 +447,9 @@ export default function DonatePage() { return s; }, [ans.intent, ans.gift]); - const current = Math.min(stepIdx, steps.length - 1); - const step = steps[current]; + const started = stepParam !== null; + const step = stepParam !== null && steps.includes(stepParam) ? stepParam : steps[0]; + const current = steps.indexOf(step); const last = step === "confirm"; function validateStep(name: string): string | null { @@ -429,30 +468,47 @@ export default function DonatePage() { } } + // Where the URL should really be: a step is only reachable once every step + // before it is answered, and payment needs a live checkout session. This + // covers reloads, deep links and stale forward entries. + function resolveStep(param: string): string { + if (param === PAYMENT_STEP && pending) return PAYMENT_STEP; + const target = steps.includes(param) ? param : "confirm"; + for (const s of steps) { + if (s === target || validateStep(s)) return s; + } + return steps[0]; + } + + const resolved = restored && stepParam !== null ? resolveStep(stepParam) : null; + // True while the draft is loading or a redirect is about to happen. + const waiting = stepParam !== null && resolved !== stepParam; + + useEffect(() => { + if (resolved && resolved !== stepParam) go(resolved, "replace"); + }, [resolved, stepParam]); + + useEffect(() => { + setError(null); + }, [stepParam]); + function goNext() { const err = validateStep(step); if (err) { setError(err); return; } setError(null); - setStepIdx((i) => Math.min(i + 1, steps.length - 1)); + go(steps[Math.min(current + 1, steps.length - 1)]); } function goBack() { setError(null); - setStepIdx((i) => Math.max(i - 1, 0)); + if ((window.history.state?.donateDepth ?? 0) > 0) window.history.back(); + else go(current > 0 ? steps[current - 1] : null, "replace"); } // Gift step: pick yes -> "who to?" step, pick no -> move straight on function chooseGift(choice: "yes" | "no") { set({ gift: choice }); - const s: string[] = ["intent"]; - if (ans.intent === "rank") s.push("rank"); - s.push("username"); - if (ans.intent === "upgrade") s.push("upgrade"); - s.push("gift"); - if (choice === "yes") s.push("giftTo"); - if (ans.intent === "custom") s.push("amount"); - s.push("confirm"); - setStepIdx(s.indexOf("gift") + 1); + go(choice === "yes" ? "giftTo" : ans.intent === "custom" ? "amount" : "confirm"); } async function handleSubmit() { @@ -517,6 +573,7 @@ export default function DonatePage() { forUser: ans.gift === "yes" ? giftToVal : playerVal, gift: ans.gift === "yes", }); + go(PAYMENT_STEP); } else toast.error(j.error || "Checkout failed"); } catch { toast.error("Checkout failed"); @@ -531,24 +588,30 @@ export default function DonatePage() { else goNext(); } - if (pending) { + const glow: GlowTheme = started ? glowFor(ans, step) : "green"; + + if (stepParam === PAYMENT_STEP && pending && !waiting) { return (
- setPending(null)} /> + window.history.back()} />
); } + if (waiting) { + return
; + } + if (!started) { return (
- +

Support FRG

Ranks are cosmetic only. Your donation keeps the server running and funds new features.

- +

Secure via Stripe ยท 1.5% to Stripe Climate

@@ -557,7 +620,8 @@ export default function DonatePage() { } return ( -
+
+
@@ -660,9 +724,7 @@ export default function DonatePage() { )}
- {current > 1 ? ( - - ) : } + {last ? (