import { TextInput, Text, Popover, Box } from '@mantine/core'; import { useForm } from '@mantine/hooks'; import { useState } from 'react'; import { Search, BrandYoutube, Download } from 'tabler-icons-react'; import { useConfig } from '../../tools/state'; export default function SearchBar(props: any) { const { config, setConfig } = useConfig(); const [opened, setOpened] = useState(false); const [icon, setIcon] = useState(); const querryUrl = config.settings.searchUrl || 'https://www.google.com/search?q='; const form = useForm({ initialValues: { querry: '', }, }); if (config.settings.searchBar === false) { return null; } return (
{ // If querry contains !yt or !t add "Searching on YouTube" or "Searching torrent" const querry = form.values.querry.trim(); const isYoutube = querry.startsWith('!yt'); const isTorrent = querry.startsWith('!t'); if (isYoutube) { setIcon(); } else if (isTorrent) { setIcon(); } else { setIcon(); } }} onSubmit={form.onSubmit((values) => { // Find if querry is prefixed by !yt or !t const querry = values.querry.trim(); const isYoutube = querry.startsWith('!yt'); const isTorrent = querry.startsWith('!t'); if (isYoutube) { window.open(`https://www.youtube.com/results?search_query=${querry.substring(3)}`); } else if (isTorrent) { window.open(`https://thepiratebay.org/search.php?q=${querry.substring(3)}`); } else { window.open(`${querryUrl}${values.querry}`); } })} > setOpened(true)} onBlurCapture={() => setOpened(false)} target={ } > tip: You can prefix your querry with !yt or !t to research on youtube or for a torrent
); }