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

Add search on business unit #152

Merged
merged 16 commits into from
Dec 13, 2024

Conversation

JefQuidousse2
Copy link
Contributor

No description provided.

@JefQuidousse2 JefQuidousse2 marked this pull request as ready for review October 25, 2024 10:47
prisma/seed.js Show resolved Hide resolved
const FetchQuestionResults = async ({role, unit} : {role:string, unit:string}) => {
switch(true) {
case (role != undefined && unit == undefined) :
return await db.questionResult.findMany(
Copy link
Collaborator

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)

src/components/select-role.tsx Outdated Show resolved Hide resolved
Comment on lines 42 to 51
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);
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Collaborator

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();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not used

@JarneVanAerde JarneVanAerde merged commit dfa3e1b into infosupport:main Dec 13, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants