From 50ec6e89fda9f33612e761b69c17ae2d12e26132 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Tue, 30 Jan 2024 21:54:20 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]=20#94=20:=20=EB=A7=88=EC=A7=80=EB=A7=89?= =?UTF-8?q?=20=EC=A7=88=EB=AC=B8=20=EC=83=81=ED=83=9C=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=B2=84=EA=B7=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feature/survey/answer/SurveyAnswerForm.kt | 20 +++++++++++-------- .../survey/answer/SurveyAnswerScreen.kt | 17 +++++++++++++--- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerForm.kt b/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerForm.kt index dc420784..61582b85 100644 --- a/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerForm.kt +++ b/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerForm.kt @@ -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), ) } @@ -79,8 +82,8 @@ internal fun SurveyAnswerForm( @Composable private fun SurveyAnswerButton( isLastQuestion: Boolean, - onButtonClicked: () -> Unit, isEnabled: Boolean, + onButtonClicked: () -> Unit, modifier: Modifier, ) { if (isLastQuestion) { @@ -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 } diff --git a/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerScreen.kt b/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerScreen.kt index bd9dbc10..563827d6 100644 --- a/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerScreen.kt +++ b/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerScreen.kt @@ -90,7 +90,7 @@ internal fun SurveyAnswerScreen( }, onNextQuestionButtonClicked = { if (questionNumber < surveyAnswerList.size) { // 작성한 답변을 수정하는 경우 - viewModel.modifySurveyAnswer() + viewModel.editSurveyAnswer() } else { viewModel.addSurveyAnswer() } @@ -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)