Skip to content

Commit

Permalink
[FIX] #94 : 마지막 질문 상태 저장되지 않는 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjaino committed Jan 30, 2024
1 parent 2a8e2dc commit 50ec6e8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,23 @@ internal fun SurveyAnswerForm(
}
}

val isFirstQuestion = questionNumber > 0
val isGreaterThanFirstQuestion = questionNumber > 0
val isLastQuestion = questionNumber == lastQuestionNumber // 마지막 응답일 경우, 완료로 변경
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
WappButton(
textRes = R.string.previous,
onClick = onPreviousQuestionButtonClicked,
isEnabled = isFirstQuestion,
isEnabled = isGreaterThanFirstQuestion,
modifier = Modifier.weight(1f),
)

SurveyAnswerButton(
isLastQuestion = isLastQuestion,
onButtonClicked = onNextQuestionButtonClicked,
isEnabled = isButtonEnabled(surveyQuestion.questionType, subjectiveAnswer),
isEnabled = checkQuestionTypeAndSubjectiveAnswer(
questionType = surveyQuestion.questionType,
subjectiveAnswer = subjectiveAnswer,
),
modifier = Modifier.weight(1f),
)
}
Expand All @@ -79,8 +82,8 @@ internal fun SurveyAnswerForm(
@Composable
private fun SurveyAnswerButton(
isLastQuestion: Boolean,
onButtonClicked: () -> Unit,
isEnabled: Boolean,
onButtonClicked: () -> Unit,
modifier: Modifier,
) {
if (isLastQuestion) {
Expand All @@ -100,11 +103,12 @@ private fun SurveyAnswerButton(
}
}

private fun isButtonEnabled(
private fun checkQuestionTypeAndSubjectiveAnswer(
questionType: QuestionType,
subjectiveAnswer: String,
): Boolean {
if (questionType == QuestionType.SUBJECTIVE) return subjectiveAnswer.length >= 10

return true
if (questionType == QuestionType.OBJECTIVE) {
return true
}
return subjectiveAnswer.length >= 10
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal fun SurveyAnswerScreen(
},
onNextQuestionButtonClicked = {
if (questionNumber < surveyAnswerList.size) { // 작성한 답변을 수정하는 경우
viewModel.modifySurveyAnswer()
viewModel.editSurveyAnswer()
} else {
viewModel.addSurveyAnswer()
}
Expand All @@ -102,9 +102,20 @@ internal fun SurveyAnswerScreen(
return@SurveyAnswerContent
}

viewModel.setNextQuestionNumber() // 다음 질문 불러오기
viewModel.setNextQuestionAndAnswer() // 다음 질문 불러오기
},
onPreviousQuestionButtonClicked = {
val lastQuestionNumber =
surveyFormUiState.surveyForm.surveyQuestionList.lastIndex
// 마지막 질문이면서, 응답의 갯수가 질문의 갯수보다 작은 경우
if (questionNumber == lastQuestionNumber &&
surveyAnswerList.lastIndex < lastQuestionNumber
) {
viewModel.addSurveyAnswer()
}

viewModel.setPreviousQuestionAndAnswer()
},
onPreviousQuestionButtonClicked = { viewModel.setPreviousQuestion() },
modifier = Modifier
.fillMaxSize()
.padding(paddingValues)
Expand Down

0 comments on commit 50ec6e8

Please sign in to comment.