diff --git a/src/components/widgets/search/search.jsx b/src/components/widgets/search/search.jsx index 5ac41efd0..48ba3b2e2 100644 --- a/src/components/widgets/search/search.jsx +++ b/src/components/widgets/search/search.jsx @@ -1,72 +1,68 @@ import { useState } from "react"; import { FiSearch } from "react-icons/fi"; -import { FcGoogle } from "react-icons/fc"; -import { SiDuckduckgo } from "react-icons/si"; -import { SiMicrosoftbing } from "react-icons/si"; +import { SiDuckduckgo, SiMicrosoftbing, SiGoogle } from "react-icons/si"; -export default function Search({ options, classN }) { - const providers = ["google", "bing", "duckduckgo", "custom"]; - const targets = ["_blank", "_parent", "_top"]; +const providers = { + google: { + name: "Google", + url: "https://www.google.com/search?q=", + icon: SiGoogle, + }, + duckduckgo: { + name: "DuckDuckGo", + url: "https://duckduckgo.com/?q=", + icon: SiDuckduckgo, + }, + bing: { + name: "Bing", + url: "https://www.bing.com/search?q=", + icon: SiMicrosoftbing, + }, + custom: { + name: "Custom", + url: false, + icon: FiSearch, + }, +}; +export default function Search({ options }) { + const provider = providers[options.provider]; const [query, setQuery] = useState(""); - function search() { - if (!providers.includes(options.provider)) { - return; + if (!provider) { + return <>>; + } + + function handleSubmit(event) { + const q = encodeURIComponent(query); + + if (provider.url) { + window.open(`${provider.url}${q}`, options.target || "_blank"); } else { - if (options.provider === "custom") { - if (targets.includes(options.target)) { - window.open(options.customdata.url + query, options.target); - } else window.open(options.customdata.url + query, "_self"); - } else { - if (targets.includes(options.target)) { - window.open(`https://www.${options.provider}.com/search?q=` + query, `${options.target}`); - } else window.open(`https://www.${options.provider}.com/search?q=` + query, "_self"); - } + window.open(`${options.url}${q}`, options.target || "_blank"); } + event.preventDefault(); + event.target.reset(); setQuery(""); } - if (!options || (options.provider === "custom" && !options.customdata)) { - return <>>; - } - return ( -
);