Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/screenshots/overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
185 changes: 25 additions & 160 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,191 +1,56 @@
import { useEffect, useState } from "react";
import DocumentLibrary from "./DocumentLibrary";
import AskContextIQ from "./AskContextIQ";
import "./App.css";
import "./phase2.css";
import Overview from "./Overview";
import Login from "./Login";
import { apiFetch } from "./api";
import "./App.css";
import "./phase2.css";

type Readiness = { status: string; checks: Record<string, string> };
type Page = "overview" | "documents" | "ask";

export default function App() {
const [page, setPage] = useState(() => {
const [page, setPage] = useState<Page>(() => {
const saved = window.location.hash.replace("#", "");
return saved === "documents" || saved === "ask" ? saved : "overview";
});
const [api, setApi] = useState("checking");
const [readiness, setReadiness] = useState<Readiness | null>(null);
const [auth, setAuth] = useState<"checking" | "authenticated" | "anonymous">(
"checking",
);

useEffect(() => {
fetch("/api/health")
.then((response) => {
if (!response.ok) throw new Error("API error");
return response.json();
})
.then(() => setApi("online"))
.catch(() => setApi("offline"));
fetch("/api/ready")
.then((response) => {
if (!response.ok) throw new Error("Readiness error");
return response.json();
})
.then(setReadiness)
.catch(() => setReadiness(null));
}, []);
const [auth, setAuth] = useState<"checking" | "authenticated" | "anonymous">("checking");

// Session verification runs once on application initialization.
// The overview loads its own live API data when it becomes visible.
useEffect(() => {
fetch("/api/auth/me")
.then((response) => {
setAuth(response.ok ? "authenticated" : "anonymous");
})
void fetch("/api/auth/me", { credentials: "same-origin" })
.then((response) => setAuth(response.ok ? "authenticated" : "anonymous"))
.catch(() => setAuth("anonymous"));
}, []);

if (auth === "checking") {
return <main className="login-page">Checking session...</main>;
function navigate(next: Page) {
setPage(next);
window.location.hash = next;
}

if (auth === "anonymous") {
return <Login onAuthenticated={() => setAuth("authenticated")} />;
}
if (auth === "checking") return <main className="login-page">Checking session...</main>;
if (auth === "anonymous") return <Login onAuthenticated={() => setAuth("authenticated")} />;

return (
<div className="shell">
<aside className="sidebar">
<div className="brand">
<span className="mark">C</span> Context<span>IQ</span>
</div>
<div className="brand"><span className="mark">C</span> Context<span>IQ</span></div>
<div className="section-label">WORKSPACE</div>
<nav aria-label="Main navigation">
<button
className={`nav-item ${page === "overview" ? "active" : ""}`}
onClick={() => {
setPage("overview");
window.location.hash = "overview";
}}
>
▦ &nbsp; Overview
</button>
<button
className={`nav-item ${page === "documents" ? "active" : ""}`}
onClick={() => {
setPage("documents");
window.location.hash = "documents";
}}
>
▤ &nbsp; Documents
</button>
<button
className={`nav-item ${page === "ask" ? "active" : ""}`}
onClick={() => {
setPage("ask");
window.location.hash = "ask";
}}
>
◇ &nbsp; Ask ContextIQ
</button>
<button
type="button"
className="nav-item"
onClick={async () => {
const response = await apiFetch("/api/auth/logout", {
method: "POST",
});

if (response.ok || response.status === 401) {
setAuth("anonymous");
}
}}
>
Sign out
</button>
<button type="button" className={`nav-item ${page === "overview" ? "active" : ""}`} onClick={() => navigate("overview")}>▦ &nbsp; Overview</button>
<button type="button" className={`nav-item ${page === "documents" ? "active" : ""}`} onClick={() => navigate("documents")}>▤ &nbsp; Documents</button>
<button type="button" className={`nav-item ${page === "ask" ? "active" : ""}`} onClick={() => navigate("ask")}>◇ &nbsp; Ask ContextIQ</button>
<button type="button" className="nav-item" onClick={async () => {
const response = await apiFetch("/api/auth/logout", { method: "POST" });
if (response.ok || response.status === 401) setAuth("anonymous");
}}>Sign out</button>
</nav>
<div className="sidebar-bottom">
LOCAL DEVELOPMENT <span className="green-dot" /> $0 cloud spend
</div>
<div className="sidebar-bottom">LOCAL DEVELOPMENT <span className="green-dot" /> $0 cloud spend</div>
</aside>
<main className="content">
{page === "documents" ? (
<DocumentLibrary />
) : page === "ask" ? (
<AskContextIQ />
) : (
<>
<div className="eyebrow">KNOWLEDGE INTELLIGENCE / OVERVIEW</div>
<h1>
Your knowledge, <em>connected.</em>
</h1>
<p className="intro">
A private, local-first workspace for evidence-grounded document
intelligence.
</p>
<div className="banner">
<div>
<strong>Document intelligence</strong>
<p>
Phase 3 adds semantic document retrieval and source-grounded
answers with Ollama.
</p>
</div>
<span className="phase">PHASE 03 / 07</span>
</div>
<h2>System status</h2>
<div className="cards">
<StatusCard
name="FastAPI service"
detail="REST API"
status={api}
/>
<StatusCard
name="PostgreSQL + pgvector"
detail="Vector storage"
status={readiness?.checks.database ?? "checking"}
/>
<StatusCard
name="Azure Blob emulator"
detail="Azurite local storage"
status={readiness?.checks.blob_emulator ?? "checking"}
/>
</div>
<div className="empty">
<div className="empty-icon">▤</div>
<h3>Document library is ready</h3>
<p>
Choose Documents in the sidebar to upload and inspect your PDFs.
</p>
<span>PDF UPLOAD · PHASE 2</span>
</div>
<footer>ContextIQ v0.3.0 · Local development environment</footer>
</>
)}
{page === "documents" ? <DocumentLibrary /> : page === "ask" ? <AskContextIQ /> : <Overview onNavigate={navigate} />}
</main>
</div>
);
}

function StatusCard({
name,
detail,
status,
}: {
name: string;
detail: string;
status: string;
}) {
const healthy = status === "ok" || status === "online";
return (
<div className="status-card">
<div className="status-head">
<span className="status-icon">◈</span>
<span className={healthy ? "pill good" : "pill"}>
{healthy ? "Connected" : status}
</span>
</div>
<strong>{name}</strong>
<p>{detail}</p>
</div>
);
}
Loading
Loading