The admin area was managing a Hacker News-style Item model that the
public site never consumed, so the homepage always fell back to sample
data. Rebuild the admin area around the real public content model.
Backend:
- Remove the Item model, schema and admin API
- Admin API now manages articles at /api/v1/admin/articles (CRUD) with
/api/v1/admin/authors and /api/v1/admin/categories reference data
- Add public read-only article endpoints (/api/v1/articles,
/api/v1/articles/{id}): no auth, published-only, newest-first
- Rewrite Article schemas; ArticleRead embeds author and category
- Add idempotent seed_content.py dev seeder (3 authors, 4 categories,
6 published articles)
Frontend:
- Admin UI rewritten around articles: AdminDashboard list, new
EditArticlePage (create/edit, author/category selects, published
toggle, Lexical editor, debounced auto-save)
- Replace AdminItem types and api client with the article domain
- Update App routes, AdminLayout sidebar, DeleteConfirmation, Lexical
editor labels and Home/client comments to article terminology
Tests:
- Rewrite admin unit tests and the Playwright admin e2e spec for the
article domain; add test_articles.py for the public endpoints and
seeder
99 lines
3.3 KiB
TypeScript
99 lines
3.3 KiB
TypeScript
import { BrowserRouter, Link, Route, Routes } from 'react-router-dom';
|
|
import { AuthProvider, RequireAdmin, RequireAuth } from './auth';
|
|
import AdminLayout from './components/AdminLayout';
|
|
import Layout from './components/ui/Layout';
|
|
import Account from './pages/Account';
|
|
import AdminDashboard from './pages/AdminDashboard';
|
|
import ArticlePage from './pages/ArticlePage';
|
|
import CategoriesPage from './pages/CategoriesPage';
|
|
import EditArticlePage from './pages/EditArticlePage';
|
|
import Home from './pages/Home';
|
|
import Login from './pages/Login';
|
|
import Register from './pages/Register';
|
|
import SignOut from './pages/SignOut';
|
|
|
|
/** 404 fallback for unknown routes. */
|
|
function NotFound() {
|
|
return (
|
|
<div className="container-page text-center">
|
|
<h1 className="mb-2 text-5xl font-bold text-slate-900">404</h1>
|
|
<p className="mb-6 text-sm text-slate-600">
|
|
That page could not be found. It may have moved, or the link may be broken.
|
|
</p>
|
|
<Link to="/" className="btn">
|
|
Back to home
|
|
</Link>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Root component: owns the React Router + auth setup.
|
|
*
|
|
* BrowserRouter wraps the whole app; AuthProvider restores the JWT
|
|
* session and exposes login/register/logout (see src/auth.tsx).
|
|
*
|
|
* Two shells are used:
|
|
* - the admin area (`/admin/*`, M6) renders inside its own dark sidebar
|
|
* layout (`AdminLayout`) and is guarded by `RequireAdmin`;
|
|
* - everything else renders inside the public site `Layout`
|
|
* (header/footer) with `RequireAuth` guarding the account page.
|
|
*
|
|
* In-app navigation always uses react-router-dom <Link>/<NavLink>.
|
|
*/
|
|
export default function App() {
|
|
return (
|
|
<BrowserRouter
|
|
future={{
|
|
v7_startTransition: true,
|
|
v7_relativeSplatPath: true,
|
|
}}
|
|
>
|
|
<AuthProvider>
|
|
<Routes>
|
|
{/* Admin area (own shell, admin-only) */}
|
|
<Route
|
|
path="/admin"
|
|
element={
|
|
<RequireAdmin>
|
|
<AdminLayout />
|
|
</RequireAdmin>
|
|
}
|
|
>
|
|
<Route index element={<AdminDashboard />} />
|
|
<Route path="articles/new" element={<EditArticlePage />} />
|
|
<Route path="articles/:id/edit" element={<EditArticlePage />} />
|
|
</Route>
|
|
|
|
{/* Public site */}
|
|
<Route
|
|
path="*"
|
|
element={
|
|
<Layout>
|
|
<Routes>
|
|
<Route path="/" element={<Home />} />
|
|
<Route path="/articles" element={<ArticlePage />} />
|
|
<Route path="/articles/:id" element={<ArticlePage />} />
|
|
<Route path="/categories" element={<CategoriesPage />} />
|
|
<Route path="/login" element={<Login />} />
|
|
<Route path="/register" element={<Register />} />
|
|
<Route path="/sign-out" element={<SignOut />} />
|
|
<Route
|
|
path="/account"
|
|
element={
|
|
<RequireAuth>
|
|
<Account />
|
|
</RequireAuth>
|
|
}
|
|
/>
|
|
<Route path="*" element={<NotFound />} />
|
|
</Routes>
|
|
</Layout>
|
|
}
|
|
/>
|
|
</Routes>
|
|
</AuthProvider>
|
|
</BrowserRouter>
|
|
);
|
|
}
|