import { TextInput, Text, Popover, Kbd, Group } from '@mantine/core'; import { useForm, useHotkeys } from '@mantine/hooks'; import { useRef, 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 queryUrl = config.settings.searchUrl || 'https://www.google.com/search?q='; const textInput: any = useRef(null); useHotkeys([['ctrl+K', () => textInput.current.focus()]]); const rightSection = (
Ctrl + K
); const form = useForm({ initialValues: { query: '', }, }); if (config.settings.searchBar === false) { return null; } return (
{ // If query contains !yt or !t add "Searching on YouTube" or "Searching torrent" const query = form.values.query.trim(); const isYoutube = query.startsWith('!yt'); const isTorrent = query.startsWith('!t'); if (isYoutube) { setIcon(); } else if (isTorrent) { setIcon(); } else { setIcon(); } }} onSubmit={form.onSubmit((values) => { // Find if query is prefixed by !yt or !t const query = values.query.trim(); const isYoutube = query.startsWith('!yt'); const isTorrent = query.startsWith('!t'); if (isYoutube) { window.open(`https://www.youtube.com/results?search_query=${query.substring(3)}`); } else if (isTorrent) { window.open(`https://bitsearch.to/search?q=${query.substring(3)}`); } else { window.open(`${queryUrl}${values.query}`); } })} > setOpened(true)} onBlurCapture={() => setOpened(false)} target={ } > tip: Use the prefixes !yt and !t in front of your query to search on YouTube or for a Torrent respectively. ); }