@@ -6,94 +6,99 @@ import {
66 InputLeftAddon ,
77 InputRightElement ,
88 HStack ,
9- Select
9+ Select ,
1010} from '@chakra-ui/react' ;
11- import { useCallback , useContext , useEffect , useState } from 'react' ;
11+ import { useCallback , useContext , useEffect , useState } from 'react' ;
1212import { SearchContext } from 'renderer/context/SearchContext' ;
13- import { FcGoogle } from 'react-icons/fc' ;
14- import { SiDuckduckgo } from 'react-icons/si' ;
15- import { FaYandexInternational } from 'react-icons/fa' ;
13+ import { FcGoogle } from 'react-icons/fc' ;
14+ import { SiDuckduckgo } from 'react-icons/si' ;
15+ import { FaYandexInternational } from 'react-icons/fa' ;
1616import '../App.css' ;
17+ import { TabContext } from 'renderer/context/TabContext' ;
1718import SearchEngineModal from './Settings/SearchEngineModal' ;
1819
1920const Searchbar = ( { } ) => {
20-
2121 const [ isModalOpen , setModal ] = useState ( false ) ;
2222
2323 const onClose = ( ) => setModal ( ! isModalOpen ) ;
2424
25- const {
26- url,
27- setUrl,
28- keyword,
29- setKeyword,
30- onChange,
31- search,
32- searchEngine
33- } = useContext ( SearchContext ) ;
25+ const { url, setUrl, keyword, setKeyword, tabs, closeTab, onChange, search, searchEngine } =
26+ useContext ( SearchContext ) ;
3427
28+ const { nexTab, setTabIndex, currentTabIndex } = useContext ( TabContext ) ;
3529
36- const handleSetSearchEngineShortcut = useCallback ( ( event ) => {
37- if ( event . ctrlKey && ( event . key === 'E' || event . key === 'e' ) ) {
30+ const handleSetSearchEngineShortcut = useCallback ( ( event ) => {
31+ if ( event . ctrlKey && ( event . key === 'E' || event . key === 'e' ) ) {
3832 onClose ( ) ;
3933 }
40- } )
34+ nexTab ( event ) ;
35+ } ) ;
4136
42- useEffect ( ( ) => {
43- document . addEventListener ( 'keydown' , handleSetSearchEngineShortcut ) ;
37+ useEffect ( ( ) => {
38+ document . addEventListener ( 'keydown' , handleSetSearchEngineShortcut ) ;
4439
4540 return ( ) => {
46- document . removeEventListener ( 'keydown' , handleSetSearchEngineShortcut ) ;
47- }
48- } , [ ] )
41+ document . removeEventListener ( 'keydown' , handleSetSearchEngineShortcut ) ;
42+ } ;
43+ } , [ ] ) ;
4944
5045 const getEngineIcon = ( ) => {
51- switch ( searchEngine ) {
52- case " https://www.google.com/search?q=" :
53- return < FcGoogle />
54- case " https://yandex.com.tr/search/?text=" :
55- return < FaYandexInternational />
56- case " https://duckduckgo.com/?q=" :
57- return < SiDuckduckgo />
58- }
59- }
46+ switch ( searchEngine ) {
47+ case ' https://www.google.com/search?q=' :
48+ return < FcGoogle /> ;
49+ case ' https://yandex.com.tr/search/?text=' :
50+ return < FaYandexInternational /> ;
51+ case ' https://duckduckgo.com/?q=' :
52+ return < SiDuckduckgo /> ;
53+ }
54+ } ;
6055
6156 return (
6257 < >
63- < HStack w = '95vw' >
64- < InputGroup size = 'md' h = '40px' id = 'search-bar-container'
65- >
66- < InputLeftAddon h = '40px' children = { getEngineIcon ( ) } color = 'white' backgroundColor = '#32363e' border = 'none' onClick = { onClose } />
67- < Input variant = 'filled' placeholder = 'Search' autoFocus
68- onKeyDown = { e => e . key === 'Enter' && search ( ) }
58+ < HStack w = "95vw" >
59+ < InputGroup size = "md" h = "40px" id = "search-bar-container" >
60+ < InputLeftAddon
61+ h = "40px"
62+ children = { getEngineIcon ( ) }
63+ color = "white"
64+ backgroundColor = "#32363e"
65+ border = "none"
66+ onClick = { onClose }
67+ />
68+ < Input
69+ variant = "filled"
70+ placeholder = "Search"
71+ autoFocus
72+ onKeyDown = { ( e ) => e . key === 'Enter' && search ( ) }
6973 onChange = { onChange }
70- backgroundColor = ' #32363e'
71- _focus = { { backgroundColor :'#32363e' } }
72- _hover = { { backgroundColor :'#32363e' } }
73- />
74+ backgroundColor = " #32363e"
75+ _focus = { { backgroundColor : '#32363e' } }
76+ _hover = { { backgroundColor : '#32363e' } }
77+ />
7478
7579 < InputRightElement >
76- < Button h = '40px' w = '40px' size = 'sm'
80+ < Button
81+ h = "40px"
82+ w = "40px"
83+ size = "sm"
7784 leftIcon = { < SearchIcon /> }
78- backgroundColor = ' #32363e'
79- variant = ' solid'
85+ backgroundColor = " #32363e"
86+ variant = " solid"
8087 onClick = { search }
8188 _hover = { {
82- backgroundColor :'#32363e' ,
89+ backgroundColor : '#32363e' ,
8390 } }
8491 _focus = { {
85- backgroundColor :'#32363e' ,
86- outline :'none'
92+ backgroundColor : '#32363e' ,
93+ outline : 'none' ,
8794 } }
88- >
89- </ Button >
95+ />
9096 </ InputRightElement >
9197 </ InputGroup >
92-
9398 </ HStack >
9499 < SearchEngineModal isOpen = { isModalOpen } onClose = { onClose } />
95100 </ >
96101 ) ;
97- }
102+ } ;
98103
99104export default Searchbar ;
0 commit comments