diff --git a/app/src/main/java/org/sopt/and/presentation/navigation/Navigation.kt b/app/src/main/java/org/sopt/and/presentation/navigation/Navigation.kt index 1b2ac34..60562c3 100644 --- a/app/src/main/java/org/sopt/and/presentation/navigation/Navigation.kt +++ b/app/src/main/java/org/sopt/and/presentation/navigation/Navigation.kt @@ -1,6 +1,7 @@ package org.sopt.and.presentation.navigation import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding import androidx.compose.material3.Scaffold import androidx.compose.material3.SnackbarHostState import androidx.compose.runtime.Composable @@ -14,6 +15,7 @@ import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.navArgument import org.sopt.and.presentation.ui.home.HomeScreen +import org.sopt.and.presentation.ui.mypage.MyPageRoute import org.sopt.and.presentation.ui.mypage.MyPageScreen import org.sopt.and.presentation.ui.search.SearchScreen import org.sopt.and.presentation.ui.signin.SignInRoute @@ -30,11 +32,13 @@ fun Navigation( ) { Scaffold ( modifier = Modifier.fillMaxSize() - ) { - + ) { paddingValues -> NavHost( navController = navController, - startDestination = Routes.SignInScreen.route + startDestination = Routes.SignInScreen.route, + modifier = Modifier + .fillMaxSize() + .padding(paddingValues) ) { composable(Routes.SignInScreen.route) { SignInRoute( @@ -51,10 +55,9 @@ fun Navigation( composable( Routes.MyPageScreen.route, - arguments = listOf(navArgument("email") { type = NavType.StringType }) - ) { backStackEntry -> - val email = backStackEntry.arguments?.getString("email") ?: "" - MyPageScreen(email = email) + + ) { + MyPageRoute() } composable(Routes.SearchScreen.route) { diff --git a/app/src/main/java/org/sopt/and/presentation/ui/mypage/MyPageRoute.kt b/app/src/main/java/org/sopt/and/presentation/ui/mypage/MyPageRoute.kt new file mode 100644 index 0000000..b972dd1 --- /dev/null +++ b/app/src/main/java/org/sopt/and/presentation/ui/mypage/MyPageRoute.kt @@ -0,0 +1,16 @@ +package org.sopt.and.presentation.ui.mypage + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import org.sopt.and.presentation.viewmodel.MyPageViewModel + +@Composable +fun MyPageRoute( + viewModel: MyPageViewModel = hiltViewModel() +) { + val userHobby by viewModel.userHobby.collectAsStateWithLifecycle() + + MyPageScreen(userHobby) +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/and/presentation/ui/mypage/MyPageScreen.kt b/app/src/main/java/org/sopt/and/presentation/ui/mypage/MyPageScreen.kt index c33f65b..b3fa50f 100644 --- a/app/src/main/java/org/sopt/and/presentation/ui/mypage/MyPageScreen.kt +++ b/app/src/main/java/org/sopt/and/presentation/ui/mypage/MyPageScreen.kt @@ -41,7 +41,7 @@ import org.sopt.and.ui.theme.White @Composable fun MyPageScreen( - email: String + myHobby: String ) { Column( modifier = Modifier @@ -56,7 +56,7 @@ fun MyPageScreen( .background(color = Gray300) ) { // 컴포넌트 - 프로필 row - MyProfileRow(email) + MyProfileRow(myHobby) // 인증하기 > MyPageActionText( diff --git a/app/src/main/java/org/sopt/and/presentation/viewmodel/MyPageViewModel.kt b/app/src/main/java/org/sopt/and/presentation/viewmodel/MyPageViewModel.kt new file mode 100644 index 0000000..8afaedb --- /dev/null +++ b/app/src/main/java/org/sopt/and/presentation/viewmodel/MyPageViewModel.kt @@ -0,0 +1,31 @@ +package org.sopt.and.presentation.viewmodel + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.launch +import org.sopt.and.domain.usecase.user.GetMyHobbyUseCase +import javax.inject.Inject + +@HiltViewModel +class MyPageViewModel @Inject constructor( + private val geyMyHobbyUseCase: GetMyHobbyUseCase +) : ViewModel() { + + private val _userHobby = MutableStateFlow("") + val userHobby: StateFlow = _userHobby + + init { + geyMyHobby() + } + + private fun geyMyHobby() { + viewModelScope.launch { + geyMyHobbyUseCase().onSuccess { + _userHobby.value = it.hobby + } + } + } +} \ No newline at end of file