mirror of
https://github.com/pawelmalak/flame.git
synced 2026-03-09 14:03:11 +08:00
Added option to set secondary search provider
This commit is contained in:
@@ -64,16 +64,22 @@ export const SearchBar = (props: Props): JSX.Element => {
|
||||
};
|
||||
|
||||
const searchHandler = (e: KeyboardEvent<HTMLInputElement>) => {
|
||||
const { isLocal, search, query, isURL, sameTab, rawQuery } = searchParser(
|
||||
inputRef.current.value
|
||||
);
|
||||
const {
|
||||
isLocal,
|
||||
encodedURL,
|
||||
primarySearch,
|
||||
secondarySearch,
|
||||
isURL,
|
||||
sameTab,
|
||||
rawQuery,
|
||||
} = searchParser(inputRef.current.value);
|
||||
|
||||
if (isLocal) {
|
||||
setLocalSearch(search);
|
||||
setLocalSearch(encodedURL);
|
||||
}
|
||||
|
||||
if (e.code === 'Enter' || e.code === 'NumpadEnter') {
|
||||
if (!query.prefix) {
|
||||
if (!primarySearch.prefix) {
|
||||
// Prefix not found -> emit notification
|
||||
createNotification({
|
||||
title: 'Error',
|
||||
@@ -91,21 +97,20 @@ export const SearchBar = (props: Props): JSX.Element => {
|
||||
redirectUrl(bookmarkSearchResult[0].bookmarks[0].url, sameTab);
|
||||
} else {
|
||||
// no local results -> search the internet with the default search provider if query is not empty
|
||||
|
||||
if (!/^ *$/.test(rawQuery)) {
|
||||
let template = query.template;
|
||||
let template = primarySearch.template;
|
||||
|
||||
if (query.prefix === 'l') {
|
||||
template = 'https://duckduckgo.com/?q=';
|
||||
if (primarySearch.prefix === 'l') {
|
||||
template = secondarySearch.template;
|
||||
}
|
||||
|
||||
const url = `${template}${search}`;
|
||||
const url = `${template}${encodedURL}`;
|
||||
redirectUrl(url, sameTab);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Valid query -> redirect to search results
|
||||
const url = `${query.template}${search}`;
|
||||
const url = `${primarySearch.template}${encodedURL}`;
|
||||
redirectUrl(url, sameTab);
|
||||
}
|
||||
} else if (e.code === 'Escape') {
|
||||
|
||||
@@ -167,7 +167,7 @@ export const GeneralSettings = (): JSX.Element => {
|
||||
{/* === SEARCH OPTIONS === */}
|
||||
<SettingsHeadline text="Search" />
|
||||
<InputGroup>
|
||||
<label htmlFor="defaultSearchProvider">Default search provider</label>
|
||||
<label htmlFor="defaultSearchProvider">Primary search provider</label>
|
||||
<select
|
||||
id="defaultSearchProvider"
|
||||
name="defaultSearchProvider"
|
||||
@@ -186,6 +186,34 @@ export const GeneralSettings = (): JSX.Element => {
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{formData.defaultSearchProvider === 'l' && (
|
||||
<InputGroup>
|
||||
<label htmlFor="secondarySearchProvider">
|
||||
Secondary search provider
|
||||
</label>
|
||||
<select
|
||||
id="secondarySearchProvider"
|
||||
name="secondarySearchProvider"
|
||||
value={formData.secondarySearchProvider}
|
||||
onChange={(e) => inputChangeHandler(e)}
|
||||
>
|
||||
{[...queries, ...customQueries].map((query: Query, idx) => {
|
||||
const isCustom = idx >= queries.length;
|
||||
|
||||
return (
|
||||
<option key={idx} value={query.prefix}>
|
||||
{isCustom && '+'} {query.name}
|
||||
</option>
|
||||
);
|
||||
})}
|
||||
</select>
|
||||
<span>
|
||||
Will be used when "Local search" is primary search provider and
|
||||
there are not any local results
|
||||
</span>
|
||||
</InputGroup>
|
||||
)}
|
||||
|
||||
<InputGroup>
|
||||
<label htmlFor="searchSameTab">
|
||||
Open search results in the same tab
|
||||
|
||||
Reference in New Issue
Block a user