Skip to content

Commit

Permalink
Merge pull request #28 from IvanSanchezSalvador/check_text_no_whitesp…
Browse files Browse the repository at this point in the history
…ace_and_value

Disable to search with no text or with blank spaces
  • Loading branch information
Mridul2820 authored Oct 20, 2022
2 parents c961828 + a13f548 commit f3cf84f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions components/reuse/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ const Search = ({ height }) => {

const handleOnSubmit = (event) => {
event.preventDefault();

if (loading) return; // Prevent multiple requests
setLoading(true);

const fields = Array.from(event.currentTarget.elements);
const username = fields.find((field) => field.name === 'username')?.value;

router.push(`/user/${username}`);
if (username && !hasWhiteSpaceText(username)) {
setLoading(true);
router.push(`/user/${username}`);
}
};

const hasWhiteSpaceText = (text) => {
return /\s/g.test(text);
};

return (
Expand Down

1 comment on commit f3cf84f

@vercel
Copy link

@vercel vercel bot commented on f3cf84f Oct 20, 2022

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:

git-to-get – ./

git-to-get-mridul28.vercel.app
git-to-get-git-main-mridul28.vercel.app
git-o-get.mridul.tech

Please sign in to comment.