"use client"; /** * QuizzesCTA — the way into /quizzes, in two shapes: * * - "tile": a card that leads the search page's "Start here" row. * - "banner": a full-width row for the homepage, under sādhana / vāṇī. * * Renders nothing until there is at least one published quiz; with * `pendingOnly` it also hides once every quiz has been finished, so the * homepage only nudges when there's something left to do. */ import { useEffect, useState } from "react"; import Link from "next/link"; import { ArrowUpRight, ChevronRight, ClipboardCheck } from "lucide-react"; import { useAuth } from "@/components/auth/auth-provider"; import { quiz, type QuizCard } from "@/lib/quiz"; import { cn } from "@/lib/utils"; export function QuizzesCTA({ variant = "banner", pendingOnly = false, className, }: { variant?: "banner" | "tile"; pendingOnly?: boolean; className?: string; }) { const { user } = useAuth(); const [cards, setCards] = useState(null); useEffect(() => { let cancelled = false; quiz .list() .then((c) => { if (!cancelled) setCards(c); }) .catch(() => { /* CTA simply doesn't render */ }); return () => { cancelled = true; }; // Refetch on sign-in/out: progress is per user. }, [user?.id]); if (!cards?.length) return null; if (pendingOnly && cards.every((c) => c.my.state === "completed")) { return null; } const tagline = "Test your understanding of chapters, lectures and more"; if (variant === "tile") { // Matches the search page's FeaturedTile so it sits in that grid as an // equal: same padding, icon chip, title scale and corner arrow. return (

Quizzes

{tagline}

); } return (

Quizzes

{tagline}

); }