fix(frontend): Error Boundary, HomePage error state, HLS catch — quick wins pre-Bloc-B

This commit is contained in:
2026-03-15 00:53:46 +01:00
parent f80b8cb81c
commit df8e594d57
4 changed files with 43 additions and 4 deletions

View File

@@ -0,0 +1,31 @@
import { Component, type ReactNode } from 'react';
interface Props { children: ReactNode; }
interface State { hasError: boolean; }
export default class ErrorBoundary extends Component<Props, State> {
state: State = { hasError: false };
static getDerivedStateFromError(): State {
return { hasError: true };
}
render() {
if (this.state.hasError) {
return (
<div className="flex min-h-screen items-center justify-center bg-od-bg">
<div className="rounded border border-od-crit/40 bg-od-surface p-8 text-center">
<p className="font-mono text-sm text-od-crit">Une erreur inattendue s'est produite.</p>
<button
className="mt-4 rounded border border-od-border px-4 py-2 text-xs text-od-muted hover:border-od-accent/40"
onClick={() => window.location.reload()}
>
Recharger
</button>
</div>
</div>
);
}
return this.props.children;
}
}

View File

@@ -69,7 +69,7 @@ function NativePlayer({ url }: { url: string }) {
hls = new Hls(); hls = new Hls();
hls.loadSource(url); hls.loadSource(url);
hls.attachMedia(video); hls.attachMedia(video);
}); }).catch(() => { /* HLS non disponible — dégradation silencieuse */ });
} }
return () => { hls?.destroy(); }; return () => { hls?.destroy(); };

View File

@@ -2,9 +2,12 @@ import { StrictMode } from "react";
import { createRoot } from "react-dom/client"; import { createRoot } from "react-dom/client";
import "./styles/index.css"; import "./styles/index.css";
import App from "./App"; import App from "./App";
import ErrorBoundary from "./components/ErrorBoundary";
createRoot(document.getElementById("root")!).render( createRoot(document.getElementById("root")!).render(
<StrictMode> <StrictMode>
<App /> <ErrorBoundary>
<App />
</ErrorBoundary>
</StrictMode> </StrictMode>
); );

View File

@@ -19,11 +19,12 @@ interface VideosResponse {
export default function HomePage() { export default function HomePage() {
const [videos, setVideos] = useState<Video[]>([]); const [videos, setVideos] = useState<Video[]>([]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState(false);
useEffect(() => { useEffect(() => {
apiFetch<VideosResponse>('/videos') apiFetch<VideosResponse>('/videos')
.then((res) => setVideos(res.data.videos)) .then((res) => setVideos(res.data.videos))
.catch(() => setVideos([])) .catch(() => setError(true))
.finally(() => setLoading(false)); .finally(() => setLoading(false));
}, []); }, []);
@@ -47,7 +48,11 @@ export default function HomePage() {
</div> </div>
)} )}
{!loading && ( {error && (
<p className="text-sm text-od-crit">Impossible de charger les vidéos. Réessaie plus tard.</p>
)}
{!loading && !error && (
<> <>
{free.length > 0 && ( {free.length > 0 && (
<section> <section>