Skip to content

Commit

Permalink
[MERGE] #122 -> develop
Browse files Browse the repository at this point in the history
[FEAT/#122] 홈 뷰 / 공고 정렬 기준 변경 구현
  • Loading branch information
Hyobeen-Park authored Jul 18, 2024
2 parents defac4e + b43b562 commit 3b3ac7f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
)
Expand Down
26 changes: 24 additions & 2 deletions feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -101,6 +101,21 @@ fun HomeRoute(
}
}

LaunchedEffect(currentSortBy.value) {
when (homeFilteringState) {
is UiState.Success ->
with((homeFilteringState as UiState.Success<HomeFilteringInfoModel>).data) {
viewModel.getRecommendInternsData(
currentSortBy.value,
startYear ?: viewModel.currentYear,
startMonth ?: viewModel.currentMonth
)
}

else -> {}
}
}

val homeTodayInternList = when (homeTodayState) {
is UiState.Success -> {
(homeTodayState as UiState.Success<List<HomeTodayInternModel>>).data
Expand All @@ -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<String>).data
else -> ""
}

HomeScreen(
currentSortBy,
homeUserName = homeUserName,
homeFilteringInfo = homeFilteringInfo,
homeTodayInternList = homeTodayInternList,
recommendInternList = homeRecommendInternList,
Expand All @@ -135,6 +156,7 @@ fun HomeRoute(
@Composable
fun HomeScreen(
currentSortBy: MutableState<Int>,
homeUserName: String,
homeFilteringInfo: HomeFilteringInfoModel,
homeTodayInternList: List<HomeTodayInternModel>,
recommendInternList: List<HomeRecommendInternModel>,
Expand Down Expand Up @@ -175,7 +197,7 @@ fun HomeScreen(
modifier = Modifier
.padding(bottom = 16.dp)
) {
ShowMainTitleWithName("남지우자랑스러운티엘이되")
ShowMainTitleWithName(homeUserName)
ShowTodayIntern(homeTodayInternList = homeTodayInternList)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -44,7 +46,11 @@ class HomeViewModel @Inject constructor(
private val _homeSortByState = MutableStateFlow(0)
val homeSortByState get() = _homeSortByState.asStateFlow()

private val _homeUserState = MutableStateFlow<UiState<String>>(UiState.Loading)
val homeUserState get() = _homeUserState.asStateFlow()

init {
getProfile()
getFilteringInfo()
getHomeTodayInternList()
getRecommendInternsData(
Expand Down Expand Up @@ -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))
}
}
}
}

0 comments on commit 3b3ac7f

Please sign in to comment.