import { WatchedMediaCard } from "components/media/WatchedMediaCard";
import { SearchBarInput } from "components/SearchBar";
import { MWMassProviderOutput, 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";
import { Navigation } from "components/layout/Navigation";
import { useSearchQuery } from "hooks/useSearchQuery";
import { useWatchedContext } from "state/watched/context";
import {
getIfBookmarkedFromPortable,
useBookmarkContext,
} from "state/bookmark/context";
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!
) : (
We couldn't find anything!
)}
) : null}
{/* Error result */}
{allFailed ? (
All providers have failed!
) : 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] = useSearchQuery();
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({ searchQuery: "" })}
/>
) : (
)}
>
);
}
function ExtraItems() {
const { getFilteredBookmarks } = useBookmarkContext();
const { watched } = useWatchedContext();
const bookmarks = getFilteredBookmarks();
const watchedItems = watched.items.filter(
(v) => !getIfBookmarkedFromPortable(bookmarks, v)
);
if (watchedItems.length === 0 && bookmarks.length === 0) return null;
return (
{bookmarks.length > 0 ? (
{bookmarks.map((v) => (
))}
) : null}
{watchedItems.length > 0 ? (
{watchedItems.map((v) => (
))}
) : null}
);
}