SPB Git

Repository Public

page.tsx 4.9 KB 59 lines tsx

1"use client";2import { useEffect } from "react";3import Link from "next/link";4import { Play } from "lucide-react";5import { countryName, currentProg, flag, hm, useApi, useNow, type Channel, type Prog, type Title, type TitleFull } from "@/lib/client";6import { usePlayer } from "@/components/player";7import { Empty, Logo, Row, StatusBadge, TitleRow } from "@/components/ui";8import { Banner } from "@/components/vod-section";9import { useVod } from "@/components/vod-player";1011interface TRow { key: string; title: string; items: Title[]; href: string | null }12interface Home { titleRows: TRow[]; featured: TitleFull[]; last: Channel | null; rows: { key: string; title: string; items: Channel[]; href: string | null }[]; programmes: Record<string, Prog[]>; autoResume: boolean; synced: boolean; lastSyncAt: number | null }1314export default function HomePage() {15  const { data, error, loading, reload } = useApi<Home>("/home");16  const { play, channel: playing, favVersion } = usePlayer();17  const { version } = useVod();18  useEffect(() => { if (version) reload(); }, [version, reload]);19  const t = useNow();20  useEffect(() => { if (favVersion) reload(); }, [favVersion, reload]);21  // Resume the last channel once per browser session, in the mini player (the browser may require a tap for sound).22  useEffect(() => {23    if (!data?.last || !data.autoResume || playing || sessionStorage.getItem("sptv:resumed")) return;24    sessionStorage.setItem("sptv:resumed", "1");25    play(data.last, data.rows.find((r) => r.key === "continue")?.items, "mini");26  }, [data]); // eslint-disable-line react-hooks/exhaustive-deps2728  if (loading && !data) return <div className="space-y-8 p-4 lg:p-8"><div className="skeleton h-56 rounded-3xl" />{[0, 1, 2].map((i) => <div key={i} className="skeleton h-40 rounded-2xl" />)}</div>;29  if (error && !data) return <Empty title="Impossible de charger l'accueil">{error}</Empty>;30  if (!data) return null;31  if (!data.synced) return <Empty title="Le catalogue n'est pas encore importé">La première synchronisation IPTV-org est lancée par le worker au démarrage. Suivez-la ou relancez-la dans <Link className="underline" href="/admin">Admin</Link>.</Empty>;3233  const hero = playing ?? data.last;34  const { now, next } = currentProg(hero ? data.programmes[hero.id] : undefined, t);35  const tr = (k: string) => data.titleRows.find((r) => r.key === k);36  const row = (k: string) => { const r = data.rows.find((x) => x.key === k); return r ? <Row key={k} title={r.title} items={r.items} href={r.href} programmes={data.programmes} /> : null; };37  const trow = (k: string, wide = false) => { const r = tr(k); return r ? <TitleRow key={k} title={r.title} items={r.items} href={r.href} wide={wide} /> : null; };38  return (39    <div className="space-y-6 pb-6 lg:space-y-8">40      {data.featured[0] && <Banner title={data.featured[0]} eyebrow="À l'affiche aujourd'hui" />}41      {hero && (42        <section className="px-4 lg:px-8">43          <div className="surface flex items-center gap-4 rounded-[1.4rem] p-3.5 sm:p-5">44            <Logo channel={hero} className="aspect-video w-[6.5rem] shrink-0 rounded-xl ring-1 ring-white/10 [container-type:size] sm:w-44 sm:rounded-2xl" />45            <div className="min-w-0 flex-1">46              <p className="eyebrow flex items-center gap-2">{playing ? <><span className="live-dot" />En direct maintenant</> : "Reprendre la télévision"}</p>47              <h2 className="mt-0.5 truncate text-lg font-semibold sm:text-2xl">{hero.name}</h2>48              <p className="truncate text-[13px] text-dim sm:text-sm">{now ? <>{hm(now.start)} – {hm(now.stop)} · <span className="text-ink">{now.title}</span>{next ? ` · ensuite ${next.title}` : ""}</> : <>{flag(hero.country)} {countryName(hero.country)} · Programme indisponible</>}</p>49              <div className="mt-2.5 flex flex-wrap items-center gap-2"><button data-nav autoFocus={!data.featured[0]} onClick={() => play(hero, data.rows.find((r) => r.key === "continue")?.items)} className="grad inline-flex h-10 items-center gap-2 rounded-full px-5 text-sm font-semibold"><Play className="h-4 w-4 fill-current" />Regarder</button><span className="hidden sm:inline-flex"><StatusBadge status={hero.status} /></span></div>50            </div>51          </div>52        </section>53      )}54      {!hero && !data.featured[0] && <section className="px-4 pt-6 lg:px-8"><h1 className="text-3xl font-bold tracking-tight">Bienvenue sur SP TV</h1><p className="mt-2 max-w-xl text-sm text-dim">Chaînes en direct, films et séries libres, et votre bibliothèque.</p><Link data-nav href="/chaines" className="grad mt-5 inline-flex h-12 items-center rounded-full px-7 text-base font-semibold">Parcourir les chaînes</Link></section>}55      {trow("t-continue", true)}{row("continue")}{row("favorites")}{trow("t-list")}{row("ca")}{trow("t-films")}{row("fr")}{trow("t-series")}{row("news")}{trow("t-fr")}{row("sports")}{trow("t-docs")}{row("entertainment")}{trow("t-library")}{row("music")}{row("recent")}56    </div>57  );58}59
Files main
Menu

Theme