Skip to content

Commit

Permalink
[CHORE] #59 : 작성한 설문 리스트에 더하는 로직 ViewModel로 Migration,
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjaino committed Dec 22, 2023
1 parent 7441c37 commit 9c90d87
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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 = "" }

Expand Down

0 comments on commit 9c90d87

Please sign in to comment.