import { useState } from "react"; import { useQuery } from "@tanstack/react-query"; import { X } from "lucide-react"; import { api, type FeedFilters, type Tag } from "../lib/api"; const DATE_PRESETS: { days: number; label: string }[] = [ { days: 1, label: "24h" }, { days: 7, label: "1 week" }, { days: 30, label: "1 month" }, { days: 180, label: "6 months" }, { days: 365, label: "1 year" }, ]; // Filter values owned by the sidebar (everything except the header search `q`). const DEFAULT_SIDEBAR_FILTERS: Omit = { tags: [], tagMode: "or", sort: "newest", includeNormal: true, includeShorts: false, includeLive: false, show: "unwatched", }; const SORTS = [ { id: "newest", label: "Newest" }, { id: "oldest", label: "Oldest" }, { id: "views", label: "Most viewed" }, { id: "duration_desc", label: "Longest" }, { id: "duration_asc", label: "Shortest" }, { id: "title", label: "Name (A–Z)" }, { id: "subscribers", label: "Channel subscribers" }, { id: "shuffle", label: "Surprise me" }, ]; const SHOWS = [ { id: "unwatched", label: "Unwatched" }, { id: "all", label: "All" }, { id: "watched", label: "Watched" }, { id: "saved", label: "Saved" }, { id: "hidden", label: "Hidden" }, ]; function TagChip({ tag, active, onClick, }: { tag: Tag; active: boolean; onClick: () => void; }) { return ( ); } export default function Sidebar({ filters, setFilters, }: { filters: FeedFilters; setFilters: (f: FeedFilters) => void; }) { const tagsQuery = useQuery({ queryKey: ["tags"], queryFn: api.tags }); const tags = tagsQuery.data ?? []; const languages = tags.filter((t) => t.category === "language"); const topics = tags.filter((t) => t.category === "topic"); const [customDates, setCustomDates] = useState(false); function toggleTag(id: number) { const has = filters.tags.includes(id); setFilters({ ...filters, tags: has ? filters.tags.filter((t) => t !== id) : [...filters.tags, id], }); } const dateActive = !!filters.maxAgeDays || !!filters.dateFrom || !!filters.dateTo; const contentChanged = !filters.includeNormal || filters.includeShorts || filters.includeLive; const activeCount = filters.tags.length + (filters.show !== "unwatched" ? 1 : 0) + (filters.sort !== "newest" ? 1 : 0) + (contentChanged ? 1 : 0) + (filters.channelId ? 1 : 0) + (dateActive ? 1 : 0); const active = activeCount > 0; function clearAll() { setCustomDates(false); setFilters({ ...DEFAULT_SIDEBAR_FILTERS, q: filters.q, }); } return ( ); } function Section({ title, right, children, }: { title: string; right?: React.ReactNode; children: React.ReactNode; }) { return (
{title}
{right}
{children}
); } function Toggle({ label, checked, onChange, }: { label: string; checked: boolean; onChange: (v: boolean) => void; }) { return ( ); }