wrap profileEditScreen in route
This commit is contained in:
		
							parent
							
								
									de42f090ef
								
							
						
					
					
						commit
						90170eb635
					
				
					 2 changed files with 47 additions and 17 deletions
				
			
		|  | @ -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.home.HomeRoute | ||||||
| import be.ugent.sel.studeez.screens.log_in.LoginRoute | import be.ugent.sel.studeez.screens.log_in.LoginRoute | ||||||
| import be.ugent.sel.studeez.screens.log_in.LoginScreen | 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.EditProfileScreen | ||||||
| import be.ugent.sel.studeez.screens.profile.ProfileScreen | import be.ugent.sel.studeez.screens.profile.ProfileScreen | ||||||
| import be.ugent.sel.studeez.screens.session.SessionScreen | import be.ugent.sel.studeez.screens.session.SessionScreen | ||||||
|  | @ -137,7 +138,7 @@ fun NavGraphBuilder.studeezGraph(appState: StudeezAppstate) { | ||||||
| 
 | 
 | ||||||
|     // Edit screens |     // Edit screens | ||||||
|     composable(StudeezDestinations.EDIT_PROFILE_SCREEN) { |     composable(StudeezDestinations.EDIT_PROFILE_SCREEN) { | ||||||
|         EditProfileScreen(goBack, openAndPopUp) |         EditProfileRoute(goBack, openAndPopUp, viewModel = hiltViewModel()) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     composable(StudeezDestinations.TIMER_SELECTION_SCREEN) { |     composable(StudeezDestinations.TIMER_SELECTION_SCREEN) { | ||||||
|  |  | ||||||
|  | @ -14,14 +14,43 @@ import be.ugent.sel.studeez.common.ext.textButton | ||||||
| import be.ugent.sel.studeez.resources | import be.ugent.sel.studeez.resources | ||||||
| import be.ugent.sel.studeez.ui.theme.StudeezTheme | 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 | @Composable | ||||||
| fun EditProfileScreen( | fun EditProfileScreen( | ||||||
|     goBack: () -> Unit, |     goBack: () -> Unit, | ||||||
|     openAndPopUp: (String, String) -> Unit, |     uiState: ProfileEditUiState, | ||||||
|     viewModel: ProfileEditViewModel = hiltViewModel() |     editProfileActions: EditProfileActions, | ||||||
| ) { | ) { | ||||||
|     val uiState by viewModel.uiState |  | ||||||
| 
 |  | ||||||
|     SecondaryScreenTemplate( |     SecondaryScreenTemplate( | ||||||
|         title = resources().getString(R.string.editing_profile), |         title = resources().getString(R.string.editing_profile), | ||||||
|         popUp = goBack |         popUp = goBack | ||||||
|  | @ -29,16 +58,19 @@ fun EditProfileScreen( | ||||||
|         Column { |         Column { | ||||||
|             LabelledInputField( |             LabelledInputField( | ||||||
|                 value = uiState.username, |                 value = uiState.username, | ||||||
|                 onNewValue = viewModel::onUsernameChange, |                 onNewValue = editProfileActions.onUserNameChange, | ||||||
|                 label = R.string.username |                 label = R.string.username | ||||||
|             ) |             ) | ||||||
| 
 |             BasicTextButton( | ||||||
|             BasicTextButton(text = R.string.save, Modifier.textButton()) { |                 text = R.string.save, | ||||||
|                 viewModel.onSaveClick() |                 Modifier.textButton(), | ||||||
|             } |                 action = editProfileActions.onSaveClick | ||||||
|             BasicTextButton(text = R.string.delete_profile, Modifier.textButton()) { |             ) | ||||||
|                 viewModel.onDeleteClick(openAndPopUp) |             BasicTextButton( | ||||||
|             } |                 text = R.string.delete_profile, | ||||||
|  |                 Modifier.textButton(), | ||||||
|  |                 action = editProfileActions.onDeleteClick | ||||||
|  |             ) | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -47,9 +79,6 @@ fun EditProfileScreen( | ||||||
| @Composable | @Composable | ||||||
| fun EditProfileScreenComposable() { | fun EditProfileScreenComposable() { | ||||||
|     StudeezTheme { |     StudeezTheme { | ||||||
|         EditProfileScreen ( |         EditProfileScreen({}, ProfileEditUiState(), EditProfileActions({}, {}, {})) | ||||||
|             {}, |  | ||||||
|             {_, _ -> {}} |  | ||||||
|         ) |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Reference in a new issue
	
	 brreynie
						brreynie