import { useEffect } from "react"; import { useTranslation } from "react-i18next"; import { useQuery } from "@tanstack/react-query"; import { ChevronRight, Film, SlidersHorizontal, Tv2 } from "lucide-react"; import { api } from "../lib/api"; // The Plex module's left filter column (mirrors the feed Sidebar's shell): pick a library, filter // by watch state (movie libraries only), and sort. State is owned by App (per-account persisted). type Props = { library: string; setLibrary: (v: string) => void; show: string; setShow: (v: string) => void; sort: string; setSort: (v: string) => void; collapsed: boolean; onToggleCollapse: () => void; }; const SHOW_OPTS = ["all", "unwatched", "in_progress", "watched"] as const; const SORT_OPTS = ["added", "title"] as const; export default function PlexSidebar({ library, setLibrary, show, setShow, sort, setSort, collapsed, onToggleCollapse, }: Props) { const { t } = useTranslation(); const libsQ = useQuery({ queryKey: ["plex-libraries"], queryFn: api.plexLibraries }); const libs = libsQ.data?.libraries ?? []; const activeLib = libs.find((l) => l.key === library); // Default to the first library once loaded (or if the stored one vanished). useEffect(() => { if (libs.length && !libs.some((l) => l.key === library)) setLibrary(libs[0].key); }, [libs, library, setLibrary]); const isMovieLib = activeLib?.kind === "movie"; const activeCount = (show !== "all" && isMovieLib ? 1 : 0) + (sort !== "added" ? 1 : 0); if (collapsed) { return ( ); } return ( ); }