From 9c90d87a0f228054f163775c3bb8c25b6a63bc31 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Fri, 22 Dec 2023 12:57:53 +0900 Subject: [PATCH] =?UTF-8?q?[CHORE]=20#59=20:=20=EC=9E=91=EC=84=B1=ED=95=9C?= =?UTF-8?q?=20=EC=84=A4=EB=AC=B8=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=EC=97=90=20?= =?UTF-8?q?=EB=8D=94=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=20ViewModel?= =?UTF-8?q?=EB=A1=9C=20Migration,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../survey/answer/SurveyAnswerScreen.kt | 10 ++----- .../survey/answer/SurveyAnswerViewModel.kt | 27 ++++++++++++++----- 2 files changed, 22 insertions(+), 15 deletions(-) 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 = "" }