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 (
Education and Career Path Engine
Enter a career, exam, or skill goal. Naaviverse maps the macro strategy, micro skills, and nano tasks.
{loadingMsg}
{data.path_description}
{activeStep.description}
WHY THIS STEP MATTERS
{activeStep.macro.why_it_matters}
HOW IT'S DONE
{activeStep.micro.how_its_done}
LIVE MENTOR GUIDANCE
{activeStep.nano.what_you_do}