Skip to content

Commit

Permalink
[MOD/#323] 저장하기 버튼 활성화 기준 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyobeen-Park committed Jan 7, 2025
1 parent 38c0cce commit 6fb2d8a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ internal fun HomeFilteringBottomSheet(
val density = LocalDensity.current
var pageHeight by remember { mutableIntStateOf(0) }

var isCheckBoxChecked by remember {
mutableStateOf(
with(currentFilteringInfo) {
listOf(grade, workingPeriod, startYear, startMonth).all { it == null || it == 0 }
}
)
}

GetPagerHeight(
onHeightMeasured = {
pageHeight = it
Expand Down Expand Up @@ -137,6 +145,7 @@ internal fun HomeFilteringBottomSheet(
1 -> {
PlanFilteringScreen(
currentFilteringInfo = currentFilteringInfo,
isCheckBoxChecked = isCheckBoxChecked,
updateGrade = {
currentFilteringInfo = currentFilteringInfo.copy(
grade = if (it != null) {
Expand All @@ -161,6 +170,9 @@ internal fun HomeFilteringBottomSheet(
startMonth = it
)
},
updateIsCheckBoxChecked = {
isCheckBoxChecked = it
}
)
}
}
Expand All @@ -184,7 +196,10 @@ internal fun HomeFilteringBottomSheet(
)
}
},
isEnabled = checkButtonEnable(currentFilteringInfo = currentFilteringInfo)
isEnabled = checkButtonEnable(
currentFilteringInfo = currentFilteringInfo,
isCheckBoxChecked = isCheckBoxChecked
)
)
}

Expand Down Expand Up @@ -238,10 +253,12 @@ fun TerningTab(
}
}

private fun checkButtonEnable(currentFilteringInfo: HomeFilteringInfo): Boolean =
private fun checkButtonEnable(
currentFilteringInfo: HomeFilteringInfo,
isCheckBoxChecked: Boolean
): Boolean =
with(currentFilteringInfo) {
listOf(grade, workingPeriod, startYear, startMonth).all { it == null || it == 0 } ||
listOf(grade, workingPeriod, startYear, startMonth).none { it == null || it == 0 }
isCheckBoxChecked || listOf(grade, workingPeriod, startYear, startMonth).none { it == null }
}

@Composable
Expand All @@ -250,6 +267,7 @@ private fun GetPagerHeight(
) {
PlanFilteringScreen(
currentFilteringInfo = HomeFilteringInfo(null, null, null, null, "total"),
isCheckBoxChecked = false,
modifier = Modifier
.onGloballyPositioned {
onHeightMeasured(it.size.height)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,17 @@ import kotlinx.collections.immutable.toImmutableList
@Composable
internal fun PlanFilteringScreen(
currentFilteringInfo: HomeFilteringInfo,
isCheckBoxChecked: Boolean,
modifier: Modifier = Modifier,
updateGrade: (Int?) -> Unit = {},
updateWorkingPeriod: (Int?) -> Unit = {},
updateStartYear: (Int?) -> Unit = {},
updateStartMonth: (Int?) -> Unit = {},
updateIsCheckBoxChecked: (Boolean) -> Unit = {},
) {
var isYearNull by remember { mutableStateOf(currentFilteringInfo.startYear == 0 || currentFilteringInfo.startYear == null) }
var isMonthNull by remember { mutableStateOf(currentFilteringInfo.startMonth == 0 || currentFilteringInfo.startMonth == null) }

var isCheckBoxChecked by remember {
mutableStateOf(
with(currentFilteringInfo) {
listOf(grade, workingPeriod, startYear, startMonth).all { it == null || it == 0 }
}
)
}

var isInitialNullState by remember { mutableStateOf(false) }

val yearsList by remember(isYearNull) {
Expand Down Expand Up @@ -99,7 +93,7 @@ internal fun PlanFilteringScreen(
).toImmutableList(),
onButtonClick = {
updateGrade(it)
isCheckBoxChecked = false
updateIsCheckBoxChecked(false)
},
columns = 4,
modifier = Modifier
Expand All @@ -124,7 +118,7 @@ internal fun PlanFilteringScreen(
).toImmutableList(),
onButtonClick = {
updateWorkingPeriod(it)
isCheckBoxChecked = false
updateIsCheckBoxChecked(false)
},
modifier = Modifier
.padding(horizontal = 23.dp),
Expand All @@ -142,15 +136,15 @@ internal fun PlanFilteringScreen(
onYearChosen = { year, isInitialSelection ->
updateStartYear(year)
if (year != null) {
isCheckBoxChecked = false
updateIsCheckBoxChecked(false)
isYearNull = false
isInitialNullState = isInitialSelection
}
},
onMonthChosen = { month, isInitialSelection ->
updateStartMonth(month)
if (month != null) {
isCheckBoxChecked = false
updateIsCheckBoxChecked(false)
isMonthNull = false
isInitialNullState = isInitialSelection
}
Expand Down Expand Up @@ -185,7 +179,7 @@ internal fun PlanFilteringScreen(
updateStartYear(null)
updateStartMonth(null)
}
isCheckBoxChecked = isChecked
updateIsCheckBoxChecked(isChecked)
},
colors = CheckboxDefaults.colors(
checkedColor = TerningMain,
Expand Down

0 comments on commit 6fb2d8a

Please sign in to comment.