wrap profileEditScreen in route

This commit is contained in:
brreynie 2023-04-22 23:03:01 +02:00
parent de42f090ef
commit 90170eb635
2 changed files with 47 additions and 17 deletions

View file

@ -28,6 +28,7 @@ import be.ugent.sel.studeez.navigation.StudeezDestinations
import be.ugent.sel.studeez.screens.home.HomeRoute
import be.ugent.sel.studeez.screens.log_in.LoginRoute
import be.ugent.sel.studeez.screens.log_in.LoginScreen
import be.ugent.sel.studeez.screens.profile.EditProfileRoute
import be.ugent.sel.studeez.screens.profile.EditProfileScreen
import be.ugent.sel.studeez.screens.profile.ProfileScreen
import be.ugent.sel.studeez.screens.session.SessionScreen
@ -137,7 +138,7 @@ fun NavGraphBuilder.studeezGraph(appState: StudeezAppstate) {
// Edit screens
composable(StudeezDestinations.EDIT_PROFILE_SCREEN) {
EditProfileScreen(goBack, openAndPopUp)
EditProfileRoute(goBack, openAndPopUp, viewModel = hiltViewModel())
}
composable(StudeezDestinations.TIMER_SELECTION_SCREEN) {

View file

@ -14,14 +14,43 @@ import be.ugent.sel.studeez.common.ext.textButton
import be.ugent.sel.studeez.resources
import be.ugent.sel.studeez.ui.theme.StudeezTheme
data class EditProfileActions(
val onUserNameChange: (String) -> Unit,
val onSaveClick: () -> Unit,
val onDeleteClick: () -> Unit
)
fun getEditProfileActions(
viewModel: ProfileEditViewModel,
openAndPopUp: (String, String) -> Unit,
): EditProfileActions {
return EditProfileActions(
onUserNameChange = { viewModel.onUsernameChange(it) },
onSaveClick = { viewModel.onSaveClick() },
onDeleteClick = { viewModel.onDeleteClick(openAndPopUp) },
)
}
@Composable
fun EditProfileRoute(
goBack: () -> Unit,
openAndPopUp: (String, String) -> Unit,
viewModel: ProfileEditViewModel,
) {
val uiState by viewModel.uiState
EditProfileScreen(
goBack = goBack,
uiState = uiState,
editProfileActions = getEditProfileActions(viewModel, openAndPopUp)
)
}
@Composable
fun EditProfileScreen(
goBack: () -> Unit,
openAndPopUp: (String, String) -> Unit,
viewModel: ProfileEditViewModel = hiltViewModel()
uiState: ProfileEditUiState,
editProfileActions: EditProfileActions,
) {
val uiState by viewModel.uiState
SecondaryScreenTemplate(
title = resources().getString(R.string.editing_profile),
popUp = goBack
@ -29,16 +58,19 @@ fun EditProfileScreen(
Column {
LabelledInputField(
value = uiState.username,
onNewValue = viewModel::onUsernameChange,
onNewValue = editProfileActions.onUserNameChange,
label = R.string.username
)
BasicTextButton(text = R.string.save, Modifier.textButton()) {
viewModel.onSaveClick()
}
BasicTextButton(text = R.string.delete_profile, Modifier.textButton()) {
viewModel.onDeleteClick(openAndPopUp)
}
BasicTextButton(
text = R.string.save,
Modifier.textButton(),
action = editProfileActions.onSaveClick
)
BasicTextButton(
text = R.string.delete_profile,
Modifier.textButton(),
action = editProfileActions.onDeleteClick
)
}
}
}
@ -47,9 +79,6 @@ fun EditProfileScreen(
@Composable
fun EditProfileScreenComposable() {
StudeezTheme {
EditProfileScreen (
{},
{_, _ -> {}}
)
EditProfileScreen({}, ProfileEditUiState(), EditProfileActions({}, {}, {}))
}
}