import { useEffect, useState } from "react"; import { MagnifyingGlass, CircleNotch } from "@phosphor-icons/react"; import { gql, thumbUrl } from "../../lib/client"; import { GET_SOURCES } from "../../lib/queries"; import { useStore } from "../../store"; import type { Source } from "../../lib/types"; import s from "./SourceList.module.css"; export default function SourceList() { const [sources, setSources] = useState([]); const [loading, setLoading] = useState(true); const [lang, setLang] = useState("all"); const [search, setSearch] = useState(""); const setActiveSource = useStore((state) => state.setActiveSource); useEffect(() => { gql<{ sources: { nodes: Source[] } }>(GET_SOURCES) .then((d) => setSources(d.sources.nodes)) .catch(console.error) .finally(() => setLoading(false)); }, []); const langs = ["all", ...Array.from(new Set(sources.map((s) => s.lang))).sort()]; const filtered = sources.filter((src) => { if (src.id === "0") return false; // hide local source const matchLang = lang === "all" || src.lang === lang; const matchSearch = src.name.toLowerCase().includes(search.toLowerCase()) || src.displayName.toLowerCase().includes(search.toLowerCase()); return matchLang && matchSearch; }); return (

Sources

setSearch(e.target.value)} />
{langs.map((l) => ( ))}
{loading ? (
) : filtered.length === 0 ? (
No sources found.
) : (
{filtered.map((src) => ( ))}
)}
); }