Adding a default search provider option, with DuckDuckGo as the default

This commit is contained in:
Jeremy Jack 2021-07-05 23:04:03 -05:00
parent c03f302fa6
commit 112a35c08f
4 changed files with 33 additions and 7 deletions

View file

@ -35,6 +35,7 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
hideApps: 0,
hideCategories: 0,
hideSearch: 0,
defaultSearchProvider: 'd',
useOrdering: 'createdAt',
appsSameTab: 0,
bookmarksSameTab: 0,
@ -51,6 +52,7 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
hideApps: searchConfig('hideApps', 0),
hideCategories: searchConfig('hideCategories', 0),
hideSearch: searchConfig('hideSearch', 0),
defaultSearchProvider: searchConfig('defaultSearchProvider', 'd'),
useOrdering: searchConfig('useOrdering', 'createdAt'),
appsSameTab: searchConfig('appsSameTab', 0),
bookmarksSameTab: searchConfig('bookmarksSameTab', 0),
@ -192,6 +194,24 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
<option value={0}>False</option>
</select>
</InputGroup>
<InputGroup>
<label htmlFor='defaultSearchProvider'>Default Search Provider</label>
<select
id='defaultSearchProvider'
name='defaultSearchProvider'
value={formData.defaultSearchProvider}
onChange={(e) => inputChangeHandler(e)}
>
<option value='d'>DuckDuckGo</option>
<option value='g'>Google</option>
<option value='s'>Disroot</option>
<option value='yt'>YouTube</option>
<option value='r'>Reddit</option>
<option value='im'>IMDb</option>
<option value='mv'>The Movie Database</option>
<option value='sp'>Spotify</option>
</select>
</InputGroup>
<InputGroup>
<label htmlFor='hideHeader'>Hide greeting and date</label>
<select

View file

@ -13,6 +13,7 @@ export interface SettingsForm {
hideApps: number;
hideCategories: number;
hideSearch: number;
defaultSearchProvider: string;
useOrdering: string;
appsSameTab: number;
bookmarksSameTab: number;

View file

@ -4,12 +4,13 @@ import { Query } from '../interfaces';
import { searchConfig } from '.';
export const searchParser = (searchQuery: string): boolean => {
const space = searchQuery.indexOf(' ');
const prefix = searchQuery.slice(1, space);
const search = encodeURIComponent(searchQuery.slice(space + 1));
const splitQuery = searchQuery.match(/^\/([a-z]+)[ ](.+)$/i);
const prefix = splitQuery ? splitQuery[1] : searchConfig('defaultSearchProvider', 'd');
const search = splitQuery ? encodeURIComponent(splitQuery[2]) : encodeURIComponent(searchQuery);
const query = queries.find((q: Query) => q.prefix === prefix);
console.log("QUERY IS " + query);
if (query) {
const sameTab = searchConfig('searchSameTab', false);

View file

@ -59,6 +59,10 @@
{
"key": "hideSearch",
"value": false
},
{
"key": "defaultSearchProvider",
"value": "d"
}
]
}