From 4514d626eb554bda73cc81167267b18379303bc5 Mon Sep 17 00:00:00 2001 From: TheRealAshik <177647015+TheRealAshik@users.noreply.github.com> Date: Sat, 16 May 2026 07:52:57 +0000 Subject: [PATCH] feat: Implement sign-out flow on Settings screen - Add `signOut()` and `signOutEvent` Flow to `SettingsViewModel` to clear stored PAT and trigger navigation. - Add `onSignOut` lambda parameter to `SettingsScreen` and hook it up to the `SettingsRow` button and `LaunchedEffect`. - Wire `onSignOut` in `App.kt` to navigate to `Route.AddPat` and properly pop the backstack up to `Route.Settings`. --- .../kotlin/dev/therealashik/github/App.kt | 7 ++++++- .../therealashik/github/settings/SettingsScreen.kt | 9 ++++++++- .../github/settings/SettingsViewModel.kt | 13 +++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/dev/therealashik/github/App.kt b/composeApp/src/commonMain/kotlin/dev/therealashik/github/App.kt index feab061..a56625f 100755 --- a/composeApp/src/commonMain/kotlin/dev/therealashik/github/App.kt +++ b/composeApp/src/commonMain/kotlin/dev/therealashik/github/App.kt @@ -59,7 +59,12 @@ fun App() { onNavigateBack = { navController.popBackStack() }, onNavigateToNotificationOptions = { navController.navigate(Route.NotificationOptions) }, onNavigateToCodeOptions = { navController.navigate(Route.CodeOptions) }, - onNavigateToAddPat = { navController.navigate(Route.AddPat) } + onNavigateToAddPat = { navController.navigate(Route.AddPat) }, + onSignOut = { + navController.navigate(Route.AddPat) { + popUpTo(Route.Settings) { inclusive = true } + } + } ) } composable { diff --git a/composeApp/src/commonMain/kotlin/dev/therealashik/github/settings/SettingsScreen.kt b/composeApp/src/commonMain/kotlin/dev/therealashik/github/settings/SettingsScreen.kt index 04b374e..a1bed89 100644 --- a/composeApp/src/commonMain/kotlin/dev/therealashik/github/settings/SettingsScreen.kt +++ b/composeApp/src/commonMain/kotlin/dev/therealashik/github/settings/SettingsScreen.kt @@ -25,6 +25,7 @@ fun SettingsScreen( onNavigateToNotificationOptions: () -> Unit, onNavigateToCodeOptions: () -> Unit, onNavigateToAddPat: () -> Unit, + onSignOut: () -> Unit, viewModel: SettingsViewModel = viewModel { SettingsViewModel() } ) { val uiState by viewModel.uiState.collectAsState() @@ -37,6 +38,12 @@ fun SettingsScreen( if (lifecycleState == Lifecycle.State.RESUMED) viewModel.refresh() } + LaunchedEffect(Unit) { + viewModel.signOutEvent.collect { + onSignOut() + } + } + if (showAccountsSheet) { AccountsSheet( accounts = uiState.accounts, @@ -128,7 +135,7 @@ fun SettingsScreen( SettingsRow( title = stringResource(Res.string.settings_sign_out), titleColor = MaterialTheme.colorScheme.error, - onClick = { /* TODO */ } + onClick = { viewModel.signOut() } ) SectionDivider() } diff --git a/composeApp/src/commonMain/kotlin/dev/therealashik/github/settings/SettingsViewModel.kt b/composeApp/src/commonMain/kotlin/dev/therealashik/github/settings/SettingsViewModel.kt index a98015b..b4fb0e9 100644 --- a/composeApp/src/commonMain/kotlin/dev/therealashik/github/settings/SettingsViewModel.kt +++ b/composeApp/src/commonMain/kotlin/dev/therealashik/github/settings/SettingsViewModel.kt @@ -4,8 +4,11 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dev.therealashik.github.data.GitHubApiClient import dev.therealashik.github.data.createTokenStorage +import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch @@ -16,6 +19,9 @@ class SettingsViewModel : ViewModel() { private val _uiState = MutableStateFlow(SettingsUiState()) val uiState: StateFlow = _uiState.asStateFlow() + private val _signOutEvent = MutableSharedFlow() + val signOutEvent: SharedFlow = _signOutEvent.asSharedFlow() + init { refresh() } @@ -37,6 +43,13 @@ class SettingsViewModel : ViewModel() { } } + fun signOut() { + viewModelScope.launch { + tokenStorage.clearToken() + _signOutEvent.emit(Unit) + } + } + override fun onCleared() { super.onCleared() apiClient.close()