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

236 add hash to course unit and method to verify hash #250

Merged

Conversation

jose-carlos-sousa
Copy link
Contributor

Closes #236
Added hash to the types
Added func to get hashes
Created hook to verify hashes against localStorage

@jose-carlos-sousa jose-carlos-sousa linked an issue Aug 18, 2024 that may be closed by this pull request
2 tasks
Copy link

netlify bot commented Aug 18, 2024

Deploy Preview for tts-fe-preview ready!

Name Link
🔨 Latest commit 11f842d
🔍 Latest deploy log https://app.netlify.com/sites/tts-fe-preview/deploys/66ce4457207d0a0008c8445e
😎 Deploy Preview https://deploy-preview-250--tts-fe-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@jose-carlos-sousa jose-carlos-sousa self-assigned this Aug 18, 2024
@jose-carlos-sousa jose-carlos-sousa requested a review from a team August 19, 2024 13:47
@jose-carlos-sousa jose-carlos-sousa force-pushed the 236-add-hash-to-course-unit-and-method-to-verify-hash branch from 2356a59 to ded395b Compare August 19, 2024 21:10
@jose-carlos-sousa jose-carlos-sousa force-pushed the 236-add-hash-to-course-unit-and-method-to-verify-hash branch from ded395b to 3dac80b Compare August 19, 2024 21:17
@tomaspalma
Copy link
Member

tomaspalma commented Aug 19, 2024

Great work!

Maybe you can also use the hook inside the CoursesController (this is the component that renders the dropdowns to select the classes) to actually perform the fetching of the hashes. And then in order to see if there are invalid classes, maybe a useEffect that runs when the data from the useSwr returned changes so that we can perform an action when there are invalid courses. The current decided action is to re-fetch the classes from that course unit.

If you think that should be done in a different component, feel free to say so!

I actually forgot to put that in the issue description that it was also the scope of this issue, I'm sorry for that.

Copy link
Member

@thePeras thePeras left a comment

Choose a reason for hiding this comment

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

I am not a big fan of using periodic check, an initial check in a useEffect would work fine.

In the code, I suggest moving updateCourses function outside the useEffect so it won't be declared multiple times

@tomaspalma
Copy link
Member

I am not a big fan of using periodic check, an initial check in a useEffect would work fine.

Since we are using useSwr, regardless of whether or not we make periodic requests, we don't need a useEffect because regardless of the refresh interval, every time you refresh the page it will make the request and update the data if it has changed.

Although I agree that periodic requests are not strictly necessary, there isn't a lot of harm to it, also because the amount of people making the same periodic request at the same time will be very low and it will be between 5-10 minutes.

Is the reason why you don't like periodic requests the potential unecessary increase in the number of requests?

In the code, I suggest moving updateCourses function outside the useEffect so it won't be declared multiple times

I also agree with that, it is a good idea!

@thePeras
Copy link
Member

Is the reason why you don't like periodic requests the potential unecessary increase in the number of requests?

Yes! Imagine we implemented the periodic scrapper today, we would probably make it run at 3h00, so, a periodic 5/10 min checker is something irrelevant since 0 users would be using the tts at that time. When the person visits the page and useEffect is triggered, it is enough to know the data is updated.
I think sleeping window tabs runs useEffect when they become active. But this needs to be confirmed! Because a user can have the tab indefinably in the browser.

If requesting this information when refresh the page is a problem, we can have some local storage variable like "have fetched today?"

@tomaspalma
Copy link
Member

If the scrapper runs at 3 am for example one time per day, yes, there is no need for periodic checking. However, the period in which the scrapper will run also depends on capabilities of niployments.

However, regardless of that, as you pointed out, the scrapper will not run too frequently probably, so the use cases where a periodic request is useful are low.

I dont think there is a problem in fetching the data when we refresh the page.

@jose-carlos-sousa
Copy link
Contributor Author

There is an issue where the app crashes when a class that I have selected is removed one solution could be to unselect the class of a course unit that has been changed

@tomaspalma
Copy link
Member

tomaspalma commented Aug 21, 2024

Can you please put here the exact error message it gives on the console?

Unfortunately, I'm unable to recreate the issue, I altered the hash on the backend on a course_unit that I had chosen a class (1LEIC01) on the frontend and no crash occured when the hash was changed.

@jose-carlos-sousa
Copy link
Contributor Author

Can you please put here the exact error message it gives on the console?

Unfortunately, I'm unable to recreate the issue, I altered the hash on the backend on a course_unit that I had chosen a class (1LEIC01) on the frontend and no crash occured when the hash was changed.

I basically used the same scenario to test and I got an error at the function getAllPickedSlots (index.ts) because classInfo was undefined so I added if( !classInfo ) return []; I will push

@jose-carlos-sousa jose-carlos-sousa force-pushed the 236-add-hash-to-course-unit-and-method-to-verify-hash branch from f659e16 to 42905ec Compare August 22, 2024 00:09
@jose-carlos-sousa
Copy link
Contributor Author

jose-carlos-sousa commented Aug 22, 2024

I realized that the app crashes when I pick a class and then the class I picked is removed

Can you please put here the exact error message it gives on the console?

Unfortunately, I'm unable to recreate the issue, I altered the hash on the backend on a course_unit that I had chosen a class (1LEIC01) on the frontend and no crash occured when the hash was changed.

ps the scenario I used was to start with normal db and select 1LEIC01 for FP then change to db where hash is changed and where there is no class 1LEIC01 for course unit FP and it crashed

@jose-carlos-sousa jose-carlos-sousa force-pushed the 236-add-hash-to-course-unit-and-method-to-verify-hash branch 2 times, most recently from 9382064 to f9131d3 Compare August 22, 2024 00:19
@tomaspalma
Copy link
Member

tomaspalma commented Aug 22, 2024

Ok, so just to clarify, that error appears jf the class you had selected was removed, right?

I hadnt thought of that scenario, it is a good observation

@jose-carlos-sousa
Copy link
Contributor Author

jose-carlos-sousa commented Aug 22, 2024

Ok, so just to clarify, that error appears jf the class you had selected was removed, right?

I hadnt thought of that scenario, it is a good observation

Yes that's it ,it appeared because 1LEIC01 was removed and it was the selected one
Currently I use that line if( !classInfo ) return []; that basically unselects the class when that happens which at least is better than crashing but I am not really sure about other solutions yet

@tomaspalma
Copy link
Member

tomaspalma commented Aug 22, 2024

It is not usual for classes to disappear. Normally the suddden data changes in sigarra are changes in the schedules or in the teachers, so that is a really narrow edge case.

I think just disappearing is fine for now, but the other solution would be to say to the user that the class disappeared in the refresh data, but I dont know if that is really needed

@jose-carlos-sousa jose-carlos-sousa force-pushed the 236-add-hash-to-course-unit-and-method-to-verify-hash branch from f9131d3 to 06313c1 Compare August 22, 2024 20:46
@jose-carlos-sousa jose-carlos-sousa force-pushed the 236-add-hash-to-course-unit-and-method-to-verify-hash branch from 6a99c66 to 127593c Compare August 24, 2024 20:42
@jose-carlos-sousa jose-carlos-sousa force-pushed the 236-add-hash-to-course-unit-and-method-to-verify-hash branch 4 times, most recently from c30262b to 402ad78 Compare August 26, 2024 23:01
@jose-carlos-sousa jose-carlos-sousa force-pushed the 236-add-hash-to-course-unit-and-method-to-verify-hash branch 2 times, most recently from 1f42042 to 8f3b4f4 Compare August 26, 2024 23:33
@jose-carlos-sousa jose-carlos-sousa force-pushed the 236-add-hash-to-course-unit-and-method-to-verify-hash branch from 8f3b4f4 to cee99be Compare August 26, 2024 23:39
tomaspalma
tomaspalma previously approved these changes Aug 27, 2024
Copy link
Member

@tomaspalma tomaspalma left a comment

Choose a reason for hiding this comment

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

🚀

@tomaspalma tomaspalma self-requested a review August 27, 2024 11:34
@tomaspalma tomaspalma dismissed their stale review August 27, 2024 11:35

a detail came up

@jose-carlos-sousa jose-carlos-sousa force-pushed the 236-add-hash-to-course-unit-and-method-to-verify-hash branch from cee99be to 11f842d Compare August 27, 2024 21:25
Copy link
Member

@tomaspalma tomaspalma left a comment

Choose a reason for hiding this comment

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

🚀 (not going to dimiss the review this time xD)

Copy link
Member

@thePeras thePeras left a comment

Choose a reason for hiding this comment

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

Very clean and documented code! Nice work!

✅ 🛫

@jose-carlos-sousa jose-carlos-sousa merged commit 185de25 into develop Aug 28, 2024
4 checks passed
@tomaspalma tomaspalma deleted the 236-add-hash-to-course-unit-and-method-to-verify-hash branch October 22, 2024 09:59
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.

Add hash to course unit and method to verify hash
3 participants