import { useTranslation } from "react-i18next"; import { Search, X, Youtube } from "lucide-react"; import type { FeedFilters, Me } from "../lib/api"; import type { Page } from "../lib/urlState"; // Contextual top bar over the content column. Primary navigation, account and the per-user sync // status live in the left NavSidebar; the feed's scope toggle now lives in the filter sidebar. // The header carries just the feed search (or the current page title). export default function Header({ me, filters, setFilters, page, onYtSearch, }: { me: Me; filters: FeedFilters; setFilters: (f: FeedFilters) => void; page: Page; // Trigger a live YouTube search for the current term (hidden for the demo account, which // can't spend the shared quota). onYtSearch: (q: string) => void; }) { const { t } = useTranslation(); const canSearchYt = !me.is_demo; const trimmedQ = filters.q.trim(); return (
{page === "feed" ? (
{ const q = e.target.value; // When a search first appears, rank the feed by relevance — set atomically with // the query (race-free vs. per-keystroke updates). Only overrides the default // "newest" sort; a custom sort the user chose is left alone. Cleared in Feed. const startSearch = !filters.q.trim() && !!q.trim() && filters.sort === "newest"; setFilters({ ...filters, q, ...(startSearch ? { sort: "relevance" } : {}) }); }} onKeyDown={(e) => { // Enter runs a live YouTube search for the typed term (the box itself filters // the local catalog as you type; Enter escalates to the YouTube API). if (e.key === "Enter" && trimmedQ && canSearchYt) onYtSearch(trimmedQ); }} placeholder={t("header.searchPlaceholder")} className="w-full bg-card border border-border rounded-full pl-9 pr-9 py-2 text-sm outline-none focus:border-accent" /> {filters.q && ( )}
{trimmedQ && canSearchYt && ( )}
) : (
{page === "stats" ? t("header.usageStats") : page === "playlists" ? t("header.account.playlists") : page === "settings" ? t("settings.title") : page === "scheduler" ? t("header.scheduler") : page === "config" ? t("header.configuration") : page === "users" ? t("header.users") : page === "notifications" ? t("inbox.navLabel") : page === "messages" ? t("messages.navLabel") : t("header.channelManager")}
)}
); }