feat: add React + TypeScript frontend with Vite, routing, tests and Docker setup

M3 frontend infrastructure for the newzy news application:

- Vite + React 18 + TypeScript project (Node >=18) in frontend/
- React Router v6: BrowserRouter in App.tsx, routes for /, /articles,
  /articles/:id and /categories, Link/NavLink-based navigation
- lucide-react icons (Home, FileText, Settings, Search, ...) in the
  responsive Header (desktop + mobile menu) and article components
- Reusable components: ArticleCard, AuthorAvatar, CategoryBadge (CVA),
  Layout shell with backend API status indicator in the footer
- Typed API client (fetch wrapper, ApiError, endpoint helpers) with
  types matching the backend models; sample-data fallback until the
  backend article endpoints exist
- Tailwind CSS global/component styles, cn() helper (clsx + tailwind-merge)
- Unit tests: Vitest + React Testing Library (23 tests, 100% statement
  coverage on components)
- E2E tests: Playwright (9 tests) covering page shell, feed rendering,
  client-side navigation, article route and API interactions
- ESLint (react + react-hooks + typescript) configured and passing
- Multi-stage Dockerfile (Vite build -> Nginx) with SPA fallback and an
  /api/ proxy to the backend service; docker-compose frontend service on
  port 3000 in both frontend/ and the root docker-compose.yml
- README with setup, API documentation, testing and Docker instructions
This commit is contained in:
Daniel Samson committed 2026-10-30 14:10:29 +00:00
1 parent cbeac5e16b
commit ffe19272b3
45 files changed
+9843 -4

No files matched your search

+72
View File
@@ -0,0 +1,72 @@
import { getHealth } from '../../api/client';
import { cn } from '../../lib/utils';
import type { ReactNode } from 'react';
import { useEffect, useState } from 'react';
import { Header } from './Header';
export interface LayoutProps {
children: ReactNode;
className?: string;
}
type ApiStatus = 'checking' | 'online' | 'offline';
const STATUS_STYLES: Record<ApiStatus, string> = {
checking: 'bg-amber-400',
online: 'bg-green-500',
offline: 'bg-red-500',
};
/**
* Application shell: sticky header, routed page content, and a footer with a
* backend API status indicator (fetched from `GET /api/v1/health` on mount).
*/
export function Layout({ children, className }: LayoutProps) {
const [apiStatus, setApiStatus] = useState<ApiStatus>('checking');
useEffect(() => {
let active = true;
getHealth()
.then(() => {
if (active) setApiStatus('online');
})
.catch(() => {
if (active) setApiStatus('offline');
});
return () => {
active = false;
};
}, []);
return (
<div className={cn('flex min-h-screen flex-col', className)}>
<Header />
<main id="main-content" className="flex-1">
{children}
</main>
<footer className="border-t border-slate-200 bg-white">
<div className="mx-auto flex max-w-6xl flex-col items-center justify-between gap-2 px-4 py-6 text-sm text-slate-500 sm:flex-row sm:px-6">
<p>
&copy; {new Date().getFullYear()} newzy — your news, curated.
</p>
<p
data-testid="api-status"
aria-live="polite"
className="flex items-center gap-2"
title="newzy backend API status"
>
<span
aria-hidden="true"
className={cn('h-2.5 w-2.5 rounded-full', STATUS_STYLES[apiStatus])}
/>
API: {apiStatus}
</p>
</div>
</footer>
</div>
);
}
export default Layout;