Closed charliemangano closed 2 weeks ago
Issues
1 New issue
0 Accepted issues
Measures
0 Security Hotspots
80.4% Coverage on New Code
0.0% Duplication on New Code
Merging this but we will definitely create a task to see what to do about the dispatchers @coaguila. Thanks for the last minute review!
Fix sync problem with CreateProfile screen
Description
This PR introduces a fix for issue #190: it solves the syncing problem that made a user have to click two times on the "Save" button on the CreateProfile screen.
The problem came from how we handle our side effects, as the callbacks of the view model execute, at least partly, only after we've checked in the CreateProfile screen that the saving had succeeded, for example:
So our CreateProfile screen thought that the operation failed, when it had just not finished executing.
Changes
Changed the signature of the functions in
UserViewModel
to haveonSuccess
andonFailure
callbacks. I moved the code that was previously in the button'sonClick
into the callbacks of the calls tosaveUser
andloadUser
. This ensures that this bit of code is executed after the rest of thesaveUser
orloadUser
code, which solves the problem. These callback all have simpleLog
s as default values. Docs were updated as well. Updated the tests for the CreateProfile screen to implement the new callbacks properly.Files
Added
None
Modified
app/src/main/java/com/android/periodpals/model/user/UserViewModel.kt
: add callbacks to function signaturesapp/src/main/java/com/android/periodpals/ui/profile/CreateProfile.kt
,app/src/main/java/com/android/periodpals/ui/profile/ProfileScreen.kt
: update the calls to the view model functions to implement the callbacks properlyapp/src/androidTest/java/com/android/periodpals/ui/profile/CreateProfileTest.kt
: update the tests to implement the callbacks properlyRemoved
None
Dependencies Added
None
Testing
Existing tests were updated but still check for the same things. Tests all pass. None more written. This should help for the end-to-end tests.
Edit: 14/11 8:22PM
Following a merge (24910ae), the function I was modifying (
onClick
of the "Save"Button
ofCreateProfile
) got refactored into a different file (ProfileComponents.kt
) that was now shared withEditProfile
. This means that any modification I made to fixCreateProfile
'sonClick
, I now had to do in theEditProfile
screen as well, and the associated tests. This PR therefore got extended after it had been approved. Having now modified everything I needed to, I'm requesting a re-review.Updated list of modifications: Everything from above, plus implementing changes asked in reviews, plus:
app/src/main/java/com/android/periodpals/ui/profile/CreateProfile.kt
: removed unused variableapp/src/main/java/com/android/periodpals/ui/profile/EditProfile.kt
: update call toloadUser
to implement callbacks properlyapp/src/main/java/com/android/periodpals/ui/components/ProfileComponents.kt
: updated now-refactoredProfileSaveButton
with work done in previous, now overwritten commits (implement callbacks properly in call tosaveUser
)app/src/androidTest/java/com/android/periodpals/ui/profile/EditProfileTest.kt
: updated to implement new callbacks properlyapp/src/test/java/com/android/periodpals/model/user/UserModelSupabaseTest.kt
: updated tests to run on main thread to comply with updatedUserModelSupabase
(fix to unit tests not passing after dc06a22)