AI Resource Pro / website · airesourcepro.com / src / app / roadmap / roadmap-view.tsx
| 1 | "use client"; |
| 2 | |
| 3 | import Image from "next/image"; |
| 4 | import Link from "next/link"; |
| 5 | import { ArrowRight, Check, Flag, RotateCcw, Map as MapIcon } from "lucide-react"; |
| 6 | import { TutorialMetaLine } from "@/components/tutorial-card"; |
| 7 | import { firstName } from "@/lib/display-name"; |
| 8 | import { LEVELS, WEEKLY_TIMES, labelFor } from "@/lib/onboarding"; |
| 9 | import { buildRoadmap, type RoadmapPhase, type RoadmapStep } from "@/lib/roadmap"; |
| 10 | import { getTrack } from "@/lib/tracks"; |
| 11 | import type { TutorialMeta } from "@/lib/tutorial-types"; |
| 12 | import { useLearningProfile, useRoadmapProgress } from "@/lib/use-learning-profile"; |
| 13 | import { cn } from "@/lib/utils"; |
| 14 | |
| 15 | const chip = |
| 16 | "inline-flex items-center rounded-full border border-border px-3 py-1.5 font-mono text-[11px] uppercase tracking-[0.08em] text-[var(--mist)]"; |
| 17 | |
| 18 | function StepRow({ step, done, onToggle }: { step: RoadmapStep; done: boolean; onToggle: () => void }) { |
| 19 | const t = step.tutorial; |
| 20 | const href = `/${t.track}/${t.slug}`; |
| 21 | return ( |
| 22 | <li |
| 23 | className={cn( |
| 24 | "group relative flex cursor-pointer items-start gap-4 rounded-2xl border p-4 transition-colors sm:items-center sm:gap-5 sm:p-5", |
| 25 | done ? "border-primary/40" : "border-border [@media(hover:hover)]:hover:border-foreground/30" |
| 26 | )} |
| 27 | style={{ "--tc": getTrack(t.track)?.color } as React.CSSProperties} |
| 28 | > |
| 29 | {/* Sits above the card's link so ticking it doesn't open the tutorial */} |
| 30 | <button |
| 31 | type="button" |
| 32 | role="checkbox" |
| 33 | aria-checked={done} |
| 34 | aria-label={done ? `Mark "${t.title}" as not done` : `Mark "${t.title}" as done`} |
| 35 | onClick={onToggle} |
| 36 | className={cn( |
| 37 | "relative z-10 mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-full border transition-colors before:absolute before:-inset-2.5 before:content-[''] sm:mt-0", |
| 38 | done ? "border-primary bg-primary text-primary-foreground" : "border-foreground/30 hover:border-primary" |
| 39 | )} |
| 40 | > |
| 41 | {done && <Check className="h-4 w-4" strokeWidth={2.5} />} |
| 42 | </button> |
| 43 | <div className="relative hidden aspect-[5/3] w-28 shrink-0 overflow-hidden rounded-lg border border-border sm:block"> |
| 44 | <Image src={t.cover} alt="" fill sizes="112px" className="object-cover" /> |
| 45 | </div> |
| 46 | <div className="min-w-0 flex-1"> |
| 47 | <TutorialMetaLine tutorial={t} /> |
| 48 | {/* The link's ::after covers the whole card, so anywhere on it opens the tutorial */} |
| 49 | <Link |
| 50 | href={href} |
| 51 | className={cn( |
| 52 | "mt-1.5 block text-[18px] font-normal leading-snug after:absolute after:inset-0 after:rounded-2xl after:content-[''] [@media(hover:hover)]:group-hover:underline [@media(hover:hover)]:group-hover:underline-offset-4", |
| 53 | done && "text-[var(--ash)]" |
| 54 | )} |
| 55 | > |
| 56 | {t.title} |
| 57 | </Link> |
| 58 | <p className="mt-1 text-[14px] text-[var(--ash)]">For: {step.reason}</p> |
| 59 | </div> |
| 60 | <ArrowRight |
| 61 | aria-hidden |
| 62 | className="hidden h-5 w-5 text-[var(--ash)] transition-transform group-hover:translate-x-0.5 group-hover:text-foreground md:block" |
| 63 | /> |
| 64 | </li> |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | function Phase({ phase, index, done, onToggle }: { phase: RoadmapPhase; index: number; done: Set<string>; onToggle: (key: string) => void }) { |
| 69 | const finished = phase.steps.filter((s) => done.has(s.key)).length; |
| 70 | const complete = finished === phase.steps.length; |
| 71 | return ( |
| 72 | <section className="relative pl-10 sm:pl-14"> |
| 73 | {/* Node on the timeline */} |
| 74 | <span |
| 75 | aria-hidden |
| 76 | className={cn( |
| 77 | "absolute left-0 top-1 flex h-7 w-7 items-center justify-center rounded-full border font-mono text-[12px]", |
| 78 | complete ? "border-primary bg-primary text-primary-foreground" : "border-primary/60 bg-background text-[var(--accent-text)]" |
| 79 | )} |
| 80 | style={complete ? undefined : { boxShadow: "0 0 18px var(--card-glow)" }} |
| 81 | > |
| 82 | {complete ? <Check className="h-4 w-4" strokeWidth={2.5} /> : index + 1} |
| 83 | </span> |
| 84 | <p className="font-mono text-[12px] uppercase tracking-[0.08em] text-[var(--ash)]"> |
| 85 | Phase {index + 1} · {finished}/{phase.steps.length} done |
| 86 | </p> |
| 87 | <h2 className="mt-2 font-display text-[clamp(28px,3.2vw,40px)] font-normal leading-tight tracking-[-0.03em]">{phase.title}</h2> |
| 88 | <p className="mt-2 max-w-[60ch] text-[16px] text-[var(--mist)]">{phase.summary}</p> |
| 89 | <p className="mt-3 font-mono text-[11.5px] uppercase tracking-[0.08em] text-[var(--ash)]"> |
| 90 | About {phase.weeks} {phase.weeks === 1 ? "week" : "weeks"} at your pace · {phase.minutes} min of tutorials |
| 91 | </p> |
| 92 | <ol className="mt-6 grid gap-3"> |
| 93 | {phase.steps.map((s) => ( |
| 94 | <StepRow key={s.key} step={s} done={done.has(s.key)} onToggle={() => onToggle(s.key)} /> |
| 95 | ))} |
| 96 | </ol> |
| 97 | <p className="mt-5 flex items-start gap-3 text-[15px] text-[var(--mist)]"> |
| 98 | <Flag className="mt-0.5 h-4 w-4 shrink-0 text-[var(--accent-text)]" /> |
| 99 | <span> |
| 100 | <span className="font-mono text-[11.5px] uppercase tracking-[0.08em] text-[var(--accent-text)]">Milestone </span> |
| 101 | {phase.milestone}. |
| 102 | </span> |
| 103 | </p> |
| 104 | </section> |
| 105 | ); |
| 106 | } |
| 107 | |
| 108 | function Intro() { |
| 109 | return ( |
| 110 | <div className="max-w-[820px]"> |
| 111 | <p className="label"> |
| 112 | <i /> |
| 113 | My roadmap |
| 114 | </p> |
| 115 | <h1 className="display-title mt-6 text-[clamp(44px,6.4vw,92px)]">A learning path built around you</h1> |
| 116 | <p className="mt-6 max-w-[56ch] text-[18px] leading-relaxed text-[var(--mist)]"> |
| 117 | Answer five quick questions about what you want from AI and where you are now. We'll turn the site's |
| 118 | tutorials into a step-by-step plan, paced to the time you have, and you can tick things off as you go. |
| 119 | </p> |
| 120 | <div className="mt-10 flex flex-wrap items-center gap-6"> |
| 121 | <Link href="/roadmap/start" className="pill"> |
| 122 | <MapIcon className="size-4" strokeWidth={2} aria-hidden="true" /> |
| 123 | Build my roadmap <ArrowRight className="h-4 w-4" /> |
| 124 | </Link> |
| 125 | <span className="font-mono text-[12px] uppercase tracking-[0.08em] text-[var(--ash)]">About a minute</span> |
| 126 | </div> |
| 127 | </div> |
| 128 | ); |
| 129 | } |
| 130 | |
| 131 | export function RoadmapView({ tutorials }: { tutorials: TutorialMeta[] }) { |
| 132 | const { user, profile } = useLearningProfile(); |
| 133 | const { done, toggle } = useRoadmapProgress(); |
| 134 | |
| 135 | if (profile === undefined || done === null) return <div className="min-h-[60vh]" />; |
| 136 | if (!profile) return <Intro />; |
| 137 | |
| 138 | const roadmap = buildRoadmap(profile, tutorials); |
| 139 | const finished = roadmap.phases.flatMap((p) => p.steps).filter((s) => done.has(s.key)).length; |
| 140 | const pct = roadmap.totalSteps ? Math.round((finished / roadmap.totalSteps) * 100) : 0; |
| 141 | |
| 142 | return ( |
| 143 | <> |
| 144 | <p className="label"> |
| 145 | <i /> |
| 146 | My roadmap |
| 147 | </p> |
| 148 | <h1 className="display-title mt-6 break-words text-[clamp(40px,5.6vw,80px)]"> |
| 149 | {user ? `${firstName(user)}, here's your path` : "Here's your path"} |
| 150 | </h1> |
| 151 | |
| 152 | <div className="mt-8 flex flex-wrap items-center gap-2"> |
| 153 | <span className={chip}>{labelFor(LEVELS, profile.level)}</span> |
| 154 | {roadmap.tracks.map((t) => ( |
| 155 | <span key={t} className={chip} style={{ color: getTrack(t)?.color }}> |
| 156 | {getTrack(t)?.name} |
| 157 | </span> |
| 158 | ))} |
| 159 | <span className={chip}>{labelFor(WEEKLY_TIMES, profile.weeklyTime)}</span> |
| 160 | <Link href="/roadmap/start" className="ml-1 inline-flex items-center gap-1.5 font-mono text-[11.5px] uppercase tracking-[0.08em] text-[var(--link)] hover:underline hover:underline-offset-4"> |
| 161 | <RotateCcw className="h-3.5 w-3.5" /> Retake the questions |
| 162 | </Link> |
| 163 | </div> |
| 164 | |
| 165 | <div className="mt-10 max-w-[560px]"> |
| 166 | <div className="flex items-baseline justify-between font-mono text-[12px] uppercase tracking-[0.08em] text-[var(--ash)]"> |
| 167 | <span> |
| 168 | {finished} of {roadmap.totalSteps} done |
| 169 | </span> |
| 170 | <span>{pct}%</span> |
| 171 | </div> |
| 172 | <div className="mt-3 h-1 overflow-hidden rounded-full bg-border"> |
| 173 | <div className="h-full rounded-full bg-primary transition-[width] duration-700" style={{ width: `${pct}%` }} /> |
| 174 | </div> |
| 175 | </div> |
| 176 | |
| 177 | {!user && ( |
| 178 | <p className="mt-8 max-w-[640px] rounded-2xl border border-border p-5 text-[15px] text-[var(--mist)]"> |
| 179 | Your roadmap is saved in this browser for now.{" "} |
| 180 | <Link href="/login?next=/roadmap" className="text-link"> |
| 181 | Sign in |
| 182 | </Link>{" "} |
| 183 | to keep it and your progress on any device. |
| 184 | </p> |
| 185 | )} |
| 186 | |
| 187 | {roadmap.phases.length === 0 ? ( |
| 188 | <p className="mt-16 border-t border-border pt-6 text-[var(--mist)]"> |
| 189 | There aren't tutorials for those tools yet. <Link href="/roadmap/start" className="text-link">Pick other tools</Link>{" "} |
| 190 | or browse <Link href="/tutorials" className="text-link">all tutorials</Link>. |
| 191 | </p> |
| 192 | ) : ( |
| 193 | <div className="relative mt-16 space-y-16"> |
| 194 | <span aria-hidden className="absolute bottom-2 left-[13px] top-2 w-px bg-gradient-to-b from-primary/70 via-border to-transparent" /> |
| 195 | {roadmap.phases.map((phase, i) => ( |
| 196 | <Phase key={phase.level} phase={phase} index={i} done={done} onToggle={toggle} /> |
| 197 | ))} |
| 198 | </div> |
| 199 | )} |
| 200 | </> |
| 201 | ); |
| 202 | } |