#52 Add logout functionality
This commit is contained in:
		
							parent
							
								
									22b5a27102
								
							
						
					
					
						commit
						85e1b55507
					
				
					 4 changed files with 31 additions and 5 deletions
				
			
		|  | @ -33,7 +33,7 @@ fun StudeezApp() { | |||
|             val appState = rememberAppState() | ||||
| 
 | ||||
|             ModalDrawer( | ||||
|                 drawerContent = { Drawer() }, | ||||
|                 drawerContent = { Drawer({ route, popUp -> appState.navigateAndPopUp(route, popUp) }) }, | ||||
|                 drawerState = appState.drawerState | ||||
|             ) { | ||||
|                 Scaffold( | ||||
|  |  | |||
|  | @ -14,13 +14,18 @@ import androidx.compose.ui.graphics.vector.ImageVector | |||
| import androidx.compose.ui.res.painterResource | ||||
| import androidx.compose.ui.res.stringResource | ||||
| import androidx.compose.ui.tooling.preview.Preview | ||||
| import androidx.hilt.navigation.compose.hiltViewModel | ||||
| import be.ugent.sel.studeez.R | ||||
| import be.ugent.sel.studeez.resources | ||||
| import be.ugent.sel.studeez.screens.drawer.DrawerViewModel | ||||
| import be.ugent.sel.studeez.ui.theme.StudeezTheme | ||||
| 
 | ||||
| 
 | ||||
| @Composable | ||||
| fun Drawer() { | ||||
| fun Drawer( | ||||
|     openAndPopup: (String, String) -> Unit, | ||||
|     viewModel: DrawerViewModel = hiltViewModel() | ||||
| ) { | ||||
|     Column(modifier = Modifier.fillMaxSize()) { | ||||
|         LoggedInUserCard() | ||||
| 
 | ||||
|  | @ -48,7 +53,7 @@ fun Drawer() { | |||
|             icon = Icons.Default.AccountBox, // TODO Fix icon | ||||
|             text = resources().getString(R.string.log_out) | ||||
|         ) { | ||||
|             // TODO Log out | ||||
|             viewModel.onLogoutClick(openAndPopup) | ||||
|         } | ||||
| 
 | ||||
|         DrawerEntry( | ||||
|  | @ -102,7 +107,7 @@ fun LoggedInUserCard() { | |||
| @Composable | ||||
| fun DrawerPreview() { | ||||
|     StudeezTheme { | ||||
|         Drawer() | ||||
|         Drawer({ a, b -> {}}) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | @ -0,0 +1,22 @@ | |||
| package be.ugent.sel.studeez.screens.drawer | ||||
| 
 | ||||
| import be.ugent.sel.studeez.domain.AccountDAO | ||||
| import be.ugent.sel.studeez.domain.LogService | ||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.HOME_SCREEN | ||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.LOGIN_SCREEN | ||||
| import be.ugent.sel.studeez.screens.StudeezViewModel | ||||
| import dagger.hilt.android.lifecycle.HiltViewModel | ||||
| import javax.inject.Inject | ||||
| 
 | ||||
| @HiltViewModel | ||||
| class DrawerViewModel @Inject constructor( | ||||
|     private val accountDAO: AccountDAO, | ||||
|     logService: LogService | ||||
| ): StudeezViewModel(logService) { | ||||
|     fun onLogoutClick(openAndPopup: (String, String) -> Unit) { | ||||
|         launchCatching { | ||||
|             accountDAO.signOut() | ||||
|             openAndPopup(LOGIN_SCREEN, HOME_SCREEN) | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -5,7 +5,6 @@ import be.ugent.sel.studeez.common.ext.isValidEmail | |||
| 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.navigation.StudeezDestinations | ||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.HOME_SCREEN | ||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.LOGIN_SCREEN | ||||
| import be.ugent.sel.studeez.navigation.StudeezDestinations.SIGN_UP_SCREEN | ||||
|  |  | |||
		Reference in a new issue