|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import Link from "next/link"; |
| 4 | +import { useEffect, useState } from "react"; |
| 5 | +import { IconChevronLeft, IconChevronRight, IconPlay } from "@/components/icons"; |
| 6 | +import { MaturityBadge } from "@/components/maturity-badge"; |
| 7 | +import { TaskDrawer } from "@/components/task-drawer"; |
| 8 | +import type { TaskIndexItem } from "@/lib/task-index"; |
| 9 | +import { formatShortDate } from "@/lib/format"; |
| 10 | +import { taskHandle, taskTitle } from "@/lib/task-display"; |
| 11 | + |
| 12 | +export function FeaturedTaskCarousel({ |
| 13 | + tasks |
| 14 | +}: { |
| 15 | + tasks: TaskIndexItem[]; |
| 16 | +}) { |
| 17 | + const [activeIndex, setActiveIndex] = useState(0); |
| 18 | + const [drawerRepo, setDrawerRepo] = useState<string | null>(null); |
| 19 | + |
| 20 | + useEffect(() => { |
| 21 | + if (tasks.length < 2) return undefined; |
| 22 | + |
| 23 | + const timer = window.setInterval(() => { |
| 24 | + setActiveIndex((current) => (current + 1) % tasks.length); |
| 25 | + }, 6500); |
| 26 | + |
| 27 | + return () => window.clearInterval(timer); |
| 28 | + }, [tasks.length]); |
| 29 | + |
| 30 | + if (tasks.length === 0) { |
| 31 | + return ( |
| 32 | + <div className="tb-frame bg-[#fffdf9] p-6"> |
| 33 | + <div className="font-heading text-2xl font-bold text-[#25314d]"> |
| 34 | + Featured tasks are unavailable in this build. |
| 35 | + </div> |
| 36 | + </div> |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + const activeTask = tasks[activeIndex] ?? tasks[0]; |
| 41 | + const preview = activeTask.web_variant; |
| 42 | + const drawerTask = tasks.find((task) => task.repo === drawerRepo) ?? null; |
| 43 | + |
| 44 | + function goTo(nextIndex: number) { |
| 45 | + const total = tasks.length; |
| 46 | + setActiveIndex(((nextIndex % total) + total) % total); |
| 47 | + } |
| 48 | + |
| 49 | + return ( |
| 50 | + <> |
| 51 | + <div className="tb-frame bg-[#fffdf9] p-6"> |
| 52 | + <div className="flex flex-wrap items-center justify-between gap-3"> |
| 53 | + <div> |
| 54 | + <div className="text-sm font-bold text-slate-600">Featured Tasks</div> |
| 55 | + <div className="mt-1 font-heading text-3xl font-bold text-[#25314d]"> |
| 56 | + Rotate through flagship paradigms |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + |
| 60 | + <div className="flex items-center gap-2"> |
| 61 | + <button |
| 62 | + type="button" |
| 63 | + className="tb-focus-ring tb-button-ghost p-3" |
| 64 | + onClick={() => goTo(activeIndex - 1)} |
| 65 | + aria-label="Show previous featured task" |
| 66 | + > |
| 67 | + <IconChevronLeft className="size-4" /> |
| 68 | + </button> |
| 69 | + <button |
| 70 | + type="button" |
| 71 | + className="tb-focus-ring tb-button-ghost p-3" |
| 72 | + onClick={() => goTo(activeIndex + 1)} |
| 73 | + aria-label="Show next featured task" |
| 74 | + > |
| 75 | + <IconChevronRight className="size-4" /> |
| 76 | + </button> |
| 77 | + </div> |
| 78 | + </div> |
| 79 | + |
| 80 | + <div className="mt-5 flex flex-wrap gap-2"> |
| 81 | + {tasks.map((task, index) => ( |
| 82 | + <button |
| 83 | + key={task.repo} |
| 84 | + type="button" |
| 85 | + className={ |
| 86 | + index === activeIndex |
| 87 | + ? "tb-focus-ring rounded-full border-2 border-[#25314d] bg-[#d7ebf6] px-3 py-1.5 text-sm font-bold text-[#25314d] shadow-[0_4px_0_#25314d]" |
| 88 | + : "tb-focus-ring rounded-full border-2 border-[#25314d] bg-white px-3 py-1.5 text-sm font-bold text-[#25314d]" |
| 89 | + } |
| 90 | + onClick={() => setActiveIndex(index)} |
| 91 | + > |
| 92 | + {task.tags?.paradigm?.[0] ?? taskHandle(task)} |
| 93 | + </button> |
| 94 | + ))} |
| 95 | + </div> |
| 96 | + |
| 97 | + <div className="mt-5 tb-frame-soft bg-[#f8fcff] p-5"> |
| 98 | + <div className="flex flex-wrap items-center gap-2 text-xs text-slate-600"> |
| 99 | + <code className="rounded-full border-2 border-[#25314d] bg-white px-2.5 py-1 font-mono text-[11px] font-semibold text-[#25314d]"> |
| 100 | + {taskHandle(activeTask)} |
| 101 | + </code> |
| 102 | + {activeTask.maturity ? <MaturityBadge maturity={activeTask.maturity} /> : null} |
| 103 | + {preview ? ( |
| 104 | + <span className="rounded-full bg-[#ecffe5] px-3 py-1 text-[11px] font-bold text-[#25314d]"> |
| 105 | + Preview available |
| 106 | + </span> |
| 107 | + ) : null} |
| 108 | + <span className="rounded-full bg-[#e2f3fb] px-3 py-1 text-[11px] font-bold text-[#25314d]"> |
| 109 | + {formatShortDate(activeTask.last_updated)} |
| 110 | + </span> |
| 111 | + </div> |
| 112 | + |
| 113 | + <div className="mt-4 font-heading text-3xl font-bold leading-tight text-[#25314d]"> |
| 114 | + {taskTitle(activeTask)} |
| 115 | + </div> |
| 116 | + |
| 117 | + <p className="mt-3 max-w-2xl text-sm leading-7 text-slate-700 sm:text-base"> |
| 118 | + {activeTask.short_description} |
| 119 | + </p> |
| 120 | + |
| 121 | + <div className="mt-6 flex flex-wrap gap-3"> |
| 122 | + <button |
| 123 | + type="button" |
| 124 | + className="tb-focus-ring tb-button-primary" |
| 125 | + onClick={() => setDrawerRepo(activeTask.repo)} |
| 126 | + > |
| 127 | + Expand details |
| 128 | + </button> |
| 129 | + {preview ? ( |
| 130 | + <a |
| 131 | + className="tb-focus-ring tb-button-secondary bg-[#d7ebf6]" |
| 132 | + href={preview.run_url} |
| 133 | + target="_blank" |
| 134 | + rel="noreferrer" |
| 135 | + > |
| 136 | + <IconPlay className="size-4" /> |
| 137 | + Run Preview |
| 138 | + </a> |
| 139 | + ) : null} |
| 140 | + </div> |
| 141 | + </div> |
| 142 | + |
| 143 | + <div className="mt-6 flex flex-wrap items-center justify-between gap-4"> |
| 144 | + <div className="text-sm leading-6 text-slate-700"> |
| 145 | + Highlighted here: BART, SST, and MID as fast entry points into the broader task catalog. |
| 146 | + </div> |
| 147 | + <Link className="tb-focus-ring tb-button-primary" href="/tasks/"> |
| 148 | + Continue to Tasks |
| 149 | + </Link> |
| 150 | + </div> |
| 151 | + </div> |
| 152 | + |
| 153 | + <TaskDrawer task={drawerTask} onClose={() => setDrawerRepo(null)} /> |
| 154 | + </> |
| 155 | + ); |
| 156 | +} |
0 commit comments