diff --git a/app/src/main/java/hu/bme/kszk/szobatarsch/composable/Profile.kt b/app/src/main/java/hu/bme/kszk/szobatarsch/composable/Profile.kt index d800f03ebab2ebb72e1f7d15976e6725213ba3a0..bf6b2a93d0d86030081f02a7159228c65ed103eb 100644 --- a/app/src/main/java/hu/bme/kszk/szobatarsch/composable/Profile.kt +++ b/app/src/main/java/hu/bme/kszk/szobatarsch/composable/Profile.kt @@ -186,33 +186,48 @@ fun Profile(isEditable: Boolean = false) { editable.value = false coroutineScope.launch { - registerOrOverwriteUser( - User( - id = user.value.id, - name = profileState.name.value, - description = profileState.description.value, - preferences = Preferences( - gender = profileState.gender.value, - age = profileState.age.value, - major = profileState.major.value, - semester = profileState.semester.value, - bedTime = profileState.bedTimeSliderPosition.value.toInt(), - wakeUpTime = profileState.wakeTimeSliderPosition.value.toInt(), - morningShower = profileState.morningShower.value, - eveningShower = profileState.eveningShower.value, - frequentNightTimeGuest = profileState.frequentNightTimeGuest.value, - frequencyOfCleaning = profileState.cleaningSliderPosition.value.toInt(), - loudness = profileState.loudnessSliderPosition.value.toInt(), - storageSpace = profileState.storageSliderPosition.value.toInt(), - ghost = profileState.ghost.value - ), - contacts = profileState.contacts.value, - dismissedUsers = user.value.dismissedUsers, - likedUsers = user.value.likedUsers - ) - ) + updateUserData(user, profileState) } + }) { + Text(text = "Mentés") + } + } + } + } +} + +private suspend fun updateUserData( + user: MutableState<User>, + profileState: ProfileState +) { + registerOrOverwriteUser( + User( + id = user.value.id, + name = profileState.name.value, + description = profileState.description.value, + preferences = Preferences( + gender = profileState.gender.value, + age = profileState.age.value, + major = profileState.major.value, + semester = profileState.semester.value, + bedTime = profileState.bedTimeSliderPosition.value.toInt(), + wakeUpTime = profileState.wakeTimeSliderPosition.value.toInt(), + morningShower = profileState.morningShower.value, + eveningShower = profileState.eveningShower.value, + frequentNightTimeGuest = profileState.frequentNightTimeGuest.value, + frequencyOfCleaning = profileState.cleaningSliderPosition.value.toInt(), + loudness = profileState.loudnessSliderPosition.value.toInt(), + storageSpace = profileState.storageSliderPosition.value.toInt(), + ghost = profileState.ghost.value + ), + contacts = profileState.contacts.value, + dismissedUsers = user.value.dismissedUsers, + likedUsers = user.value.likedUsers + ) + ) +} + private fun firebaseUserDataToProfileState( profileState: ProfileState, user: MutableState<User>