2022-03-06 13:43:32 +01:00
|
|
|
import { useState } from "react";
|
2022-12-13 23:50:13 +01:00
|
|
|
import { MWMediaType, MWQuery } from "@/providers";
|
2022-12-17 10:04:13 +01:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-02-25 21:23:16 +01:00
|
|
|
import { DropdownButton } from "./buttons/DropdownButton";
|
2023-01-07 21:36:18 +01:00
|
|
|
import { Icon, Icons } from "./Icon";
|
2022-02-25 21:23:16 +01:00
|
|
|
import { TextInputControl } from "./text-inputs/TextInputControl";
|
2022-02-07 23:22:35 +01:00
|
|
|
|
2022-02-13 19:29:25 +01:00
|
|
|
export interface SearchBarProps {
|
2022-02-07 23:22:35 +01:00
|
|
|
buttonText?: string;
|
2022-02-10 23:45:17 +01:00
|
|
|
placeholder?: string;
|
2022-05-03 20:58:34 +02:00
|
|
|
onChange: (value: MWQuery, force: boolean) => void;
|
|
|
|
onUnFocus: () => void;
|
2022-02-13 19:29:25 +01:00
|
|
|
value: MWQuery;
|
2022-02-07 23:22:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function SearchBarInput(props: SearchBarProps) {
|
2022-12-17 10:04:13 +01:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
2022-02-13 18:49:03 +01:00
|
|
|
const [dropdownOpen, setDropdownOpen] = useState(false);
|
2022-02-13 19:29:25 +01:00
|
|
|
function setSearch(value: string) {
|
2022-05-03 20:58:34 +02:00
|
|
|
props.onChange(
|
|
|
|
{
|
|
|
|
...props.value,
|
|
|
|
searchQuery: value,
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
2022-02-13 19:29:25 +01:00
|
|
|
}
|
|
|
|
function setType(type: string) {
|
2022-05-03 20:58:34 +02:00
|
|
|
props.onChange(
|
|
|
|
{
|
|
|
|
...props.value,
|
|
|
|
type: type as MWMediaType,
|
|
|
|
},
|
|
|
|
true
|
|
|
|
);
|
2022-02-13 19:29:25 +01:00
|
|
|
}
|
2022-02-13 18:49:03 +01:00
|
|
|
|
2022-02-07 23:22:35 +01:00
|
|
|
return (
|
2023-01-07 23:44:46 +01:00
|
|
|
<div className="relative flex flex-col rounded-[28px] bg-denim-400 transition-colors focus-within:bg-denim-400 hover:bg-denim-500 sm:flex-row sm:items-center">
|
2023-01-07 21:36:18 +01:00
|
|
|
<div className="pointer-events-none absolute left-5 top-0 bottom-0 flex max-h-14 items-center">
|
|
|
|
<Icon icon={Icons.SEARCH} />
|
|
|
|
</div>
|
|
|
|
|
2022-02-10 23:45:17 +01:00
|
|
|
<TextInputControl
|
2022-05-03 20:58:34 +02:00
|
|
|
onUnFocus={props.onUnFocus}
|
2022-03-06 14:41:51 +01:00
|
|
|
onChange={(val) => setSearch(val)}
|
2022-02-13 19:29:25 +01:00
|
|
|
value={props.value.searchQuery}
|
2023-01-07 21:36:18 +01:00
|
|
|
className="w-full flex-1 bg-transparent px-4 py-4 pl-12 text-white placeholder-denim-700 focus:outline-none sm:py-4 sm:pr-2"
|
2022-02-10 23:45:17 +01:00
|
|
|
placeholder={props.placeholder}
|
|
|
|
/>
|
2022-02-13 18:49:03 +01:00
|
|
|
|
2023-01-07 21:36:18 +01:00
|
|
|
<div className="px-4 py-4 pt-0 sm:py-2 sm:px-2">
|
|
|
|
<DropdownButton
|
|
|
|
icon={Icons.SEARCH}
|
|
|
|
open={dropdownOpen}
|
|
|
|
setOpen={(val) => setDropdownOpen(val)}
|
|
|
|
selectedItem={props.value.type}
|
|
|
|
setSelectedItem={(val) => setType(val)}
|
|
|
|
options={[
|
|
|
|
{
|
|
|
|
id: MWMediaType.MOVIE,
|
|
|
|
name: t("searchBar.movie"),
|
|
|
|
icon: Icons.FILM,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: MWMediaType.SERIES,
|
|
|
|
name: t("searchBar.series"),
|
|
|
|
icon: Icons.CLAPPER_BOARD,
|
|
|
|
},
|
|
|
|
// {
|
|
|
|
// id: MWMediaType.ANIME,
|
|
|
|
// name: "Anime",
|
|
|
|
// icon: Icons.DRAGON,
|
|
|
|
// },
|
|
|
|
]}
|
|
|
|
onClick={() => setDropdownOpen((old) => !old)}
|
|
|
|
>
|
|
|
|
{props.buttonText || t("searchBar.search")}
|
|
|
|
</DropdownButton>
|
|
|
|
</div>
|
2022-02-07 23:22:35 +01:00
|
|
|
</div>
|
2022-02-10 23:45:17 +01:00
|
|
|
);
|
2022-02-07 23:22:35 +01:00
|
|
|
}
|