Skip to content

Commit f1c48e8

Browse files
authored
Merge pull request pawelmalak#61 from jjack/master
Adding a default search provider option, with DuckDuckGo as the default
2 parents 6445a50 + 112a35c commit f1c48e8

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

client/src/components/Settings/OtherSettings/OtherSettings.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
3535
hideApps: 0,
3636
hideCategories: 0,
3737
hideSearch: 0,
38+
defaultSearchProvider: 'd',
3839
useOrdering: 'createdAt',
3940
appsSameTab: 0,
4041
bookmarksSameTab: 0,
@@ -51,6 +52,7 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
5152
hideApps: searchConfig('hideApps', 0),
5253
hideCategories: searchConfig('hideCategories', 0),
5354
hideSearch: searchConfig('hideSearch', 0),
55+
defaultSearchProvider: searchConfig('defaultSearchProvider', 'd'),
5456
useOrdering: searchConfig('useOrdering', 'createdAt'),
5557
appsSameTab: searchConfig('appsSameTab', 0),
5658
bookmarksSameTab: searchConfig('bookmarksSameTab', 0),
@@ -192,6 +194,24 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
192194
<option value={0}>False</option>
193195
</select>
194196
</InputGroup>
197+
<InputGroup>
198+
<label htmlFor='defaultSearchProvider'>Default Search Provider</label>
199+
<select
200+
id='defaultSearchProvider'
201+
name='defaultSearchProvider'
202+
value={formData.defaultSearchProvider}
203+
onChange={(e) => inputChangeHandler(e)}
204+
>
205+
<option value='d'>DuckDuckGo</option>
206+
<option value='g'>Google</option>
207+
<option value='s'>Disroot</option>
208+
<option value='yt'>YouTube</option>
209+
<option value='r'>Reddit</option>
210+
<option value='im'>IMDb</option>
211+
<option value='mv'>The Movie Database</option>
212+
<option value='sp'>Spotify</option>
213+
</select>
214+
</InputGroup>
195215
<InputGroup>
196216
<label htmlFor='hideHeader'>Hide greeting and date</label>
197217
<select
@@ -246,4 +266,4 @@ const actions = {
246266
sortCategories
247267
}
248268

249-
export default connect(mapStateToProps, actions)(OtherSettings);
269+
export default connect(mapStateToProps, actions)(OtherSettings);

client/src/interfaces/Forms.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ export interface SettingsForm {
1313
hideApps: number;
1414
hideCategories: number;
1515
hideSearch: number;
16+
defaultSearchProvider: string;
1617
useOrdering: string;
1718
appsSameTab: number;
1819
bookmarksSameTab: number;
1920
searchSameTab: number;
20-
}
21+
}

client/src/utility/searchParser.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import { Query } from '../interfaces';
44
import { searchConfig } from '.';
55

66
export const searchParser = (searchQuery: string): boolean => {
7-
const space = searchQuery.indexOf(' ');
8-
const prefix = searchQuery.slice(1, space);
9-
const search = encodeURIComponent(searchQuery.slice(space + 1));
7+
const splitQuery = searchQuery.match(/^\/([a-z]+)[ ](.+)$/i);
8+
const prefix = splitQuery ? splitQuery[1] : searchConfig('defaultSearchProvider', 'd');
9+
const search = splitQuery ? encodeURIComponent(splitQuery[2]) : encodeURIComponent(searchQuery);
1010

1111
const query = queries.find((q: Query) => q.prefix === prefix);
1212

13+
console.log("QUERY IS " + query);
1314
if (query) {
1415
const sameTab = searchConfig('searchSameTab', false);
1516

@@ -23,4 +24,4 @@ export const searchParser = (searchQuery: string): boolean => {
2324
}
2425

2526
return false;
26-
}
27+
}

utils/initialConfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
{
6060
"key": "hideSearch",
6161
"value": false
62+
},
63+
{
64+
"key": "defaultSearchProvider",
65+
"value": "d"
6266
}
6367
]
64-
}
68+
}

0 commit comments

Comments
 (0)