Skip to content

Commit

Permalink
Direct user to login screen on logout.
Browse files Browse the repository at this point in the history
  • Loading branch information
mutkuensert committed Nov 28, 2023
1 parent fff5141 commit 66b13f6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class PopularMovieModel(
@Serializable
data class PopularMovies(
@SerialName("adult") val adult: Boolean,
@SerialName("backdrop_path") val backdropPath: String,
@SerialName("backdrop_path") val backdropPath: String?,
@SerialName("genre_ids") val genreIds: List<Int>,
@SerialName("id") val movieId: Int,
@SerialName("original_language") val originalLanguage: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class AccountScreen : Screen {
AccountScreen(
viewModel = viewModel,
navigateToSplash = { mainNavigator.replaceAll(SplashScreen()) },
navigateToFavorite = { navigator.push(FavoriteScreen(it)) })
navigateToFavorite = { navigator.push(FavoriteScreen(it)) },
navigateToLogin = { navigator.replaceAll(LoginScreen()) }
)

BackHandler(isEnabled = true) {
navigator.pop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ class AccountDetailViewModel(
}
}

fun logout() {
viewModelScope.launch {
val result = logoutUseCase.execute()
if (result.isSuccess) {
_logoutState.value = result.getOrNull() ?: false
}
}
suspend fun logout(): Result<Unit> {
val result = logoutUseCase.execute()

return result.onSuccess {
_logoutState.value = it
}.map { Result.success(Unit) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
Expand All @@ -31,16 +32,17 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.moveeapp_compose_kmm.MR
import com.example.moveeapp_compose_kmm.domain.MediaType
import com.example.moveeapp_compose_kmm.core.viewModel
import com.example.moveeapp_compose_kmm.ui.components.TextItem
import dev.icerock.moko.resources.compose.fontFamilyResource
import dev.icerock.moko.resources.compose.stringResource
import kotlinx.coroutines.launch

@Composable
fun AccountScreen(
viewModel: AccountDetailViewModel,
navigateToSplash: () -> Unit,
navigateToFavorite: (MediaType) -> Unit,
navigateToLogin: () -> Unit,
) {
val uiState by viewModel.uiState.collectAsState()
val logoutState by viewModel.logoutState.collectAsState()
Expand All @@ -61,11 +63,19 @@ fun AccountScreen(
.background(MaterialTheme.colorScheme.primary)
)

val coroutineScope = rememberCoroutineScope()

SuccessContent(
uiState = uiState,
onFavMovieClick = navigateToFavorite,
onFavTvClick = navigateToFavorite,
onLogoutClick = { viewModel.logout() }
onLogoutClick = {
coroutineScope.launch {
viewModel.logout().onSuccess {
navigateToLogin.invoke()
}
}
}
)
}
}
Expand Down

0 comments on commit 66b13f6

Please sign in to comment.