From 0f6d79683e1d28f707236c1fa5b8acc6f46146d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Malak?= Date: Fri, 25 Mar 2022 13:37:53 +0100 Subject: [PATCH] Fixed bug where pressing Enter with empty search bar would redirect to search results --- CHANGELOG.md | 1 + client/src/components/SearchBar/SearchBar.tsx | 19 +++++++++++-------- client/src/interfaces/SearchResult.ts | 1 + client/src/utility/searchParser.ts | 1 + 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b67f87..3c9daaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/client/src/components/SearchBar/SearchBar.tsx b/client/src/components/SearchBar/SearchBar.tsx index 9920073..2ec3420 100644 --- a/client/src/components/SearchBar/SearchBar.tsx +++ b/client/src/components/SearchBar/SearchBar.tsx @@ -64,7 +64,7 @@ export const SearchBar = (props: Props): JSX.Element => { }; const searchHandler = (e: KeyboardEvent) => { - 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 diff --git a/client/src/interfaces/SearchResult.ts b/client/src/interfaces/SearchResult.ts index 3d6c8ae..cac982f 100644 --- a/client/src/interfaces/SearchResult.ts +++ b/client/src/interfaces/SearchResult.ts @@ -6,4 +6,5 @@ export interface SearchResult { sameTab: boolean; search: string; query: Query; + rawQuery: string; } diff --git a/client/src/utility/searchParser.ts b/client/src/utility/searchParser.ts index 82ce28c..84c733d 100644 --- a/client/src/utility/searchParser.ts +++ b/client/src/utility/searchParser.ts @@ -14,6 +14,7 @@ export const searchParser = (searchQuery: string): SearchResult => { prefix: '', template: '', }, + rawQuery: searchQuery, }; const { customQueries, config } = store.getState().config;