import { WatchedMediaCard } from "components/media/WatchedMediaCard"; import { SearchBarInput } from "components/SearchBar"; import { 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"; function SearchLoading() { return ; } function SearchResultsView({ searchQuery }: { searchQuery: MWQuery }) { 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.length > 0 ? ( {results.map((v) => ( ))} ) : null} {/* no results */} {success && results.length === 0 ?

No results found

: null} {/* error */} {error ?

All scrapers failed

: 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 ? ( ) : null}
); }