Skip to content

Commit 3da7e13

Browse files
committed
refactor :: viewmodel filter 값 수정
1 parent 6de88bc commit 3da7e13

File tree

3 files changed

+26
-34
lines changed

3 files changed

+26
-34
lines changed

feature/employment/src/main/java/team/retum/employment/ui/EmploymentDetailScreen.kt

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@ import androidx.compose.foundation.shape.RoundedCornerShape
1717
import androidx.compose.runtime.Composable
1818
import androidx.compose.runtime.LaunchedEffect
1919
import androidx.compose.runtime.getValue
20+
import androidx.compose.ui.Alignment
2021
import androidx.compose.ui.Modifier
2122
import androidx.compose.ui.draw.clip
2223
import androidx.compose.ui.draw.shadow
2324
import androidx.compose.ui.unit.dp
2425
import androidx.hilt.navigation.compose.hiltViewModel
2526
import androidx.lifecycle.compose.collectAsStateWithLifecycle
2627
import coil.compose.AsyncImage
27-
import team.retum.employment.model.CompanyItem
2828
import team.retum.employment.viewmodel.EmploymentDetailViewModel
2929
import team.retum.jobisdesignsystemv2.appbar.JobisSmallTopAppBar
3030
import team.retum.jobisdesignsystemv2.foundation.JobisTheme
3131
import team.retum.jobisdesignsystemv2.foundation.JobisTypography
3232
import team.retum.jobisdesignsystemv2.text.JobisText
33+
import team.retum.usecase.entity.application.EmploymentStatusEntity
34+
35+
const val MAX_STUDENT = 16
3336

3437
@Composable
3538
internal fun EmploymentDetail(
@@ -38,7 +41,7 @@ internal fun EmploymentDetail(
3841
employmentDetailViewModel: EmploymentDetailViewModel = hiltViewModel(),
3942
) {
4043
val state by employmentDetailViewModel.state.collectAsStateWithLifecycle()
41-
val classNameList = listOf("소프트웨어 1반", "소프트웨어 2반", "임베디드 3반", "인공지능 4반")
44+
val classNameList = listOf("소프트웨어 개발 1반", "소프트웨어 개발 2반", "임베디드 개발 3반", "인공지능 개발 4반")
4245

4346
LaunchedEffect(Unit) {
4447
with(employmentDetailViewModel) {
@@ -52,8 +55,8 @@ internal fun EmploymentDetail(
5255
classId = classId,
5356
passStudent = state.passStudent,
5457
totalStudent = state.totalStudent,
55-
companyList = state.companyInfo,
5658
classNameList = classNameList,
59+
classInfoList = state.classInfoList.toMutableList(),
5760
onBackPressed = onBackPressed,
5861
)
5962
}
@@ -63,8 +66,8 @@ private fun EmploymentDetailScreen(
6366
classId: Long,
6467
passStudent: Int,
6568
totalStudent: Int,
66-
companyList: List<CompanyItem>,
6769
classNameList: List<String>,
70+
classInfoList: MutableList<EmploymentStatusEntity.ClassEmploymentStatusEntity.GetEmploymentRateList>,
6871
onBackPressed: () -> Unit,
6972
) {
7073
Column(
@@ -82,24 +85,22 @@ private fun EmploymentDetailScreen(
8285
verticalArrangement = Arrangement.spacedBy(32.dp),
8386
contentPadding = PaddingValues(top = 32.dp, start = 24.dp, end = 24.dp, bottom = 24.dp),
8487
) {
85-
if (companyList.isNotEmpty()) {
86-
items(items = companyList) { company ->
87-
CompanyCard(
88-
imageUrl = company.logoUrl,
89-
companyName = company.companyName,
90-
)
91-
}
92-
} else {
93-
val list = List(totalStudent) {
94-
CompanyItem(
95-
companyName = "",
96-
logoUrl = "",
88+
classInfoList.apply {
89+
repeat(MAX_STUDENT - passStudent) {
90+
add(
91+
EmploymentStatusEntity.ClassEmploymentStatusEntity.GetEmploymentRateList(
92+
id = 0,
93+
companyName = "",
94+
logoUrl = "",
95+
),
9796
)
9897
}
99-
items(items = list) { company ->
98+
}
99+
if (classInfoList.isNotEmpty()) {
100+
items(items = classInfoList) { company ->
100101
CompanyCard(
101-
imageUrl = company.logoUrl,
102102
companyName = company.companyName,
103+
imageUrl = company.logoUrl,
103104
)
104105
}
105106
}
@@ -133,6 +134,8 @@ private fun CompanyCard(
133134
.background(color = JobisTheme.colors.inverseSurface),
134135
) {
135136
AsyncImage(
137+
modifier = Modifier
138+
.align(Alignment.Center),
136139
model = imageUrl,
137140
contentDescription = companyName,
138141
)

feature/employment/src/main/java/team/retum/employment/ui/EmploymentScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ private fun ClassEmploymentButton(
344344
) {
345345
Column(
346346
modifier = Modifier.background(color = JobisTheme.colors.inverseSurface),
347-
horizontalAlignment = Alignment.CenterHorizontally
347+
horizontalAlignment = Alignment.CenterHorizontally,
348348
) {
349349
Column(
350350
modifier = Modifier.padding(top = 20.dp, start = 34.dp, end = 34.dp),

feature/employment/src/main/java/team/retum/employment/viewmodel/EmploymentDetailViewModel.kt

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@ package team.retum.employment.viewmodel
22

33
import androidx.lifecycle.viewModelScope
44
import dagger.hilt.android.lifecycle.HiltViewModel
5-
import kotlinx.collections.immutable.ImmutableList
6-
import kotlinx.collections.immutable.persistentListOf
7-
import kotlinx.collections.immutable.toImmutableList
85
import kotlinx.coroutines.Dispatchers
96
import kotlinx.coroutines.launch
107
import team.retum.common.base.BaseViewModel
11-
import team.retum.employment.model.CompanyItem
8+
import team.retum.usecase.entity.application.EmploymentStatusEntity
129
import team.retum.usecase.usecase.application.FetchEmploymentStatusUseCase
1310
import javax.inject.Inject
1411

1512
@HiltViewModel
1613
internal class EmploymentDetailViewModel @Inject constructor(
1714
private val fetchEmploymentStatusUseCase: FetchEmploymentStatusUseCase,
1815
) : BaseViewModel<EmploymentDetailState, EmploymentDetailSideEffect>(EmploymentDetailState.getDefaultState()) {
19-
2016
internal fun setClassId(classId: Int) = setState {
2117
state.value.copy(classId = classId)
2218
}
@@ -39,14 +35,7 @@ internal class EmploymentDetailViewModel @Inject constructor(
3935
fetchEmploymentStatusUseCase().onSuccess {
4036
setState {
4137
state.value.copy(
42-
companyInfo = it.classes.flatMap { classInfo ->
43-
classInfo.employmentRateList.map { employmentRate ->
44-
CompanyItem(
45-
companyName = employmentRate.companyName,
46-
logoUrl = employmentRate.logoUrl,
47-
)
48-
}
49-
}.toImmutableList(),
38+
classInfoList = it.classes[state.value.classId].employmentRateList,
5039
)
5140
}
5241
}
@@ -58,14 +47,14 @@ internal data class EmploymentDetailState(
5847
val classId: Int,
5948
val totalStudent: Int,
6049
val passStudent: Int,
61-
val companyInfo: ImmutableList<CompanyItem>,
50+
val classInfoList: List<EmploymentStatusEntity.ClassEmploymentStatusEntity.GetEmploymentRateList>,
6251
) {
6352
companion object {
6453
fun getDefaultState() = EmploymentDetailState(
6554
classId = 0,
6655
totalStudent = 0,
6756
passStudent = 0,
68-
companyInfo = persistentListOf(),
57+
classInfoList = mutableListOf(),
6958
)
7059
}
7160
}

0 commit comments

Comments
 (0)