diff --git a/feature/auth/src/main/java/com/puzzle/auth/graph/main/AuthScreen.kt b/feature/auth/src/main/java/com/puzzle/auth/graph/main/AuthScreen.kt index 7592ed6d..41a15fc9 100644 --- a/feature/auth/src/main/java/com/puzzle/auth/graph/main/AuthScreen.kt +++ b/feature/auth/src/main/java/com/puzzle/auth/graph/main/AuthScreen.kt @@ -1,10 +1,25 @@ package com.puzzle.auth.graph.main +import android.util.Log +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.sp import com.airbnb.mvrx.compose.collectAsState import com.airbnb.mvrx.compose.mavericksViewModel +import com.kakao.sdk.user.UserApiClient +import com.puzzle.auth.graph.main.contract.AuthIntent.Navigate +import com.puzzle.auth.graph.main.contract.AuthState +import com.puzzle.designsystem.foundation.PieceTheme +import com.puzzle.navigation.AuthGraph +import com.puzzle.navigation.AuthGraphDest +import com.puzzle.navigation.NavigationEvent @Composable fun AuthRoute( @@ -14,47 +29,59 @@ fun AuthRoute( val context = LocalContext.current AuthScreen( - + state = state, + loginKakao = { + UserApiClient.instance.loginWithKakaoAccount(context) { token, error -> + if (error != null) { + Log.e("test", "로그인 실패", error) + } else if (token != null) { + Log.i("test", "로그인 성공 ${token.accessToken}") + } + } + }, + navigate = { viewModel.onIntent(Navigate(it)) }, ) } @Composable -fun AuthScreen() { -// Column( -// modifier = Modifier -// .fillMaxSize() -// .clickable { -// viewModel.navigationHelper.navigate( -// NavigationEvent.NavigateTo( -// route = MatchingGraph, -// popUpTo = AuthGraph, -// ) -// ) -// }, -// ) { -// Text( -// text = "카카오 로그인", -// fontSize = 30.sp, -// modifier = Modifier.clickable { -// UserApiClient.instance.loginWithKakaoAccount(context) { token, error -> -// if (error != null) { -// Log.e("test", "로그인 실패", error) -// } else if (token != null) { -// Log.i("test", "로그인 성공 ${token.accessToken}") -// } -// } -// } -// ) -// -// Text( -// text = "AuthRoute", -// fontSize = 30.sp, -// ) -// } +fun AuthScreen( + state: AuthState, + loginKakao: () -> Unit, + navigate: (NavigationEvent) -> Unit, +) { + Column( + modifier = Modifier + .fillMaxSize() + .clickable { + navigate( + NavigationEvent.NavigateTo( + route = AuthGraphDest.AuthRegistrationRoute, + popUpTo = AuthGraph, + ) + ) + }, + ) { + Text( + text = "카카오 로그인", + fontSize = 30.sp, + modifier = Modifier.clickable { loginKakao() }, + ) + + Text( + text = "AuthRoute", + fontSize = 30.sp, + ) + } } -//@Preview -//@Composable -//fun PreviewAuthScreen() { -// -//} \ No newline at end of file +@Preview +@Composable +fun PreviewAuthScreen() { + PieceTheme { + AuthScreen( + state = AuthState(), + loginKakao = {}, + navigate = {}, + ) + } +} \ No newline at end of file diff --git a/feature/auth/src/main/java/com/puzzle/auth/graph/main/AuthViewModel.kt b/feature/auth/src/main/java/com/puzzle/auth/graph/main/AuthViewModel.kt index 3e2b66da..26982fcf 100644 --- a/feature/auth/src/main/java/com/puzzle/auth/graph/main/AuthViewModel.kt +++ b/feature/auth/src/main/java/com/puzzle/auth/graph/main/AuthViewModel.kt @@ -4,16 +4,50 @@ import com.airbnb.mvrx.MavericksViewModel import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.hilt.AssistedViewModelFactory import com.airbnb.mvrx.hilt.hiltMavericksViewModelFactory +import com.puzzle.auth.graph.main.contract.AuthIntent +import com.puzzle.auth.graph.main.contract.AuthSideEffect import com.puzzle.auth.graph.main.contract.AuthState import com.puzzle.navigation.NavigationHelper import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.channels.Channel.Factory.BUFFERED +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.receiveAsFlow +import kotlinx.coroutines.launch class AuthViewModel @AssistedInject constructor( @Assisted initialState: AuthState, private val navigationHelper: NavigationHelper, ) : MavericksViewModel(initialState) { + private val intents = Channel(BUFFERED) + + private val _sideEffect = Channel(BUFFERED) + val sideEffect = _sideEffect.receiveAsFlow() + + init { + intents.receiveAsFlow() + .onEach(::processIntent) + .launchIn(viewModelScope) + } + + internal fun onIntent(intent: AuthIntent) = viewModelScope.launch { + intents.send(intent) + } + + private fun processIntent(intent: AuthIntent) { + when (intent) { + is AuthIntent.Navigate -> navigationHelper.navigate(intent.navigationEvent) + } + } + + private fun handleSideEffect(sideEffect: AuthSideEffect) { + when (sideEffect) { + else -> Unit + } + } @AssistedFactory interface Factory : AssistedViewModelFactory { diff --git a/feature/auth/src/main/java/com/puzzle/auth/graph/main/contract/AuthIntent.kt b/feature/auth/src/main/java/com/puzzle/auth/graph/main/contract/AuthIntent.kt index db5398f6..56d77be2 100644 --- a/feature/auth/src/main/java/com/puzzle/auth/graph/main/contract/AuthIntent.kt +++ b/feature/auth/src/main/java/com/puzzle/auth/graph/main/contract/AuthIntent.kt @@ -1,3 +1,7 @@ package com.puzzle.auth.graph.main.contract -class AuthIntent \ No newline at end of file +import com.puzzle.navigation.NavigationEvent + +sealed class AuthIntent { + data class Navigate(val navigationEvent: NavigationEvent) : AuthIntent() +} \ No newline at end of file diff --git a/feature/auth/src/main/java/com/puzzle/auth/graph/main/contract/AuthSideEffect.kt b/feature/auth/src/main/java/com/puzzle/auth/graph/main/contract/AuthSideEffect.kt index fcda07a5..60153de6 100644 --- a/feature/auth/src/main/java/com/puzzle/auth/graph/main/contract/AuthSideEffect.kt +++ b/feature/auth/src/main/java/com/puzzle/auth/graph/main/contract/AuthSideEffect.kt @@ -1,3 +1,3 @@ package com.puzzle.auth.graph.main.contract -class AuthSideEffect \ No newline at end of file +sealed class AuthSideEffect \ No newline at end of file diff --git a/feature/auth/src/main/java/com/puzzle/auth/graph/registration/AuthRegistrationScreen.kt b/feature/auth/src/main/java/com/puzzle/auth/graph/registration/AuthRegistrationRoute.kt similarity index 90% rename from feature/auth/src/main/java/com/puzzle/auth/graph/registration/AuthRegistrationScreen.kt rename to feature/auth/src/main/java/com/puzzle/auth/graph/registration/AuthRegistrationRoute.kt index b396ff44..06f6d6e5 100644 --- a/feature/auth/src/main/java/com/puzzle/auth/graph/registration/AuthRegistrationScreen.kt +++ b/feature/auth/src/main/java/com/puzzle/auth/graph/registration/AuthRegistrationRoute.kt @@ -6,7 +6,7 @@ import com.airbnb.mvrx.compose.collectAsState import com.airbnb.mvrx.compose.mavericksViewModel @Composable -internal fun AuthRegistrationScreen( +internal fun AuthRegistrationRoute( viewModel: AuthRegistrationViewModel = mavericksViewModel() ) { val state by viewModel.collectAsState() diff --git a/feature/auth/src/main/java/com/puzzle/auth/navigation/AuthNavigation.kt b/feature/auth/src/main/java/com/puzzle/auth/navigation/AuthNavigation.kt index f915be46..93eae177 100644 --- a/feature/auth/src/main/java/com/puzzle/auth/navigation/AuthNavigation.kt +++ b/feature/auth/src/main/java/com/puzzle/auth/navigation/AuthNavigation.kt @@ -4,6 +4,8 @@ import androidx.navigation.NavGraphBuilder import androidx.navigation.compose.composable import androidx.navigation.navigation import com.puzzle.auth.graph.main.AuthRoute +import com.puzzle.auth.graph.registration.AuthRegistrationRoute +import com.puzzle.auth.graph.verification.AuthVerificationRoute import com.puzzle.navigation.AuthGraph import com.puzzle.navigation.AuthGraphDest @@ -12,5 +14,13 @@ fun NavGraphBuilder.authNavGraph() { composable { AuthRoute() } + + composable { + AuthRegistrationRoute() + } + + composable { + AuthVerificationRoute() + } } } \ No newline at end of file