import { WatchedMediaCard } from "components/media/WatchedMediaCard"; import { SearchBarInput } from "components/SearchBar"; import { MWMassProviderOutput, MWMedia, MWMediaType, MWQuery, SearchProviders, } from "providers"; import { useEffect, useState } from "react"; import { ThinContainer } from "components/layout/ThinContainer"; import { SectionHeading } from "components/layout/SectionHeading"; import { Icons } from "components/Icon"; import { Loading } from "components/layout/Loading"; import { Tagline } from "components/Text/Tagline"; import { Title } from "components/Text/Title"; import { useDebounce } from "hooks/useDebounce"; import { useLoading } from "hooks/useLoading"; import { IconPatch } from "components/Buttons/IconPatch"; function SearchLoading() { return ; } function SearchSuffix(props: { fails: number; total: number; resultsSize: number; }) { const allFailed: boolean = props.fails === props.total; const icon: Icons = allFailed ? Icons.WARNING : Icons.EYE_SLASH; return (
{/* standard suffix */} {!allFailed ? (
{props.fails > 0 ? (

{props.fails}/{props.total} providers failed

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

That's all we have — sorry

) : (

We couldn't find anything — sorry

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

All providers failed — whoops

) : null}
); } function SearchResultsView({ searchQuery, clear, }: { searchQuery: MWQuery; clear: () => void; }) { const [results, setResults] = useState(); const [runSearchQuery, loading, error, success] = useLoading( (query: MWQuery) => SearchProviders(query) ); useEffect(() => { if (searchQuery.searchQuery !== "") runSearch(searchQuery); }, [searchQuery]); async function runSearch(query: MWQuery) { const results = await runSearchQuery(query); if (!results) return; setResults(results); } return (
{/* results */} {success && results?.results.length ? ( clear()} > {results.results.map((v) => ( ))} ) : null} {/* search suffix */} {success && results ? ( ) : null} {/* error */} {error ? : null} {/* Loading icon */} {loading ? : null}
); } export function SearchView() { const [searching, setSearching] = useState(false); const [loading, setLoading] = useState(false); const [search, setSearch] = useState({ searchQuery: "", type: MWMediaType.MOVIE, }); const debouncedSearch = useDebounce(search, 2000); useEffect(() => { setSearching(search.searchQuery !== ""); setLoading(search.searchQuery !== ""); }, [search]); useEffect(() => { setLoading(false); }, [debouncedSearch]); return ( {/* input section */}
Because watching legally is boring What movie do you want to watch?
{/* results view */} {loading ? ( ) : searching ? ( setSearch((v) => ({ searchQuery: "", type: v.type }))} /> ) : null}
); }