SPB Git

Repository Public

page.tsx 4.6 KB 51 lines tsx

1"use client";2import { useEffect, useState } from "react";3import Link from "next/link";4import { ChevronRight, KeyRound, ListVideo, LogOut, ShieldCheck, Sliders } from "lucide-react";5import { api, cn, useApi } from "@/lib/client";6import { PageHeader, btnCls, inputCls } from "@/components/ui";78const card = "rounded-2xl bg-panel p-5 ring-1 ring-line";910export default function SettingsPage() {11  const { data, reload } = useApi<{ settings: Record<string, string> }>("/admin/overview");12  const sec = useApi<{ username: string; passkeys: unknown[]; sessions: unknown[] }>("/auth/security");13  const [v, setV] = useState<Record<string, string>>({}); const [msg, setMsg] = useState<string | null>(null);14  useEffect(() => { if (data) setV(data.settings); }, [data]);15  const save = async (patch: Record<string, string>) => { setV((p) => ({ ...p, ...patch })); setMsg(null); try { await api("/admin/settings", { method: "PUT", body: patch }); setMsg("Enregistré."); reload(); } catch (e) { setMsg((e as Error).message); } };16  const toggle = (key: string, label: string, help: string) => (17    <label className="flex items-start justify-between gap-4 py-3 text-sm"><span><span className="font-medium">{label}</span><span className="block text-xs text-dim">{help}</span></span>18      <input type="checkbox" className="mt-0.5 h-6 w-6 shrink-0 accent-white" checked={v[key] === "1"} onChange={(e) => save({ [key]: e.target.checked ? "1" : "0" })} /></label>19  );20  const link = (href: string, Icon: typeof Sliders, label: string, sub: string) => (21    <Link href={href} data-nav className="flex items-center gap-4 rounded-2xl bg-panel p-4 ring-1 ring-line hover:bg-raised"><Icon className="h-6 w-6 shrink-0 text-accent2" /><span className="min-w-0 flex-1"><span className="block font-medium">{label}</span><span className="block truncate text-xs text-dim">{sub}</span></span><ChevronRight className="h-5 w-5 text-faint" /></Link>22  );23  return (24    <div className="pb-8">25      <PageHeader title="Paramètres" sub="Préférences de lecture et accès à votre compte." />26      <div className="mx-auto max-w-3xl space-y-5 px-4 lg:mx-0 lg:px-8">27        <section className={cn(card, "divide-y divide-line")}>28          <h2 className="pb-2 text-base font-semibold">Lecture</h2>29          {toggle("auto_resume", "Reprendre la dernière chaîne à l'ouverture", "Dans le mini-lecteur, une fois par session.")}30          {toggle("check_enabled", "Surveiller la disponibilité des flux", "Tests en arrière-plan, sans jamais télécharger la vidéo.")}31          {toggle("premium_filter", "Écarter les chaînes payantes présumées", "Les entrées au nom d'une marque à abonnement ne sont pas importées des listes publiques.")}32        </section>33        <section className={card}>34          <h2 className="text-base font-semibold">Guide TV</h2>35          <label className="mt-3 block text-sm font-medium">Pays dont les chaînes reçoivent un guide<input value={v.epg_countries ?? ""} onChange={(e) => setV({ ...v, epg_countries: e.target.value })} onBlur={(e) => save({ epg_countries: e.target.value })} placeholder="CA,FR" className={cn(inputCls, "mt-1 max-w-xs")} /></label>36          <p className="mt-1 text-xs text-dim">Codes ISO séparés par des virgules. Vos favoris sont toujours inclus.</p>37        </section>38        {msg && <p role="status" className="rounded-xl bg-up/10 px-3 py-2 text-sm text-up">{msg}</p>}39        <div className="grid gap-3 sm:grid-cols-2">40          {link("/playlists", ListVideo, "Playlists M3U", "Vos chaînes sur les téléviseurs de la maison")}41          {link("/admin", ShieldCheck, "Sécurité", sec.data ? `${sec.data.passkeys.length} clé${sec.data.passkeys.length > 1 ? "s" : ""} d'accès · ${sec.data.sessions.length} session${sec.data.sessions.length > 1 ? "s" : ""}` : "Mot de passe, clés d'accès, sessions")}42          {link("/admin", Sliders, "Administration", "Sources, synchronisation, bibliothèque, journaux")}43          {link("/favoris", KeyRound, "Favoris et listes", "Chaînes, films et séries enregistrés")}44        </div>45        <p className="text-xs leading-relaxed text-faint">Métadonnées : Wikidata, Wikipédia, Wikimedia Commons, ONF, ARTE, NASA, et <a className="underline" href="https://www.themoviedb.org/" target="_blank" rel="noreferrer">TMDB</a> pour certaines affiches et certains synopsis. This product uses the TMDB API but is not endorsed or certified by TMDB.</p>46        <button onClick={async () => { await api("/auth/logout", { method: "POST" }).catch(() => {}); location.href = "/connexion"; }} className={cn(btnCls, "bg-white/10 hover:bg-white/15")}><LogOut className="h-4 w-4" />Se déconnecter{sec.data ? ` (${sec.data.username})` : ""}</button>47      </div>48    </div>49  );50}51
Files main
Menu

Theme