From 795e4efe296c9295e0869497b22beef8d4f39293 Mon Sep 17 00:00:00 2001 From: Orionis312050 Date: Sat, 10 Oct 2026 00:37:41 +0000 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Correction=20et=20Ajustement=20des?= =?UTF-8?q?=20fonctionnalit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/App.tsx | 355 ++++++++++++++++++++++++++++++++++++++++------ web/src/style.css | 195 +++++++++++++++++++++++-- 2 files changed, 488 insertions(+), 62 deletions(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 420a7ce..353f79b 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1,4 +1,4 @@ -import { FormEvent, useCallback, useEffect, useMemo, useState } from "react"; +import { FormEvent, useCallback, useEffect, useMemo, useRef, useState } from "react"; type Movie = { id: number; @@ -17,6 +17,9 @@ type Movie = { }; type RadarrSettings = { url: string | null; api_key_configured: boolean }; + +type NotificationKind = "info" | "error" | "warning"; +type Notification = { id: number; text: string; kind: NotificationKind }; type QbittorrentSettings = { url: string | null; username: string | null; @@ -119,15 +122,74 @@ export default function App() { const [confirmSingle, setConfirmSingle] = useState(null); const [confirmBulk, setConfirmBulk] = useState(false); const [deleting, setDeleting] = useState(false); - const [message, setMessage] = useState(""); - const [messageError, setMessageError] = useState(false); + const [notifications, setNotifications] = useState([]); + const notificationId = useRef(0); const [busy, setBusy] = useState(false); + const [authState, setAuthState] = useState<"checking" | "guest" | "authed">("checking"); + const [authedUser, setAuthedUser] = useState(""); + const [isSetup, setIsSetup] = useState(() => window.location.pathname === "/setup"); + const [setupToken, setSetupToken] = useState( + () => new URLSearchParams(window.location.search).get("token"), + ); + const [loginUsername, setLoginUsername] = useState(""); + const [loginPassword, setLoginPassword] = useState(""); + const [loginError, setLoginError] = useState(""); + const [setupUsername, setSetupUsername] = useState(""); + const [setupPassword, setSetupPassword] = useState(""); + const [setupConfirm, setSetupConfirm] = useState(""); + const [setupError, setSetupError] = useState(""); + const [authBusy, setAuthBusy] = useState(false); + const [theme, setTheme] = useState<"dark" | "light">( + () => (localStorage.getItem("mkvtool-theme") === "light" ? "light" : "dark"), + ); + const [menuOpen, setMenuOpen] = useState(false); + const userMenuRef = useRef(null); const loadMovies = useCallback(async () => { setMovies(await api("/api/movies")); }, []); + function notify(text: string, kind: NotificationKind = "info") { + setNotifications((current) => [ + { id: ++notificationId.current, text, kind }, + ...current, + ]); + } + + function dismissNotification(id: number) { + setNotifications((current) => current.filter((item) => item.id !== id)); + } + useEffect(() => { + document.documentElement.dataset.theme = theme; + }, [theme]); + + useEffect(() => { + if (!menuOpen) return; + function onPointerDown(event: MouseEvent) { + if (userMenuRef.current && !userMenuRef.current.contains(event.target as Node)) { + setMenuOpen(false); + } + } + document.addEventListener("mousedown", onPointerDown); + return () => document.removeEventListener("mousedown", onPointerDown); + }, [menuOpen]); + + useEffect(() => { + if (isSetup) { + setAuthState("guest"); + return; + } + api<{ username: string }>("/api/auth/me") + .then((me) => { + setAuthedUser(me.username); + setAuthState("authed"); + }) + .catch(() => setAuthState("guest")); + }, [isSetup]); + + useEffect(() => { + if (authState !== "authed") return; Promise.all([ api("/api/settings/radarr"), api("/api/settings/qbittorrent"), @@ -139,24 +201,95 @@ export default function App() { setQbitUrl(qbittorrent.url ?? ""); setQbitUsername(qbittorrent.username ?? ""); setQbitConfigured(qbittorrent.password_configured); + if (!radarr.api_key_configured || !qbittorrent.password_configured) { + notify( + "Configuration incomplète — renseignez les connexions Radarr et qBittorrent dans la page Configuration.", + "warning", + ); + } }) .catch((error: Error) => { - setMessage(error.message); - setMessageError(true); + notify(error.message, "error"); }); - }, [loadMovies]); + }, [authState, loadMovies]); useEffect(() => { + if (authState !== "authed") return; const timer = setInterval(() => { loadMovies().catch(() => undefined); }, 10_000); return () => clearInterval(timer); - }, [loadMovies]); + }, [authState, loadMovies]); + + function toggleTheme() { + setTheme((current) => { + const next = current === "dark" ? "light" : "dark"; + localStorage.setItem("mkvtool-theme", next); + return next; + }); + } + + async function handleLogin(event: FormEvent) { + event.preventDefault(); + setAuthBusy(true); + setLoginError(""); + try { + const me = await api<{ username: string }>("/api/auth/login", { + method: "POST", + headers: jsonHeaders, + body: JSON.stringify({ username: loginUsername, password: loginPassword }), + }); + setAuthedUser(me.username); + setAuthState("authed"); + setLoginPassword(""); + } catch (error) { + setLoginError((error as Error).message); + } finally { + setAuthBusy(false); + } + } + + async function handleSetup(event: FormEvent) { + event.preventDefault(); + if (setupPassword !== setupConfirm) { + setSetupError("Les mots de passe ne correspondent pas."); + return; + } + setAuthBusy(true); + setSetupError(""); + try { + const me = await api<{ username: string }>("/api/auth/setup", { + method: "POST", + headers: jsonHeaders, + body: JSON.stringify({ + token: setupToken, + username: setupUsername, + password: setupPassword, + }), + }); + setIsSetup(false); + setSetupToken(null); + window.history.replaceState(null, "", "/"); + setAuthedUser(me.username); + setAuthState("authed"); + notify("Compte créé — bienvenue sur MKVTool."); + } catch (error) { + setSetupError((error as Error).message); + } finally { + setAuthBusy(false); + } + } + + async function handleLogout() { + await api("/api/auth/logout", { method: "POST" }).catch(() => undefined); + setAuthState("guest"); + setAuthedUser(""); + setMovies([]); + } async function saveSettings(event: FormEvent) { event.preventDefault(); setBusy(true); - setMessage(""); try { const settings = await api("/api/settings/radarr", { method: "PUT", @@ -168,11 +301,9 @@ export default function App() { const result = await api<{ message: string }>("/api/settings/radarr/test", { method: "POST", }); - setMessage(result.message); - setMessageError(false); + notify(result.message); } catch (error) { - setMessage((error as Error).message); - setMessageError(true); + notify((error as Error).message, "error"); } finally { setBusy(false); } @@ -181,7 +312,6 @@ export default function App() { async function saveQbittorrent(event: FormEvent) { event.preventDefault(); setBusy(true); - setMessage(""); try { const settings = await api("/api/settings/qbittorrent", { method: "PUT", @@ -197,11 +327,9 @@ export default function App() { const result = await api<{ message: string }>("/api/settings/qbittorrent/test", { method: "POST", }); - setMessage(result.message); - setMessageError(false); + notify(result.message); } catch (error) { - setMessage((error as Error).message); - setMessageError(true); + notify((error as Error).message, "error"); } finally { setBusy(false); } @@ -209,18 +337,15 @@ export default function App() { async function scan() { setBusy(true); - setMessage(""); try { const result = await api<{ iso_files: number; scanned_movies: number }>( "/api/scans", { method: "POST" }, ); await loadMovies(); - setMessage(`${result.iso_files} ISO trouvée(s) sur ${result.scanned_movies} film(s)`); - setMessageError(false); + notify(`${result.iso_files} ISO trouvée(s) sur ${result.scanned_movies} film(s)`); } catch (error) { - setMessage((error as Error).message); - setMessageError(true); + notify((error as Error).message, "error"); } finally { setBusy(false); } @@ -271,12 +396,10 @@ export default function App() { setSelectedIds((ids) => ids.filter((id) => id !== movie.id)); setConfirmSingle(null); await loadMovies(); - setMessage(`« ${movie.title} » retiré de l'inventaire.`); - setMessageError(false); + notify(`« ${movie.title} » retiré de l'inventaire.`); } catch (error) { setConfirmSingle(null); - setMessage((error as Error).message); - setMessageError(true); + notify((error as Error).message, "error"); } finally { setDeleting(false); } @@ -293,13 +416,9 @@ export default function App() { setSelectedIds([]); const successes = selectedIds.length - failures; if (failures === 0) { - setMessage(`${successes} ligne(s) retirée(s) de l'inventaire.`); - setMessageError(false); + notify(`${successes} ligne(s) retirée(s) de l'inventaire.`); } else { - setMessage( - `${successes} supprimée(s), ${failures} en échec — une conversion est peut-être en cours.`, - ); - setMessageError(true); + notify(`${successes} supprimée(s), ${failures} en échec — une conversion est peut-être en cours.`, "error"); } setDeleting(false); } @@ -327,8 +446,7 @@ export default function App() { setModalMessage("Conversion mise en file d'attente."); setModalError(false); closeModal(); - setMessage(`Conversion de « ${movie.title} » mise en file d'attente.`); - setMessageError(false); + notify(`Conversion de « ${movie.title} » mise en file d'attente.`); } catch (error) { setModalMessage((error as Error).message); setModalError(true); @@ -343,8 +461,7 @@ export default function App() { setModalMessage(text); setModalError(true); } else { - setMessage(text); - setMessageError(true); + notify(text, "error"); } }; if (fromModal) setModalBusy(true); @@ -354,8 +471,7 @@ export default function App() { await loadMovies(); if (fromModal) { closeModal(); - setMessage(`« ${movie.title} » validé — ISO supprimée, film complètement converti.`); - setMessageError(false); + notify(`« ${movie.title} » validé — ISO supprimée, film complètement converti.`); } } catch (error) { setError((error as Error).message); @@ -372,10 +488,7 @@ export default function App() { await api(`/api/movies/${movie.id}/cancel`, { method: "POST" }); await loadMovies(); closeModal(); - setMessage( - `Conversion de « ${movie.title} » annulée — MKV et lien supprimés, film remis à « Détecté ».`, - ); - setMessageError(false); + notify(`Conversion de « ${movie.title} » annulée — MKV et lien supprimés, film remis à « Détecté ».`,); } catch (error) { setModalMessage((error as Error).message); setModalError(true); @@ -397,6 +510,126 @@ export default function App() { selected !== null && CONVERTIBLE.includes(selected.status); const resuming = selected?.status === "failed"; + const notificationStack = ( +
+ {[...notifications].reverse().map((notification) => ( +
+
+ ))} +
+ ); + + if (authState === "checking") { + return null; + } + + if (isSetup && authState !== "authed") { + return ( +
+
+

PREMIER LANCEMENT

+

Créer votre compte

+

+ Ce lien ne fonctionne qu’une seule fois. Choisissez un nom d’utilisateur + et un mot de passe (8 caractères minimum) pour administrer MKVTool. +

+ {!setupToken ? ( +

+ Jeton manquant — utilisez le lien complet affiché dans la console du serveur. +

+ ) : ( +
+ + + + +
+ )} + {setupError &&

{setupError}

} +
+ {notifications.length > 0 && notificationStack} +
+ ); + } + + if (authState === "guest") { + return ( +
+
+

MKVTOOL

+

Connexion

+

Connectez-vous pour accéder à vos conversions.

+
+ + + +
+ {loginError &&

{loginError}

} +
+ {notifications.length > 0 && notificationStack} +
+ ); + } + return (
@@ -404,9 +637,38 @@ export default function App() {

RADARR · ISO → MKV

MKVTool

- +
+ +
+ + {menuOpen && ( +
+

{authedUser}

+ + +
+ )} +
+
- {message &&

{message}

} - {page === "dashboard" && ( <>
@@ -865,6 +1125,7 @@ export default function App() { )} + {notifications.length > 0 && notificationStack}
); } diff --git a/web/src/style.css b/web/src/style.css index 521fb7f..4bf57c8 100644 --- a/web/src/style.css +++ b/web/src/style.css @@ -14,6 +14,40 @@ --text-muted: #a1a1aa; --text-faint: #71717a; --danger: #f87171; + --danger-soft: #fecaca; + --warning: #facc15; + --warning-soft: #fde68a; + --accent: #fafafa; + --on-accent: #09090b; + --border-hover: #d4d4d8; + --pill: rgba(255, 255, 255, 0.06); + --pill-hover: rgba(255, 255, 255, 0.12); + --glow: rgba(255, 255, 255, 0.03); +} + +[data-theme="light"] { + color: #18181b; + background: #fafafa; + color-scheme: light; + + --bg: #fafafa; + --surface: #ffffff; + --surface-raised: #f4f4f5; + --border: #e4e4e7; + --border-strong: #d4d4d8; + --border-hover: #a1a1aa; + --text: #18181b; + --text-muted: #52525b; + --text-faint: #71717a; + --danger: #dc2626; + --danger-soft: #b91c1c; + --warning: #ca8a04; + --warning-soft: #a16207; + --accent: #18181b; + --on-accent: #fafafa; + --pill: rgba(0, 0, 0, 0.06); + --pill-hover: rgba(0, 0, 0, 0.12); + --glow: rgba(0, 0, 0, 0.04); } * { box-sizing: border-box; } @@ -29,16 +63,16 @@ button { cursor: pointer; transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease; } -button:hover:not(:disabled) { border-color: #d4d4d8; } +button:hover:not(:disabled) { border-color: var(--border-hover); } button:disabled { cursor: not-allowed; opacity: 0.4; } button.primary { - color: #09090b; - background: #fafafa; - border-color: #fafafa; + color: var(--on-accent); + background: var(--accent); + border-color: var(--accent); font-weight: 650; } -button.primary:hover:not(:disabled) { background: #ffffff; border-color: #ffffff; } -:focus-visible { outline: 2px solid #fafafa; outline-offset: 2px; } +button.primary:hover:not(:disabled) { filter: brightness(1.08); } +:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } main { width: min(1100px, calc(100% - 2rem)); margin: 0 auto; padding: 3.5rem 0 4rem; } header, .section-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; } @@ -108,14 +142,14 @@ input { transition: border-color 0.15s ease; } input::placeholder { color: #52525b; } -input:focus { outline: none; border-color: #fafafa; } +input:focus { outline: none; border-color: var(--accent); } .hint { grid-column: 1 / -1; margin: 0.6rem 0 0; color: var(--text-faint); font-size: 0.8rem; } .message { margin: 1.25rem 0 0; padding: 0.85rem 1.1rem; border: 1px solid var(--border); - border-left: 3px solid #fafafa; + border-left: 3px solid var(--accent); border-radius: 8px; background: var(--surface); font-size: 0.92rem; @@ -199,17 +233,93 @@ input[type="checkbox"] { width: 16px; height: 16px; margin: 0; - accent-color: #fafafa; + accent-color: var(--accent); cursor: pointer; flex-shrink: 0; } article.selected { background: var(--surface-raised); - box-shadow: inset 2px 0 0 #fafafa; + box-shadow: inset 2px 0 0 var(--accent); } .modal.confirm { width: min(480px, 100%); padding: 1.6rem; } .modal.confirm h2 { font-size: 1.25rem; margin-bottom: 0.5rem; } +.notifications { + position: fixed; + right: 1.25rem; + bottom: 1.25rem; + z-index: 80; + display: flex; + flex-direction: column; + width: min(380px, calc(100vw - 2.5rem)); +} +.notification { + display: flex; + align-items: flex-start; + gap: 0.7rem; + padding: 0.85rem 0.95rem; + border: 1px solid var(--border-strong); + border-radius: 12px; + background: var(--surface); + box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--glow); + animation: rise 0.2s ease; + transition: margin 0.3s ease; +} +.notification p { + margin: 0; + font-size: 0.9rem; + font-weight: 500; + line-height: 1.45; + overflow-wrap: anywhere; +} +.notification .dot { + flex-shrink: 0; + width: 8px; + height: 8px; + margin-top: 0.35rem; + border-radius: 999px; + background: var(--accent); +} +.notification.error { color: var(--danger-soft); } +.notification.warning { color: var(--warning-soft); } +.notification.error .dot { background: var(--danger); } +.notification.warning .dot { background: var(--warning); } +/* Deck facon sonner: chaque carte est recouverte par la suivante; la plus + recente est devant, en bas, et les anciennes depassent au-dessus. */ +.notification:not(:last-child) { margin-bottom: -2.2rem; } +/* Au survol, la pile se deploie en colonne, de bas en haut. */ +.notifications:hover .notification:not(:last-child) { margin-bottom: 0.55rem; } +.notification-close { + flex-shrink: 0; + padding: 0.1rem 0.55rem; + border: 0; + border-radius: 999px; + color: var(--text-muted); + background: var(--pill); + font-size: 0.95rem; + line-height: 1.3; + cursor: pointer; +} +.notification-close:hover { color: var(--text); background: var(--pill-hover); } + +.header-actions { display: flex; align-items: center; gap: 0.6rem; } + +.auth-main { + width: min(1100px, calc(100% - 2rem)); + min-height: 100vh; + margin: 0 auto; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; +} +.auth-panel { width: min(420px, 100%); padding: 2.5rem; margin: 0; } +.auth-panel h1 { font-size: clamp(2rem, 6vw, 2.75rem); margin-bottom: 0.5rem; } +.auth-sub { color: var(--text-muted); font-size: 0.92rem; line-height: 1.5; margin-bottom: 1.5rem; } +.auth-form { grid-template-columns: 1fr; gap: 1rem; } +.auth-form button { margin-top: 0.5rem; } +.auth-main .notifications { position: fixed; } + .activity { display: grid; grid-template-columns: 1fr 1fr; @@ -261,8 +371,8 @@ article.selected { font-size: 0.9rem; font-weight: 600; } -.page-link:hover:not(.active) { color: var(--text); border-color: #d4d4d8; } -.page-link.active { color: #09090b; background: #fafafa; border-color: #fafafa; } +.page-link:hover:not(.active) { color: var(--text); border-color: var(--border-hover); } +.page-link.active { color: var(--on-accent); background: var(--accent); border-color: var(--accent); } .page-link .count { font-variant-numeric: tabular-nums; font-size: 0.78rem; opacity: 0.7; } .tabs { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; } @@ -277,7 +387,7 @@ article.selected { font-weight: 600; } .tab:hover:not(.active) { color: var(--text); } -.tab.active { color: #09090b; background: #fafafa; border-color: #fafafa; } +.tab.active { color: var(--on-accent); background: var(--accent); border-color: var(--accent); } .tab .count { font-variant-numeric: tabular-nums; font-size: 0.78rem; opacity: 0.7; } .empty.small { padding: 1.6rem 1rem; font-size: 0.88rem; border-radius: 8px; } .panel-head .eyebrow { margin-bottom: 0.3rem; } @@ -365,7 +475,7 @@ button.danger { background: transparent; } button.danger:hover:not(:disabled) { - color: #09090b; + color: var(--on-accent); background: var(--danger); border-color: var(--danger); } @@ -382,6 +492,61 @@ button.danger:hover:not(:disabled) { .modal-grid { grid-template-columns: 1fr; } header { align-items: flex-end; } article { flex-direction: column; gap: 0.75rem; } - article.selected { box-shadow: inset 2px 0 0 #fafafa; } + article.selected { box-shadow: inset 2px 0 0 var(--accent); } .bulk-bar { flex-wrap: wrap; gap: 0.75rem; } } + +.header-actions { display: flex; align-items: center; gap: 0.6rem; } +.user-menu { position: relative; } +.avatar { + width: 2.4rem; + height: 2.4rem; + padding: 0; + display: flex; + align-items: center; + justify-content: center; + border-radius: 999px; + background: var(--surface-raised); + color: var(--text); + font-weight: 700; + font-size: 0.95rem; +} +.avatar:hover:not(:disabled) { border-color: var(--border-hover); } +.user-dropdown { + position: absolute; + right: 0; + top: calc(100% + 0.5rem); + z-index: 90; + min-width: 210px; + padding: 0.5rem; + border: 1px solid var(--border-strong); + border-radius: 12px; + background: var(--surface); + box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35); + display: grid; + gap: 0.15rem; + animation: rise 0.15s ease; +} +.user-dropdown .user-name { + margin: 0 0 0.3rem; + padding: 0.45rem 0.7rem 0.55rem; + border-bottom: 1px solid var(--border); + color: var(--text-faint); + font-size: 0.8rem; + font-weight: 600; + letter-spacing: 0.03em; +} +.user-dropdown button { + padding: 0.55rem 0.7rem; + border-color: transparent; + border-radius: 8px; + background: transparent; + color: var(--text); + font-size: 0.9rem; + font-weight: 600; + text-align: left; +} +.user-dropdown button:hover:not(:disabled) { + background: var(--surface-raised); + border-color: transparent; +}