import { IconPatch } from "@/components/buttons/IconPatch"; import { Icons } from "@/components/Icon"; import { SectionHeading } from "@/components/layout/SectionHeading"; import { MediaGrid } from "@/components/media/MediaGrid"; import { WatchedMediaCard } from "@/components/media/WatchedMediaCard"; import { useLoading } from "@/hooks/useLoading"; import { MWMassProviderOutput, MWQuery, SearchProviders } from "@/providers"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { SearchLoadingView } from "./SearchLoadingView"; function SearchSuffix(props: { fails: number; total: number; resultsSize: number; }) { const { t } = useTranslation(); const allFailed: boolean = props.fails === props.total; const icon: Icons = allFailed ? Icons.WARNING : Icons.EYE_SLASH; return (
{/* standard suffix */} {!allFailed ? (
{props.fails > 0 ? (

{t("search.providersFailed", { fails: props.fails, total: props.total, })}

) : null} {props.resultsSize > 0 ? (

{t("search.allResults")}

) : (

{t("search.noResults")}

)}
) : null} {/* Error result */} {allFailed ? (

{t("search.allFailed")}

) : null}
); } export function SearchResultsView({ searchQuery }: { searchQuery: MWQuery }) { const { t } = useTranslation(); const [results, setResults] = useState(); const [runSearchQuery, loading, error] = useLoading((query: MWQuery) => SearchProviders(query) ); useEffect(() => { async function runSearch(query: MWQuery) { const searchResults = await runSearchQuery(query); if (!searchResults) return; setResults(searchResults); } if (searchQuery.searchQuery !== "") runSearch(searchQuery); }, [searchQuery, runSearchQuery]); if (loading) return ; if (error) return ; if (!results) return null; return (
{results?.results.length > 0 ? ( {results.results.map((v) => ( ))} ) : null}
); }