Spaces:
Sleeping
Sleeping
File size: 11,330 Bytes
96dd01c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | import { useState } from "react";
import "./App.css";
const API = import.meta.env.VITE_API_URL || (import.meta.env.PROD ? "" : "http://localhost:8000");
const EXAMPLES = [
"Become a Data Scientist",
"Switch from Marketing to Product Management",
"Become a Full Stack Developer",
"Break into AI/ML Engineering",
"Become a UX Designer",
];
const LOADING_MESSAGES = [
"Mapping your career path...",
"Building your steps...",
"Crafting macro & micro views...",
"Adding nano-level tasks...",
"Almost ready...",
];
const STEP_ACCENTS = ["#1a9e75", "#3b82f6", "#8b5cf6", "#f59e0b", "#ec4899", "#06b6d4"];
export default function App() {
const [goal, setGoal] = useState("");
const [loading, setLoading] = useState(false);
const [loadingMsg, setLoadingMsg] = useState("");
const [data, setData] = useState(null);
const [error, setError] = useState("");
const [activeStep, setActiveStep] = useState(null);
async function generate(overrideGoal) {
const g = (overrideGoal || goal).trim();
if (!g) return;
setLoading(true);
setError("");
setData(null);
setActiveStep(null);
let i = 0;
setLoadingMsg(LOADING_MESSAGES[0]);
const interval = setInterval(() => {
i = (i + 1) % LOADING_MESSAGES.length;
setLoadingMsg(LOADING_MESSAGES[i]);
}, 1800);
try {
const res = await fetch(`${API}/api/path`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ goal: g }),
});
const json = await res.json();
if (!res.ok) throw new Error(json.detail || "Something went wrong");
setData(json);
} catch (e) {
setError(
e.message.includes("fetch")
? "Cannot connect to backend. Run: uvicorn main:app --reload --port 8000"
: e.message
);
} finally {
clearInterval(interval);
setLoading(false);
}
}
function openSearch(query) {
const url = `https://www.google.com/search?q=${encodeURIComponent(query)}`;
window.open(url, "_blank", "noopener,noreferrer");
}
async function copyNanoTask() {
if (!activeStep?.nano?.what_you_do) return;
await navigator.clipboard.writeText(activeStep.nano.what_you_do);
}
function handleKey(e) { if (e.key === "Enter") generate(); }
function handleChip(ex) { setGoal(ex); generate(ex); }
function openStep(step) { setActiveStep(step); }
function closeStep() { setActiveStep(null); }
const activeIdx = activeStep ? data?.steps.findIndex((s) => s.id === activeStep.id) : -1;
const activeAccent = activeIdx >= 0 ? STEP_ACCENTS[activeIdx % STEP_ACCENTS.length] : "#1a9e75";
return (
<div className="app">
{/* ββ Nav ββ */}
<nav className="nav">
<div className="nav-logo">
<div className="nav-mark">N</div>
<span className="nav-brand">Naaviverse</span>
</div>
<span className="nav-pill">Path Simulator</span>
</nav>
{/* ββ Hero ββ */}
{!data && !loading && (
<header className="hero">
<p className="hero-eyebrow">Education and Career Path Engine</p>
<h1 className="hero-headline">
Turn an education goal into a{" "}
<span className="hero-accent hero-accent--nowrap">step-by-step path.</span>
</h1>
<p className="hero-sub">
Enter a career, exam, or skill goal. Naaviverse maps the macro strategy, micro skills, and nano tasks.
</p>
</header>
)}
{/* ββ Input ββ */}
<section className={`input-section ${data ? "input-section--compact" : "input-section--starter"}`}>
<div className="input-shell">
<input
className="goal-input"
value={goal}
onChange={(e) => setGoal(e.target.value)}
onKeyDown={handleKey}
placeholder="e.g. Become a Data Scientist"
disabled={loading}
/>
<button
className="gen-btn"
onClick={() => generate()}
disabled={loading || !goal.trim()}
>
{loading ? (
<span className="btn-loading"><span className="btn-spinner" /> Generating</span>
) : "Generate Path β"}
</button>
</div>
<div className="chips">
{EXAMPLES.map((ex) => (
<button key={ex} className="chip" onClick={() => handleChip(ex)} disabled={loading}>
{ex}
</button>
))}
</div>
</section>
{/* ββ Loading ββ */}
{loading && (
<div className="loading-state">
<div className="loading-track"><div className="loading-bar" /></div>
<p className="loading-msg">{loadingMsg}</p>
</div>
)}
{/* ββ Error ββ */}
{error && <div className="error-banner">β {error}</div>}
{/* ββ Result ββ */}
{data && (
<div className="result">
{/* Path header β always visible */}
<div className="path-header-card">
<div className="path-header-left">
<h2 className="path-name">{data.path_name}</h2>
<p className="path-desc">{data.path_description}</p>
</div>
<div className="path-steps-badge">
<span className="badge-num">{data.total_steps}</span>
<span className="badge-label">TOTAL STEPS</span>
</div>
</div>
{/* ββ MODE A: Step grid (no active step) ββ */}
{!activeStep && (
<div className="steps-section">
<div className="steps-header">
<span className="steps-label">ALL STEPS</span>
<div className="steps-divider" />
<span className="steps-count">{data.total_steps} Steps Β· click any to explore</span>
</div>
<div className="steps-grid">
{data.steps.map((step, idx) => {
const accent = STEP_ACCENTS[idx % STEP_ACCENTS.length];
return (
<button
key={step.id}
className="step-card"
style={{ "--accent": accent }}
onClick={() => openStep(step)}
>
<div className="step-num-circle" style={{ background: accent + "22", color: accent, border: `1.5px solid ${accent}55` }}>
{step.id}
</div>
<h3 className="step-title">{step.title}</h3>
<p className="step-desc">{step.description}</p>
<span className="step-explore-hint" style={{ color: accent }}>Tap to explore β</span>
</button>
);
})}
</div>
</div>
)}
{/* ββ MODE B: Expanded view (active step) ββ */}
{activeStep && (
<div className="views-section" key={activeStep.id}>
{/* Top bar: back + step number pills */}
<div className="views-back-bar">
<button className="back-btn" onClick={closeStep}>
β All Steps
</button>
</div>
{/* Step intro */}
<div className="views-intro">
<div className="views-step-badge" style={{ background: activeAccent + "18", color: activeAccent, border: `1px solid ${activeAccent}44` }}>
Step {activeStep.id} of {data.total_steps}
</div>
<h2 className="views-heading">{activeStep.title}</h2>
<p className="views-desc">{activeStep.description}</p>
</div>
{/* 3 view cards */}
<div className="views-grid">
<div className="view-card view-card--macro">
<div className="view-card-top">
<span className="view-tag view-tag--macro">MACRO VIEW</span>
<span className="view-badge view-badge--free">FREE</span>
</div>
<h4 className="view-title">{activeStep.macro.title}</h4>
<p className="view-sublabel">WHY THIS STEP MATTERS</p>
<p className="view-body">{activeStep.macro.why_it_matters}</p>
<button
className="view-cta view-cta--macro"
onClick={() => openSearch(`${activeStep.title} learning roadmap`)}
>
Discover Resources β
</button>
</div>
<div className="view-card view-card--micro">
<div className="view-card-top">
<span className="view-tag view-tag--micro">MICRO VIEW</span>
<span className="view-badge view-badge--micro">MICRO PLAN</span>
</div>
<h4 className="view-title">{activeStep.micro.title}</h4>
<p className="view-sublabel">HOW IT'S DONE</p>
<p className="view-body">{activeStep.micro.how_its_done}</p>
<button
className="view-cta view-cta--micro"
onClick={() => openSearch(`${activeStep.micro.title} course tutorial`)}
>
Browse Resources β
</button>
</div>
<div className="view-card view-card--nano">
<div className="view-card-top">
<span className="view-tag view-tag--nano">NANO VIEW</span>
<span className="view-badge view-badge--nano">NANO PLAN</span>
</div>
<h4 className="view-title">{activeStep.nano.title}</h4>
<p className="view-sublabel">LIVE MENTOR GUIDANCE</p>
<p className="view-body">{activeStep.nano.what_you_do}</p>
<button className="view-cta view-cta--nano" onClick={copyNanoTask}>
Copy Task β
</button>
</div>
</div>
{/*
Disabled: users should return to All Steps before opening another step.
<div className="views-nav-row">
<button
className="views-nav-btn"
disabled={activeStep.id === 1}
onClick={() => openStep(data.steps[activeStep.id - 2])}
>
β Previous Step
</button>
<button
className="views-nav-btn views-nav-btn--primary"
disabled={activeStep.id === data.total_steps}
onClick={() => openStep(data.steps[activeStep.id])}
>
Next Step β
</button>
</div>
*/}
</div>
)}
{/* Footer */}
<div className="result-footer">
<button className="reset-btn" onClick={() => { setData(null); setGoal(""); setActiveStep(null); }}>
β Try another goal
</button>
</div>
</div>
)}
</div>
);
}
|