Skip to content

Commit

Permalink
fix(ui,api): prevent whitespace search (#1288)
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimarchAlpharius committed Sep 20, 2021
1 parent eb52040 commit 5aaa639
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/hub/src/resolvers/query.ts
Expand Up @@ -163,7 +163,7 @@ const query = {
return Object.assign({}, returned, { results: posts });
},
globalSearch: async (_source, { keyword }, { dataSources }) => {
const results = await dataSources.postsAPI.globalSearch(keyword);
const results = await dataSources.postsAPI.globalSearch(keyword?.trim());
results.tags = await (async () => {
const res = [];
for (const rec of results.tags) {
Expand Down
4 changes: 3 additions & 1 deletion ui/design/src/components/TopBar/mobile-search-bar.tsx
Expand Up @@ -16,8 +16,10 @@ const MobileSearchBar: React.FC<ISearchBar> = props => {
const [showSearch, setShowSearch] = React.useState(true);

const handleSearch = (ev: React.KeyboardEvent<HTMLInputElement>) => {
const trimmedValue = inputValue.trim();
if (!trimmedValue) return;
if (ev.key === 'Enter') {
onSearch(inputValue);
onSearch(trimmedValue);
}
};

Expand Down
4 changes: 3 additions & 1 deletion ui/widgets/top-bar/src/components/topbar-component.tsx
Expand Up @@ -167,7 +167,9 @@ const TopbarComponent = (props: RootComponentProps) => {
};

const handleSearch = (inputValue: string) => {
const encodedSearchKey = encodeURIComponent(inputValue);
const trimmedValue = inputValue.trim();
if (!trimmedValue) return;
const encodedSearchKey = encodeURIComponent(trimmedValue);
if (searchAreaItem) {
handleNavigation(`${searchAreaItem.route}/${encodedSearchKey}`);
}
Expand Down

0 comments on commit 5aaa639

Please sign in to comment.