polito / students-app

Politecnico di Torino's official mobile application for students
European Union Public License 1.2
147 stars 14 forks source link

fix(courses): fix switches behavior #482

Closed emacoricciati closed 4 months ago

emacoricciati commented 4 months ago

Closes #477

QcFe commented 4 months ago

I'm not extremely sure this is the most appropriate way to fix this issue... If I understood correctly, this would imply an optimistic approach but the final state of the switches could still not be the correct one. I would suggest a slightly different approach, such as disabling the switch until the change has been correctly propagated...

You can likely use properties from useMutation to understand if there's something going on and disable the input/show a loading spinner accordingly.

emacoricciati commented 4 months ago

@QcFe Right, in some cases, this version doesn't consider the updated version from the server and could lead to some inconsistencies between the server and the phone. Trying to leverage the isLoading return value of useMutation still shows some issues in propagating notifications and updating switches. I was wondering if it would be better, after a button is pressed, to use a timeout (e.g., 500/1000 ms) during which the buttons remain disabled to propagate the change.

Bri74 commented 4 months ago

@emacoricciati I never find it a good idea to use a timeout in these situations. @QcFe Any chance of finding a more elegant solution that works?