From 0d11244506ffbfe53939944200fd2ce52c4c69a8 Mon Sep 17 00:00:00 2001 From: Aj - Thomas Date: Mon, 16 May 2022 13:50:08 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=20Rework=20the=20search=20bar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/SearchBar/SearchBar.tsx | 125 +++++++++++++------------ 1 file changed, 66 insertions(+), 59 deletions(-) diff --git a/src/components/SearchBar/SearchBar.tsx b/src/components/SearchBar/SearchBar.tsx index 6cd026784..be853e67c 100644 --- a/src/components/SearchBar/SearchBar.tsx +++ b/src/components/SearchBar/SearchBar.tsx @@ -1,6 +1,6 @@ -import { TextInput, Text, Popover, Box } from '@mantine/core'; -import { useForm } from '@mantine/hooks'; -import { useState } from 'react'; +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'; @@ -9,6 +9,16 @@ export default function SearchBar(props: any) { 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: { @@ -21,71 +31,68 @@ export default function SearchBar(props: any) { } 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}`); + } + })} > -
{ - // 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={ + 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. - - - -
+ + } + > + + tip: Use the prefixes !yt and !t in front of your query to search on YouTube + or for a Torrent respectively. + + + ); }