Fixed bug where pressing Enter with empty search bar would redirect to search results

This commit is contained in:
Paweł Malak 2022-03-25 13:37:53 +01:00
parent 0b3eb2e87f
commit 0f6d79683e
4 changed files with 14 additions and 8 deletions

View file

@ -1,5 +1,6 @@
### v2.3.0 (TBA)
- Added custom theme editor ([#246](https://github.com/pawelmalak/flame/issues/246))
- Fixed bug where pressing Enter with empty search bar would redirect to search results ([#325](https://github.com/pawelmalak/flame/issues/325))
- Fixed bug where user could create empty app or bookmark which was causing page to go blank ([#332](https://github.com/pawelmalak/flame/issues/332))
### v2.2.2 (2022-03-21)

View file

@ -64,7 +64,7 @@ export const SearchBar = (props: Props): JSX.Element => {
};
const searchHandler = (e: KeyboardEvent<HTMLInputElement>) => {
const { isLocal, search, query, isURL, sameTab } = searchParser(
const { isLocal, search, query, isURL, sameTab, rawQuery } = searchParser(
inputRef.current.value
);
@ -90,15 +90,18 @@ export const SearchBar = (props: Props): JSX.Element => {
} else if (bookmarkSearchResult?.[0]?.bookmarks?.length) {
redirectUrl(bookmarkSearchResult[0].bookmarks[0].url, sameTab);
} else {
// no local results -> search the internet with the default search provider
let template = query.template;
// no local results -> search the internet with the default search provider if query is not empty
if (query.prefix === 'l') {
template = 'https://duckduckgo.com/?q=';
if (!/^ *$/.test(rawQuery)) {
let template = query.template;
if (query.prefix === 'l') {
template = 'https://duckduckgo.com/?q=';
}
const url = `${template}${search}`;
redirectUrl(url, sameTab);
}
const url = `${template}${search}`;
redirectUrl(url, sameTab);
}
} else {
// Valid query -> redirect to search results

View file

@ -6,4 +6,5 @@ export interface SearchResult {
sameTab: boolean;
search: string;
query: Query;
rawQuery: string;
}

View file

@ -14,6 +14,7 @@ export const searchParser = (searchQuery: string): SearchResult => {
prefix: '',
template: '',
},
rawQuery: searchQuery,
};
const { customQueries, config } = store.getState().config;