diff --git a/feature/src/main/java/com/terning/feature/home/changefilter/ChangeFilterRoute.kt b/feature/src/main/java/com/terning/feature/home/changefilter/ChangeFilterRoute.kt index 68d943f10..f40269b95 100644 --- a/feature/src/main/java/com/terning/feature/home/changefilter/ChangeFilterRoute.kt +++ b/feature/src/main/java/com/terning/feature/home/changefilter/ChangeFilterRoute.kt @@ -165,7 +165,7 @@ fun ChangeFilterScreen( Spacer(modifier = Modifier.weight(1f)) DatePickerUI( chosenYear = filterData.startYear ?: currentStartYear, - chosenMonth = filterData.startMonth ?: currentStartMonth, + chosenMonth = filterData.startMonth?.minus(1) ?: currentStartMonth, onYearChosen = { currentStartYear = it }, onMonthChosen = { currentStartMonth = it } ) diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt index 2f6988208..c698a4254 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt @@ -42,7 +42,6 @@ import com.terning.core.designsystem.component.topappbar.LogoTopAppBar import com.terning.core.designsystem.theme.Black import com.terning.core.designsystem.theme.Grey150 import com.terning.core.designsystem.theme.Grey200 -import com.terning.core.designsystem.theme.TerningMain import com.terning.core.designsystem.theme.TerningTheme import com.terning.core.designsystem.theme.White import com.terning.core.extension.customShadow @@ -89,6 +88,7 @@ fun HomeRoute( val homeTodayState by viewModel.homeTodayState.collectAsStateWithLifecycle() val homeRecommendInternState by viewModel.homeRecommendInternState.collectAsStateWithLifecycle() val homeFilteringState by viewModel.homeFilteringState.collectAsStateWithLifecycle() + val homeUserState by viewModel.homeUserState.collectAsStateWithLifecycle() LaunchedEffect(viewModel.homeSideEffect, lifecycleOwner) { viewModel.homeSideEffect.flowWithLifecycle(lifecycle = lifecycleOwner.lifecycle) @@ -101,6 +101,21 @@ fun HomeRoute( } } + LaunchedEffect(currentSortBy.value) { + when (homeFilteringState) { + is UiState.Success -> + with((homeFilteringState as UiState.Success).data) { + viewModel.getRecommendInternsData( + currentSortBy.value, + startYear ?: viewModel.currentYear, + startMonth ?: viewModel.currentMonth + ) + } + + else -> {} + } + } + val homeTodayInternList = when (homeTodayState) { is UiState.Success -> { (homeTodayState as UiState.Success>).data @@ -122,8 +137,14 @@ fun HomeRoute( else -> HomeFilteringInfoModel(null, null, viewModel.currentYear, viewModel.currentMonth) } + val homeUserName = when (homeUserState) { + is UiState.Success -> (homeUserState as UiState.Success).data + else -> "" + } + HomeScreen( currentSortBy, + homeUserName = homeUserName, homeFilteringInfo = homeFilteringInfo, homeTodayInternList = homeTodayInternList, recommendInternList = homeRecommendInternList, @@ -135,6 +156,7 @@ fun HomeRoute( @Composable fun HomeScreen( currentSortBy: MutableState, + homeUserName: String, homeFilteringInfo: HomeFilteringInfoModel, homeTodayInternList: List, recommendInternList: List, @@ -175,7 +197,7 @@ fun HomeScreen( modifier = Modifier .padding(bottom = 16.dp) ) { - ShowMainTitleWithName("남지우자랑스러운티엘이되") + ShowMainTitleWithName(homeUserName) ShowTodayIntern(homeTodayInternList = homeTodayInternList) } } diff --git a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt index 443ab177d..36dc99c51 100644 --- a/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt +++ b/feature/src/main/java/com/terning/feature/home/home/HomeViewModel.kt @@ -8,6 +8,7 @@ import com.terning.domain.entity.response.HomeFilteringInfoModel import com.terning.domain.entity.response.HomeRecommendInternModel import com.terning.domain.entity.response.HomeTodayInternModel import com.terning.domain.repository.HomeRepository +import com.terning.domain.repository.MyPageRepository import com.terning.feature.R import com.terning.feature.home.home.model.SortBy import dagger.hilt.android.lifecycle.HiltViewModel @@ -22,6 +23,7 @@ import javax.inject.Inject @HiltViewModel class HomeViewModel @Inject constructor( private val homeRepository: HomeRepository, + private val myPageRepository: MyPageRepository, ) : ViewModel() { val currentYear = Calendar.getInstance().get(Calendar.YEAR) val currentMonth = Calendar.getInstance().get(Calendar.MONTH) @@ -44,7 +46,11 @@ class HomeViewModel @Inject constructor( private val _homeSortByState = MutableStateFlow(0) val homeSortByState get() = _homeSortByState.asStateFlow() + private val _homeUserState = MutableStateFlow>(UiState.Loading) + val homeUserState get() = _homeUserState.asStateFlow() + init { + getProfile() getFilteringInfo() getHomeTodayInternList() getRecommendInternsData( @@ -100,4 +106,15 @@ class HomeViewModel @Inject constructor( } } } + + private fun getProfile() { + viewModelScope.launch { + myPageRepository.getProfile().onSuccess { response -> + _homeUserState.value = UiState.Success(response.name) + }.onFailure { exception: Throwable -> + _homeUserState.value = UiState.Failure(exception.message ?: "") + _homeSideEffect.emit(HomeSideEffect.ShowToast(R.string.server_failure)) + } + } + } } \ No newline at end of file