Skip to content

Commit

Permalink
[REFACTOR] #95 : 이전 질문, 이후 질문, 질문 추가하기, 다음 버튼 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjaino committed Jan 31, 2024
1 parent aefdaac commit 13cc8bc
Showing 1 changed file with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ internal fun SurveyRegistrationScreen(
val currentRegistrationState =
viewModel.currentSurveyFormState.collectAsStateWithLifecycle().value
val eventList = viewModel.eventList.collectAsStateWithLifecycle().value
val eventSelection = viewModel.surveyEventSelection.collectAsStateWithLifecycle().value
val eventSelection = viewModel.eventSelection.collectAsStateWithLifecycle().value
val title = viewModel.surveyTitle.collectAsStateWithLifecycle().value
val content = viewModel.surveyContent.collectAsStateWithLifecycle().value
val questionTitle = viewModel.surveyQuestionTitle.collectAsStateWithLifecycle().value
val questionType = viewModel.surveyQuestionType.collectAsStateWithLifecycle().value
val questionNumber = viewModel.surveyQuestionNumber.collectAsStateWithLifecycle().value
val questionTitle = viewModel.questionTitle.collectAsStateWithLifecycle().value
val questionType = viewModel.questionType.collectAsStateWithLifecycle().value
val currentQuestionNumber = viewModel.currentQuestionNumber.collectAsStateWithLifecycle().value
val totalQuestionNumber =
viewModel.surveyQuestionTotalNumber.collectAsStateWithLifecycle().value
val time = viewModel.surveyTimeDeadline.collectAsStateWithLifecycle().value
val date = viewModel.surveyDateDeadline.collectAsStateWithLifecycle().value
viewModel.totalQuestionNumber.collectAsStateWithLifecycle().value
val questionList = viewModel.questionList.collectAsStateWithLifecycle().value
val timeDeadline = viewModel.timeDeadline.collectAsStateWithLifecycle().value
val dateDeadline = viewModel.dateDeadline.collectAsStateWithLifecycle().value
val snackBarHostState = remember { SnackbarHostState() }
val timePickerState = rememberTimePickerState()
var showDatePicker by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -106,12 +107,12 @@ internal fun SurveyRegistrationScreen(
content = content,
question = questionTitle,
questionType = questionType,
date = date,
time = time,
dateDeadline = dateDeadline,
timeDeadline = timeDeadline,
timePickerState = timePickerState,
showDatePicker = showDatePicker,
showTimePicker = showTimePicker,
questionNumber = questionNumber,
currentQuestionNumber = currentQuestionNumber,
totalQuestionNumber = totalQuestionNumber,
onDatePickerStateChanged = { state -> showDatePicker = state },
onTimePickerStateChanged = { state -> showTimePicker = state },
Expand All @@ -123,23 +124,23 @@ internal fun SurveyRegistrationScreen(
onQuestionTypeChanged = { questionType ->
viewModel.setSurveyQuestionType(questionType)
},
onNextQuestionButtonClicked = {
onNextQuestionButtonClicked = { // '>' 버튼
if (viewModel.validateSurveyForm(SurveyFormState.QUESTION).not()) {
return@SurveyFormContent // 답변 검증
return@SurveyFormContent
}

viewModel.editSurveyQuestion() // 답변 수정

viewModel.setNextQuestionNumber() // 다음 질문 불러오기
viewModel.setQuestion()
},
onPreviousQuestionButtonClicked = {
onPreviousQuestionButtonClicked = { // '<' 버튼
if (viewModel.validateSurveyForm(SurveyFormState.QUESTION).not()) {
return@SurveyFormContent
}

// 다른 질문으로 넘어가기 전, 상태 저장
if (questionNumber == totalQuestionNumber) {
// 다른 질문으로 넘어가기 전, 질문 추가 혹은 저장
if (currentQuestionNumber == questionList.size) {
viewModel.addSurveyQuestion()
} else {
viewModel.editSurveyQuestion()
Expand All @@ -148,28 +149,35 @@ internal fun SurveyRegistrationScreen(
viewModel.setPreviousQuestionNumber() // 이전 질문 불러오기
viewModel.setQuestion()
},
onAddQuestionButtonClicked = {
if (viewModel.validateSurveyForm(SurveyFormState.QUESTION)) {
viewModel.addSurveyQuestion()
onAddQuestionButtonClicked = { // 문항 추가 버튼
if (viewModel.validateSurveyForm(SurveyFormState.QUESTION).not()) {
return@SurveyFormContent
}
viewModel.setLastQuestionNumber()

if (currentQuestionNumber == questionList.size) {
viewModel.addSurveyQuestion() // 질문 추가
} else {
viewModel.editSurveyQuestion()
}

viewModel.setLastQuestion()
},
onDateChanged = viewModel::setSurveyDateDeadline,
onTimeChanged = { localTime -> viewModel.setSurveyTimeDeadline(localTime) },
onPreviousButtonClicked = { previousState ->
onPreviousButtonClicked = { previousState -> // 이전 버튼
if (previousState == SurveyFormState.QUESTION) {
viewModel.setSurveyQuestionFromQuestionList()
}

viewModel.setSurveyFormState(previousState)
},
onNextButtonClicked = { currentState, nextState ->
onNextButtonClicked = { currentState, nextState -> // 다음 버튼
if (viewModel.validateSurveyForm(currentState).not()) {
return@SurveyFormContent
}

if (currentState == SurveyFormState.QUESTION) {
if (questionNumber == totalQuestionNumber) {
if (currentQuestionNumber == questionList.size) { // 마지막 질문인 경우
viewModel.addSurveyQuestion()
} else {
viewModel.editSurveyQuestion()
Expand Down

0 comments on commit 13cc8bc

Please sign in to comment.