"use client"; import { useState } from "react"; import { triggerRefresh } from "@/lib/api"; interface Props { lastUpdated: string | null; videoCount: number; onSearch: (q: string) => void; dark: boolean; onToggleDark: () => void; } export default function TopBar({ lastUpdated, videoCount, onSearch, dark, onToggleDark }: Props) { const [refreshing, setRefreshing] = useState(false); const [inputValue, setInputValue] = useState(""); const commitSearch = () => onSearch(inputValue); const handleRefresh = async () => { commitSearch(); setRefreshing(true); try { await triggerRefresh(); setTimeout(() => window.location.reload(), 3000); } catch { // silently fail } finally { setTimeout(() => setRefreshing(false), 3000); } }; return (
🔍 setInputValue(e.target.value)} onKeyDown={(e) => e.key === "Enter" && commitSearch()} />
{lastUpdated && (

{videoCount} vidéos · mis à jour {new Intl.RelativeTimeFormat("fr", { numeric: "auto" }).format( -Math.round((Date.now() - new Date(lastUpdated).getTime()) / 3600000), "hours" )}

)}
); }