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 a0af8c76..acaadf29 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 @@ -95,14 +95,8 @@ internal fun SurveyAnswerScreen( onSubjectiveAnswerChanged = viewModel::setSubjectiveAnswer, onObjectiveAnswerSelected = viewModel::setObjectiveAnswer, onNextButtonClicked = { - viewModel.setSurveyAnswer() // 응답 저장 - - if (questionNumber == lastQuestionNumber) { // 마지막 질문일 경우 제출 - viewModel.submitSurvey() - return@SurveyAnswerForm - } - - viewModel.setNextQuestionNumber() // 다음 질문 넘기기 + viewModel.addSurveyAnswer() + viewModel.setNextQuestion() }, ) } diff --git a/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerViewModel.kt b/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerViewModel.kt index d08c9405..0ff9897b 100644 --- a/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerViewModel.kt +++ b/feature/survey/src/main/java/com/wap/wapp/feature/survey/answer/SurveyAnswerViewModel.kt @@ -54,12 +54,7 @@ class SurveyAnswerViewModel @Inject constructor( } } - fun submitSurvey() { - viewModelScope.launch { - } - } - - fun setSurveyAnswer() { + fun addSurveyAnswer() { val questionNumber = _questionNumber.value val surveyQuestion = _surveyForm.value.surveyQuestionList[questionNumber] @@ -88,11 +83,29 @@ class SurveyAnswerViewModel @Inject constructor( } } + fun setNextQuestion() { + val currentQuestionNumber = _questionNumber.value + val lastQuestionNumber = surveyAnswerList.value.size + + if(currentQuestionNumber == lastQuestionNumber) { // 마지막 질문일 경우 제출 + submitSurvey() + return + } + + addQuestionNumber() // 다음 질문 넘기기 + } + + private fun submitSurvey() { + viewModelScope.launch { + + } + } + fun setSubjectiveAnswer(answer: String) { _subjectiveAnswer.value = answer } fun setObjectiveAnswer(answer: Rating) { _objectiveAnswer.value = answer } - fun setNextQuestionNumber() { _questionNumber.value += 1 } + private fun addQuestionNumber() { _questionNumber.value += 1 } private fun clearSubjectiveAnswer() { _subjectiveAnswer.value = "" }