Skip to content

Commit

Permalink
[chore] : #8 MyPage API 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
1971123-seongmin committed Nov 13, 2024
1 parent 34a6dcb commit b4d30d0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import org.sopt.and.ui.theme.White

@Composable
fun MyPageScreen(
email: String
myHobby: String
) {
Column(
modifier = Modifier
Expand All @@ -56,7 +56,7 @@ fun MyPageScreen(
.background(color = Gray300)
) {
// 컴포넌트 - 프로필 row
MyProfileRow(email)
MyProfileRow(myHobby)

// 인증하기 >
MyPageActionText(
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String>("")
val userHobby: StateFlow<String> = _userHobby

init {
geyMyHobby()
}

private fun geyMyHobby() {
viewModelScope.launch {
geyMyHobbyUseCase().onSuccess {
_userHobby.value = it.hobby
}
}
}
}

0 comments on commit b4d30d0

Please sign in to comment.