Spaces:
Sleeping
Sleeping
Download Agent_Frontend/src/App.jsx from Chaithu8790/Codex_Agent: direct link, hf CLI and curl.
- Browser
- Download file 11.3 kB
-
https://huggingface.co/spaces/Chaithu8790/Codex_Agent/resolve/main/Agent_Frontend/src/App.jsx
- Command line
-
hf download hf://spaces/Chaithu8790/Codex_Agent/Agent_Frontend/src/App.jsx
-
curl -L -o App.jsx https://huggingface.co/spaces/Chaithu8790/Codex_Agent/resolve/main/Agent_Frontend/src/App.jsx
11.3 kB
| 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> | |
| ); | |
| } | |