Skip to content

Commit 79d183e

Browse files
authored
Merge pull request #7 from yessGlory17/change-search-engine
search engine settings
2 parents 96b4664 + 40791f5 commit 79d183e

File tree

4 files changed

+99
-5
lines changed

4 files changed

+99
-5
lines changed

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/components/BrowserCollapse.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ const BrowserCollapse = ({name, tabUrl, tabId}) => {
3636
webviewRef.current.canGoForward() && webviewRef.current.goForward()
3737
}
3838

39+
const refresh = (e) => {
40+
e.preventDefault();
41+
webviewRef.current.isLoading() ? webviewRef.current.stop() : webviewRef.current.reload();
42+
}
3943

4044
const getTitle = () => {
4145
if(webviewRef.current === undefined){
@@ -67,7 +71,19 @@ const BrowserCollapse = ({name, tabUrl, tabId}) => {
6771
onClick={(e)=>forward(e)}
6872
icon={<AiOutlineRight _hover={{color:'red'}} />}
6973
/>
74+
<IconButton
75+
backgroundColor="#32363e"
76+
marginRight='10px'
77+
_hover={{ bg: '#32363e' }}
78+
size='xs'
79+
onClick={(e) => refresh(e)}
80+
icon={
81+
<RepeatIcon
82+
_hover={{ color: 'yellow' }}
7083

84+
/>
85+
}
86+
/>
7187
<IconButton
7288
backgroundColor="#32363e"
7389
_hover={{ bg: '#32363e' }}

src/renderer/components/Searchbar.tsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@ import {
55
InputGroup,
66
InputLeftAddon,
77
InputRightElement,
8-
HStack
8+
HStack,
9+
Select
910
} from '@chakra-ui/react';
10-
import {useContext, useEffect,useState} from 'react';
11+
import {useCallback, useContext, useEffect,useState} from 'react';
1112
import { SearchContext } from 'renderer/context/SearchContext';
13+
import {FcGoogle} from 'react-icons/fc';
1214
import '../App.css';
15+
import SearchEngineModal from './Settings/SearchEngineModal';
16+
1317
const Searchbar = ({}) => {
1418

19+
const [isModalOpen, setModal] = useState(false);
20+
21+
const onClose = () => setModal(!isModalOpen);
22+
1523
const {
1624
url,
1725
setUrl,
@@ -21,12 +29,27 @@ const Searchbar = ({}) => {
2129
search
2230
} = useContext(SearchContext);
2331

32+
33+
const handleSetSearchEngineShortcut = useCallback((event)=>{
34+
if(event.ctrlKey && (event.key === 'E' || event.key === 'e')){
35+
onClose();
36+
}
37+
})
38+
39+
useEffect(()=>{
40+
document.addEventListener('keydown',handleSetSearchEngineShortcut);
41+
42+
return () => {
43+
document.removeEventListener('keydown',handleSetSearchEngineShortcut);
44+
}
45+
},[])
46+
2447
return (
2548
<>
2649
<HStack w='95vw' >
2750
<InputGroup size='md' h='40px' id='search-bar-container'
2851
>
29-
{/* <InputLeftAddon h='40px' children='Google' color='white' backgroundColor='teal' /> */}
52+
<InputLeftAddon h='40px' children={<FcGoogle />} color='white' backgroundColor='#32363e' border='none' onClick={onClose} />
3053
<Input variant='filled' placeholder='Search' autoFocus
3154
onKeyDown={e => e.key === 'Enter' && search()}
3255
onChange={onChange}
@@ -54,7 +77,7 @@ const Searchbar = ({}) => {
5477
</InputGroup>
5578

5679
</HStack>
57-
80+
<SearchEngineModal isOpen={isModalOpen} onClose={onClose} />
5881
</>
5982
);
6083
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { useEffect, useContext } from 'react';
2+
import {
3+
Modal,
4+
ModalOverlay,
5+
ModalContent,
6+
ModalHeader,
7+
ModalCloseButton,
8+
ModalBody,
9+
Select,
10+
} from '@chakra-ui/react';
11+
12+
import { SearchContext } from '../../context/SearchContext';
13+
14+
// eslint-disable-next-line react/prop-types
15+
const SearchEngineModal = ({ isOpen, onClose }) => {
16+
const {
17+
url,
18+
setUrl,
19+
keyword,
20+
setKeyword,
21+
onChange,
22+
search,
23+
setSearchEngine,
24+
searchEngine
25+
} = useContext(SearchContext);
26+
27+
const onChangeSelect = (event) => setSearchEngine(event.target.value);
28+
29+
return (
30+
<>
31+
<Modal isOpen={isOpen} onClose={onClose}>
32+
<ModalOverlay />
33+
<ModalContent
34+
backgroundColor="#32363e"
35+
onChange={(e) => onChangeSelect(e)}
36+
>
37+
<ModalHeader>Search Engine Settings</ModalHeader>
38+
<ModalCloseButton />
39+
<ModalBody marginBottom='20px' >
40+
<Select
41+
value={searchEngine}
42+
backgroundColor={{ backgroundColor: '#32363e' }}
43+
>
44+
<option value='https://www.google.com/search?q=' style={{backgroundColor:'#32363e'}} > Google</option>
45+
<option value='https://duckduckgo.com/?q=' style={{backgroundColor:'#32363e'}}>DucDuckGo</option>
46+
<option value='https://yandex.com.tr/search/?text=' style={{backgroundColor:'#32363e'}}>Yandex</option>
47+
</Select>
48+
</ModalBody>
49+
50+
</ModalContent>
51+
</Modal>
52+
</>
53+
)
54+
}
55+
56+
export default SearchEngineModal;

0 commit comments

Comments
 (0)