From 8d7c03eaf95e2e8b063c7aad650f95ed8e2c328b Mon Sep 17 00:00:00 2001 From: "Thomas \"ajnart\" Camlong" Date: Thu, 28 Apr 2022 15:05:42 +0200 Subject: [PATCH] Update search bar --- components/SearchBar/SearchBar.tsx | 37 +++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/components/SearchBar/SearchBar.tsx b/components/SearchBar/SearchBar.tsx index 1ae6444cf..723d457b8 100644 --- a/components/SearchBar/SearchBar.tsx +++ b/components/SearchBar/SearchBar.tsx @@ -2,10 +2,11 @@ import { Input, TextInput, Text, ActionIcon, useMantineTheme, Center } from '@ma import { useForm } from '@mantine/hooks'; import { showNotification } from '@mantine/notifications'; import { useState, useEffect } from 'react'; -import { Search, ArrowRight, ArrowLeft } from 'tabler-icons-react'; +import { Search, ArrowRight, ArrowLeft, BrandYoutube, Download } from 'tabler-icons-react'; import { Config, loadConfig } from '../../tools/config'; export default function SearchBar(props: any) { + const [icon, setIcon] = useState(); const theme = useMantineTheme(); const [config, setConfig] = useState({ searchBar: true, @@ -37,10 +38,40 @@ export default function SearchBar(props: any) { } return ( -
window.open(`${querryUrl}${values.querry}`))}> + { + // 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}`); + } + })} + > } - radius="xl" + radius="md" + rightSection={icon} size="md" placeholder="Search the web" {...props}