diff --git a/shared/src/commonMain/kotlin/com/example/moveeapp_compose_kmm/data/movie/PopularMovieModel.kt b/shared/src/commonMain/kotlin/com/example/moveeapp_compose_kmm/data/movie/PopularMovieModel.kt index ed5ad4e..c02b266 100644 --- a/shared/src/commonMain/kotlin/com/example/moveeapp_compose_kmm/data/movie/PopularMovieModel.kt +++ b/shared/src/commonMain/kotlin/com/example/moveeapp_compose_kmm/data/movie/PopularMovieModel.kt @@ -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, @SerialName("id") val movieId: Int, @SerialName("original_language") val originalLanguage: String, diff --git a/shared/src/commonMain/kotlin/com/example/moveeapp_compose_kmm/nav/AccountScreen.kt b/shared/src/commonMain/kotlin/com/example/moveeapp_compose_kmm/nav/AccountScreen.kt index 7cca76c..0f3ca41 100644 --- a/shared/src/commonMain/kotlin/com/example/moveeapp_compose_kmm/nav/AccountScreen.kt +++ b/shared/src/commonMain/kotlin/com/example/moveeapp_compose_kmm/nav/AccountScreen.kt @@ -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() diff --git a/shared/src/commonMain/kotlin/com/example/moveeapp_compose_kmm/ui/scene/account/AccountDetailViewModel.kt b/shared/src/commonMain/kotlin/com/example/moveeapp_compose_kmm/ui/scene/account/AccountDetailViewModel.kt index 4d20ff2..ea3b771 100644 --- a/shared/src/commonMain/kotlin/com/example/moveeapp_compose_kmm/ui/scene/account/AccountDetailViewModel.kt +++ b/shared/src/commonMain/kotlin/com/example/moveeapp_compose_kmm/ui/scene/account/AccountDetailViewModel.kt @@ -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 { + val result = logoutUseCase.execute() + + return result.onSuccess { + _logoutState.value = it + }.map { Result.success(Unit) } } } diff --git a/shared/src/commonMain/kotlin/com/example/moveeapp_compose_kmm/ui/scene/account/AccountScreen.kt b/shared/src/commonMain/kotlin/com/example/moveeapp_compose_kmm/ui/scene/account/AccountScreen.kt index e2eebc9..ce4409f 100644 --- a/shared/src/commonMain/kotlin/com/example/moveeapp_compose_kmm/ui/scene/account/AccountScreen.kt +++ b/shared/src/commonMain/kotlin/com/example/moveeapp_compose_kmm/ui/scene/account/AccountScreen.kt @@ -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 @@ -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() @@ -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() + } + } + } ) } }