Skip to content

Commit

Permalink
[FEATURE] #95 : 질문 순서 변경 (빠른 #94 핫픽스를 위한 중간 커밋)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjaino committed Jan 30, 2024
1 parent ddf6401 commit 1c0fe5b
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 144 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.wap.wapp.feature.management.survey

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.TimePickerState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.wap.wapp.core.model.event.Event
import com.wap.wapp.core.model.survey.QuestionType
import com.wap.wapp.feature.management.survey.registration.SurveyFormRegistrationViewModel
Expand All @@ -24,97 +21,103 @@ internal fun SurveyFormContent(
questionType: QuestionType,
time: LocalTime,
date: LocalDate,
currentQuestionIndex: Int,
totalQuestionSize: Int,
questionNumber: Int,
totalQuestionNumber: Int,
timePickerState: TimePickerState,
showDatePicker: Boolean,
showTimePicker: Boolean,
onDateChanged: (LocalDate) -> Unit,
onDatePickerStateChanged: (Boolean) -> Unit,
onTimePickerStateChanged: (Boolean) -> Unit,
onEventListChanged: () -> Unit,
onEventContentInitialized: () -> Unit,
onEventSelected: (Event) -> Unit,
onTitleChanged: (String) -> Unit,
onContentChanged: (String) -> Unit,
onQuestionChanged: (String) -> Unit,
onQuestionTypeChanged: (QuestionType) -> Unit,
onPreviousQuestionButtonClicked: () -> Unit,
onNextQuestionButtonClicked: () -> Unit,
onTimeChanged: (LocalTime) -> Unit,
onPreviousButtonClicked: (SurveyFormState) -> Unit, // previousState
onNextButtonClicked: (SurveyFormState, SurveyFormState) -> Unit, // (currentState, nextState)
onAddQuestionButtonClicked: () -> Unit,
onRegisterButtonClicked: () -> Unit,
modifier: Modifier = Modifier,
) {
Column(
modifier = modifier.fillMaxSize(),
) {
when (surveyRegistrationState) {
SurveyFormState.EVENT_SELECTION -> {
onEventListChanged()
SurveyEventContent(
eventsState = eventsState,
selectedEvent = eventSelection,
onEventSelected = onEventSelected,
onNextButtonClicked = {
onNextButtonClicked(
SurveyFormState.EVENT_SELECTION,
SurveyFormState.INFORMATION,
)
},
modifier = Modifier
.fillMaxSize()
.weight(1f),
)
}
when (surveyRegistrationState) {
SurveyFormState.EVENT_SELECTION -> {
onEventContentInitialized()
SurveyEventContent(
eventsState = eventsState,
selectedEvent = eventSelection,
onEventSelected = onEventSelected,
onNextButtonClicked = {
onNextButtonClicked(
SurveyFormState.EVENT_SELECTION,
SurveyFormState.INFORMATION,
)
},
)
}

SurveyFormState.INFORMATION -> {
SurveyInformationContent(
title = title,
onTitleChanged = onTitleChanged,
content = content,
onContentChanged = onContentChanged,
onNextButtonClicked = {
onNextButtonClicked(
SurveyFormState.INFORMATION,
SurveyFormState.QUESTION,
)
},
)
}
SurveyFormState.INFORMATION -> {
SurveyInformationContent(
title = title,
onTitleChanged = onTitleChanged,
content = content,
onContentChanged = onContentChanged,
onPreviousButtonClicked = {
onPreviousButtonClicked(SurveyFormState.EVENT_SELECTION)
},
onNextButtonClicked = {
onNextButtonClicked(
SurveyFormState.INFORMATION,
SurveyFormState.QUESTION,
)
},
)
}

SurveyFormState.QUESTION -> {
SurveyQuestionContent(
question = question,
questionType = questionType,
onQuestionTypeChanged = { defaultQuestionType ->
onQuestionTypeChanged(defaultQuestionType)
},
onQuestionChanged = onQuestionChanged,
onAddSurveyQuestionButtonClicked = onAddQuestionButtonClicked,
currentQuestionIndex = currentQuestionIndex,
totalQuestionIndex = totalQuestionSize,
onNextButtonClicked = {
onNextButtonClicked(
SurveyFormState.QUESTION,
SurveyFormState.DEADLINE,
)
},
)
}
SurveyFormState.QUESTION -> {
SurveyQuestionContent(
question = question,
questionType = questionType,
onQuestionTypeChanged = { defaultQuestionType ->
onQuestionTypeChanged(defaultQuestionType)
},
onQuestionChanged = onQuestionChanged,
onAddSurveyQuestionButtonClicked = onAddQuestionButtonClicked,
questionNumber = questionNumber,
totalQuestionNumber = totalQuestionNumber,
onPreviousButtonClicked = {
onPreviousButtonClicked(SurveyFormState.INFORMATION)
},
onNextButtonClicked = {
onNextButtonClicked(
SurveyFormState.QUESTION,
SurveyFormState.DEADLINE,
)
},
onPreviousQuestionButtonClicked = onPreviousQuestionButtonClicked,
onNextQuestionButtonClicked = onNextQuestionButtonClicked,
)
}

SurveyFormState.DEADLINE -> {
SurveyDeadlineContent(
time = time,
date = date,
timePickerState = timePickerState,
showDatePicker = showDatePicker,
showTimePicker = showTimePicker,
onDateChanged = onDateChanged,
onTimePickerStateChanged = onTimePickerStateChanged,
onTimeChanged = onTimeChanged,
onRegisterButtonClicked = onRegisterButtonClicked,
onDatePickerStateChanged = onDatePickerStateChanged,
)
}
SurveyFormState.DEADLINE -> {
SurveyDeadlineContent(
time = time,
date = date,
timePickerState = timePickerState,
showDatePicker = showDatePicker,
showTimePicker = showTimePicker,
onDateChanged = onDateChanged,
onTimePickerStateChanged = onTimePickerStateChanged,
onTimeChanged = onTimeChanged,
onRegisterButtonClicked = onRegisterButtonClicked,
onDatePickerStateChanged = onDatePickerStateChanged,
onPreviousButtonClicked = {
onPreviousButtonClicked(SurveyFormState.QUESTION)
},
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import androidx.hilt.navigation.compose.hiltViewModel
import com.wap.designsystem.WappTheme
import com.wap.designsystem.component.WappSubTopBar
import com.wap.wapp.core.commmon.extensions.toSupportingText
import com.wap.wapp.core.designresource.R.drawable
import com.wap.wapp.feature.management.survey.R
import com.wap.wapp.feature.management.survey.SurveyFormContent
import com.wap.wapp.feature.management.survey.SurveyFormState
Expand Down Expand Up @@ -99,13 +100,24 @@ internal fun SurveyFormEditScreen(
containerColor = WappTheme.colors.backgroundBlack,
modifier = Modifier.fillMaxSize(),
contentWindowInsets = WindowInsets(0.dp),
topBar = {
WappSubTopBar(
titleRes = R.string.survey_edit,
showLeftButton = true,
showRightButton = true,
leftButtonDrawableRes = drawable.ic_close,
modifier = Modifier.padding(top = 16.dp),
onClickLeftButton = navigateToManagement,
onClickRightButton = { showDeleteSurveyDialog = true },
)
},
) { paddingValues ->
Column(
modifier = Modifier
.fillMaxSize()
.padding(paddingValues) // paddingValue padding
.padding(16.dp), // dp value padding
verticalArrangement = Arrangement.spacedBy(32.dp),
.padding(vertical = 16.dp, horizontal = 20.dp), // dp value padding
verticalArrangement = Arrangement.spacedBy(20.dp),
) {
if (showDeleteSurveyDialog) {
DeleteSurveyDialog(
Expand All @@ -114,21 +126,9 @@ internal fun SurveyFormEditScreen(
)
}

Column(
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
WappSubTopBar(
titleRes = R.string.survey_edit,
showLeftButton = true,
showRightButton = true,
onClickLeftButton = navigateToManagement,
onClickRightButton = { showDeleteSurveyDialog = true },
)

SurveyFormStateIndicator(
surveyRegistrationState = currentRegistrationState,
)
}
SurveyFormStateIndicator(
surveyRegistrationState = currentRegistrationState,
)

SurveyFormContent(
surveyRegistrationState = currentRegistrationState,
Expand All @@ -143,20 +143,28 @@ internal fun SurveyFormEditScreen(
timePickerState = timePickerState,
showDatePicker = showDatePicker,
showTimePicker = showTimePicker,
currentQuestionIndex = totalQuestionSize,
totalQuestionSize = totalQuestionSize,
questionNumber = totalQuestionSize,
totalQuestionNumber = totalQuestionSize,
onDatePickerStateChanged = { state -> showDatePicker = state },
onTimePickerStateChanged = { state -> showTimePicker = state },
onEventListChanged = { viewModel.getEventList() },
onEventContentInitialized = { viewModel.getEventList() },
onEventSelected = { event -> viewModel.setSurveyEventSelection(event) },
onTitleChanged = { title -> viewModel.setSurveyTitle(title) },
onContentChanged = { content -> viewModel.setSurveyContent(content) },
onQuestionChanged = { question -> viewModel.setSurveyQuestion(question) },
onQuestionTypeChanged = { questionType ->
viewModel.setSurveyQuestionType(questionType)
},
onPreviousQuestionButtonClicked = {},
onNextQuestionButtonClicked = {},
onDateChanged = viewModel::setSurveyDateDeadline,
onTimeChanged = { localTime -> viewModel.setSurveyTimeDeadline(localTime) },
onPreviousButtonClicked = { previousState ->
if (previousState == SurveyFormState.QUESTION) {
viewModel.setSurveyQuestionFromAnsweredList()
}
viewModel.setSurveyFormState(previousState)
},
onNextButtonClicked = { currentState, nextState ->
if (viewModel.validateSurveyForm(currentState).not()) { // 유효성 검증
return@SurveyFormContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class SurveyFormEditViewModel @Inject constructor(
setSurveyFormId(surveyForm.surveyFormId)
setSurveyEventSelection(EVENT_SELECTION_INIT.copy(eventId = surveyForm.eventId))
setSurveyTitle(surveyForm.title)
setSurveyQuestionList(surveyForm.surveyQuestionList.toMutableList())
setSurveyQuestionList(surveyForm.surveyQuestionList)
setSurveyQuestionFromAnsweredList()
setSurveyContent(surveyForm.content)
setSurveyTimeDeadline(surveyForm.deadline.toLocalTime())
setSurveyDateDeadline(surveyForm.deadline.toLocalDate())
Expand Down Expand Up @@ -195,13 +196,15 @@ class SurveyFormEditViewModel @Inject constructor(

fun setSurveyDateDeadline(date: LocalDate) { _surveyDateDeadline.value = date }

private fun setSurveyQuestionList(surveyQuestionList: MutableList<SurveyQuestion>) {
// 마지막 질문은 UI에 노출
val lastSurveyQuestion = surveyQuestionList.removeLast()
// 이전 버튼 클릭시 진입점이 질문 페이지인 경우, 응답 목록에서 마지막 질문 노출
private fun setSurveyQuestionList(surveyQuestionList: List<SurveyQuestion>) {
_surveyQuestionList.value.addAll(surveyQuestionList)
}

fun setSurveyQuestionFromAnsweredList() {
val lastSurveyQuestion = _surveyQuestionList.value.removeLast()
setSurveyQuestion(lastSurveyQuestion.questionTitle)
setSurveyQuestionType(lastSurveyQuestion.questionType)

_surveyQuestionList.value.addAll(surveyQuestionList)
}

private fun clearSurveyQuestionState() { _surveyQuestion.value = "" }
Expand Down
Loading

0 comments on commit 1c0fe5b

Please sign in to comment.