Skip to content

Commit

Permalink
Search bar query (#254)
Browse files Browse the repository at this point in the history
* Remove search results if the query is null.

* Remove search results if the query is null.

* Apply suggestions from code review

* Whoops

---------

Co-authored-by: David Leal <halfpacho@gmail.com>
  • Loading branch information
ESAM-ALSAWAH and Panquesito7 authored Jan 16, 2024
1 parent 80c3238 commit 509429c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions components/searchBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ export default function SearchBar({

function handleInput(event: FormEvent) {
setQuery((event.target as HTMLInputElement).value);

// When input value is null, set error & empty state to `true` and do nothing.

if (!smallScreen)
debounce(() => {
router.push(`/search?q=${(event.target as HTMLInputElement).value}`);
});
if (!(event.target as HTMLInputElement).value) {
setIsEmpty(true);
setIsError(true);
Expand All @@ -49,12 +53,7 @@ export default function SearchBar({
// When input value is not null, reset error & empty state to `false`.
// And also debounce the router push.
setIsError(false);
setIsEmpty(false);

if (!smallScreen)
debounce(() => {
router.push(`/search?q=${(event.target as HTMLInputElement).value}`);
});
setIsEmpty(false);

Check warning on line 56 in components/searchBar/index.tsx

View workflow job for this annotation

GitHub Actions / tsc and eslint

Delete `··`
}

function handleSubmit(event?: FormEvent) {
Expand Down

1 comment on commit 509429c

@vercel
Copy link

@vercel vercel bot commented on 509429c Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

website – ./

website-thealgorithms.vercel.app
website-git-main-thealgorithms.vercel.app
the-algorithms.com

Please sign in to comment.