refactor: Phase D — composant Modal réutilisable + utilitaire searchParams

- Crée Modal.tsx dans components/ui (backdrop, container, header sticky, close button)
- Remplace le scaffolding modal dupliqué dans EditBookForm, EditSeriesForm,
  DeleteBookButton, MetadataSearchModal (4 composants)
- Crée lib/searchParams.ts avec paramString, paramStringOr, paramInt, paramBool
- Simplifie le parsing des query params dans books, series, authors pages

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-29 12:23:50 +02:00
parent 13b1e1768e
commit 2670969d7e
10 changed files with 150 additions and 145 deletions

View File

@@ -0,0 +1,25 @@
type RawSearchParams = { [key: string]: string | string[] | undefined };
/** Extract a string param, returning undefined if missing or not a string. */
export function paramString(params: RawSearchParams, key: string): string | undefined {
const v = params[key];
return typeof v === "string" ? v : undefined;
}
/** Extract a string param with a default value. */
export function paramStringOr(params: RawSearchParams, key: string, defaultValue: string): string {
return paramString(params, key) ?? defaultValue;
}
/** Extract a numeric param, returning a default if missing or not parseable. */
export function paramInt(params: RawSearchParams, key: string, defaultValue: number): number {
const v = params[key];
if (typeof v !== "string") return defaultValue;
const n = parseInt(v, 10);
return Number.isNaN(n) ? defaultValue : n;
}
/** Extract a boolean param (true only if value is exactly "true"). */
export function paramBool(params: RawSearchParams, key: string): boolean {
return params[key] === "true";
}