#18 Edit and delete profile implemented

This commit is contained in:
Tibo De Peuter 2023-04-16 22:40:43 +02:00
parent f263b34c12
commit 5e2c8de521
9 changed files with 32 additions and 25 deletions

View file

@ -17,6 +17,7 @@ import be.ugent.sel.studeez.ui.theme.StudeezTheme
@Composable
fun EditProfileScreen(
goBack: () -> Unit,
openAndPopUp: (String, String) -> Unit,
viewModel: ProfileEditViewModel = hiltViewModel()
) {
val uiState by viewModel.uiState
@ -36,7 +37,7 @@ fun EditProfileScreen(
viewModel.onSaveClick()
}
BasicTextButton(text = R.string.delete_profile, Modifier.textButton()) {
viewModel.onDeleteClick()
viewModel.onDeleteClick(openAndPopUp)
}
}
}
@ -47,7 +48,8 @@ fun EditProfileScreen(
fun EditProfileScreenComposable() {
StudeezTheme {
EditProfileScreen (
{}
{},
{_, _ -> {}}
)
}
}

View file

@ -6,6 +6,7 @@ import be.ugent.sel.studeez.common.snackbar.SnackbarManager
import be.ugent.sel.studeez.domain.AccountDAO
import be.ugent.sel.studeez.domain.LogService
import be.ugent.sel.studeez.domain.UserDAO
import be.ugent.sel.studeez.navigation.StudeezDestinations
import be.ugent.sel.studeez.screens.StudeezViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
@ -33,13 +34,15 @@ class ProfileEditViewModel @Inject constructor(
fun onSaveClick() {
launchCatching {
userDAO.save(uiState.value.username)
SnackbarManager.showMessage(R.string.save_success)
SnackbarManager.showMessage(R.string.success)
}
}
fun onDeleteClick() {
fun onDeleteClick(openAndPopUp: (String, String) -> Unit) {
launchCatching {
accountDAO.deleteAccount()
userDAO.deleteUserReferences() // Delete references
accountDAO.deleteAccount() // Delete authentication
}
openAndPopUp(StudeezDestinations.SIGN_UP_SCREEN, StudeezDestinations.EDIT_PROFILE_SCREEN)
}
}

View file

@ -13,11 +13,8 @@ import be.ugent.sel.studeez.navigation.StudeezDestinations.LOGIN_SCREEN
import be.ugent.sel.studeez.navigation.StudeezDestinations.SIGN_UP_SCREEN
import be.ugent.sel.studeez.screens.StudeezViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.take
import be.ugent.sel.studeez.R.string as AppText
import javax.inject.Inject
import be.ugent.sel.studeez.R.string as AppText
@HiltViewModel
class SignUpViewModel @Inject constructor(