- Cover w-48 → w-40 (cohérent avec la page série) - Titre séparé, auteur + série + statut de lecture regroupés en badges - Métadonnées (format, pages, langue, ISBN, date) en ligne texte au lieu de pills (style série) - Toolbar d'actions groupée en bas (Edit, MarkRead, Convert, Delete) - Tous les boutons d'action (MarkBookRead, Convert, Delete) alignés en py-1.5 au lieu de Button size=sm (h-9) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import Link from "next/link";
|
|
import { Button } from "./ui";
|
|
import { useTranslation } from "../../lib/i18n/context";
|
|
|
|
interface ConvertButtonProps {
|
|
bookId: string;
|
|
}
|
|
|
|
type ConvertState =
|
|
| { type: "idle" }
|
|
| { type: "loading" }
|
|
| { type: "success"; jobId: string }
|
|
| { type: "error"; message: string };
|
|
|
|
export function ConvertButton({ bookId }: ConvertButtonProps) {
|
|
const { t } = useTranslation();
|
|
const [state, setState] = useState<ConvertState>({ type: "idle" });
|
|
|
|
const handleConvert = async () => {
|
|
setState({ type: "loading" });
|
|
try {
|
|
const res = await fetch(`/api/books/${bookId}/convert`, { method: "POST" });
|
|
if (!res.ok) {
|
|
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
setState({ type: "error", message: body.error || t("convert.failed") });
|
|
return;
|
|
}
|
|
const job = await res.json();
|
|
setState({ type: "success", jobId: job.id });
|
|
} catch (err) {
|
|
setState({ type: "error", message: err instanceof Error ? err.message : t("convert.unknownError") });
|
|
}
|
|
};
|
|
|
|
if (state.type === "success") {
|
|
return (
|
|
<div className="flex items-center gap-2 text-sm text-success">
|
|
<span>{t("convert.started")}</span>
|
|
<Link href={`/jobs/${state.jobId}`} className="text-primary hover:underline font-medium">
|
|
{t("convert.viewJob")}
|
|
</Link>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (state.type === "error") {
|
|
return (
|
|
<div className="flex flex-col gap-1">
|
|
<span className="text-sm text-destructive">{state.message}</span>
|
|
<button
|
|
className="text-xs text-muted-foreground hover:underline text-left"
|
|
onClick={() => setState({ type: "idle" })}
|
|
>
|
|
{t("common.close")}
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<button
|
|
type="button"
|
|
onClick={handleConvert}
|
|
disabled={state.type === "loading"}
|
|
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-border bg-card text-sm font-medium text-muted-foreground hover:text-foreground hover:border-primary transition-colors disabled:opacity-50"
|
|
>
|
|
{state.type === "loading" ? t("convert.converting") : t("convert.convertToCbz")}
|
|
</button>
|
|
);
|
|
}
|