Preventing seeing no posts when clicking on the "Search" button while search inputs are empty #114
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I realized that when you click on the "Search" button and both "tags" & "search" inputs are empty, then it's going to show you the loading icon and return an empty array which is not the expected output.
This means it's still going to run the
if
block of code (if you pay attention to the url) while theelse
block must be executed instead of that.It means we should change our conditions and just add
length
at the end of thesearch.trim()
&tags
so as to count the number of items in our array.This will produce the ideal and expected output and it will run the
else
block while we have written nothing in the search inputs and have also clicked on the search button instead of seeing no posts on the screen. So, it means it's going to redirect the user to the home page (history.push('/')
) if we only click on the "Search" button without writing anything in its inputs.