-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add search on business unit #152
Conversation
src/app/result/page.tsx
Outdated
const FetchQuestionResults = async ({role, unit} : {role:string, unit:string}) => { | ||
switch(true) { | ||
case (role != undefined && unit == undefined) : | ||
return await db.questionResult.findMany( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you could again take a look at using falsy
& truty
, same as in this comment:
#151 (comment)
setInterval(() => { | ||
const currentRole = form.getValues().role; | ||
const currentUnit = form.getValues().unit; | ||
if (previousRole != currentRole || previousUnit != currentUnit) { | ||
previousRole = currentRole; | ||
previousUnit = currentUnit; | ||
onSubmit({role: currentRole, unit: currentUnit}); | ||
} | ||
|
||
}, 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was your intention here to use this setInterval
as a debounce? If so, then it's maybe better to have a look at setTimeout
instead. It will fire unintentionally when no actual update has happend. Moreover, the interval will actually not be cleared, which means that if this component is unmounted, your interval would keep running. And the next time you come back, a second interval will be started.
If you put the previousRole
and currentRole
into a useState
, you can use the useEffect
to trigger whenever there was an update, to then trigger the setTimeout which would function as a debounce. Additionally you can also make use of the clearTimeout
to clear a timeout when it's not relevant anymore, this could be because a new timeout has started, or because the component was unmounted.
The way you can trigger code to be exectuted before the component is actually unmounted is by doing this:
https://stackoverflow.com/questions/55020041/react-hooks-useeffect-cleanup-for-only-componentwillunmount
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ik snap niet helemaal hoe je vanuit de from dat er is gemaakt kun inhaken op de state. Ik heb voor nu een return state aan het useEffect toegevoegd. Deze zou ervoor moeten zorgen dat de interval op juiste manier word geunmount.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventueel kunnen ofwel @lucacelea of ikzelf daar eens even mee meekijken, laat maar iets weten dan 😄
}) | ||
|
||
export default function SearchAnonymized({roles, businessUnits} : {roles: Section[], businessUnits : BusinessUnit[]}) { | ||
const [count, setCount] = useState(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not used
No description provided.