Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify filter to work on selection change without button click (Fix #55) #78

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions app/routes/_index.tsx
Copy link
Contributor

Choose a reason for hiding this comment

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

@ST-KO This is not the ideal way of working with immediate searches/filters, We must be a debounce (delay) before firing a query. Consider typing paragraphs/digits for some reason, it will be flooded with tons of requests as you type the text in the box, kinda like a DDOS attack if many people are using it.

We must debounce for at least 500 milliseconds (standard). That would prevent tons of queries from being fired to API.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is exactly what I was going to suggest

Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,35 @@ export default function Index() {
}
}, [initialIssues, showBookmarked, isBookmarked])

const handleLanguageChange = (selectedLanguage: any) => {
useEffect(() => {
const formData = new FormData()
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend creating a custom hook that contains all the logic of the filter and exposes only the required stuff. That way it would be easy to test (I recommend writing tests too, if you can 😉 ) and we don't need to touch _index.tsx file while caring about filtration.

formData.set("service", service)
formData.set("minStars", minStars)
formData.set("maxStars", maxStars)
formData.set("minForks", minForks)
formData.set("language", language.join(" "))
formData.set("isAssigned", isAssigned.toString())
formData.set("category", category)
formData.set("framework", framework)
formData.set("hasPullRequests", hasPullRequests.toString())
formData.set("showBookmarked", showBookmarked.toString())
formData.set("searchQuery", mobileSearchQuery)
setIssues([])
setIsSearching(true)
submit(formData, { method: "get" })
}, [
service,
minStars,
maxStars,
minForks,
language,
category,
framework,
isAssigned,
hasPullRequests,
])

const handleLanguageChange = (selectedLanguage: string) => {
setLanguage(selectedLanguage)
}

Expand Down Expand Up @@ -226,7 +254,7 @@ export default function Index() {
formData.set("minStars", minStars)
formData.set("maxStars", maxStars)
formData.set("minForks", minForks)
formData.set("language", language)
formData.set("language", language.join(" "))
formData.set("isAssigned", isAssigned.toString())
formData.set("category", category)
formData.set("framework", framework)
Expand Down Expand Up @@ -257,8 +285,8 @@ export default function Index() {
formData.append(key, value.toString())
}
})
formData.set('service', service)
formData.set('searchQuery', mobileSearchQuery)
formData.set("service", service)
formData.set("searchQuery", mobileSearchQuery)
setIssues([])
setIsSearching(true)
submit(formData, { method: "get" })
Expand Down