Skip to content

Commit

Permalink
Merge pull request #111 from pknu-wap/feature/jaino/#94
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjaino authored Feb 3, 2024
2 parents 0a67943 + ad6e575 commit 7c41c14
Show file tree
Hide file tree
Showing 15 changed files with 419 additions and 184 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/src/main/java/com/wap/wapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.wap.wapp.feature.management.event.navigation.eventRegistrationNavigat
import com.wap.wapp.feature.management.survey.navigation.ManagementSurveyRoute
import com.wap.wapp.feature.profile.profilesetting.navigation.profileSettingNavigationRoute
import com.wap.wapp.feature.splash.navigation.splashNavigationRoute
import com.wap.wapp.feature.survey.navigation.SurveyRoute
import com.wap.wapp.navigation.TopLevelDestination
import com.wap.wapp.navigation.WappNavHost
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -116,6 +117,7 @@ private fun handleBottomBarState(
attendanceManagementNavigationRoute -> setBottomBarState(false)
ManagementSurveyRoute.surveyFormRegistrationRoute -> setBottomBarState(false)
eventRegistrationNavigationRoute -> setBottomBarState(false)
SurveyRoute.answerRoute("{id}") ->setBottomBarState(false)
else -> setBottomBarState(true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ internal fun ManagementRoute(
LaunchedEffect(true) {
viewModel.getUserRole() // 유저 권한 검색

viewModel.userRole.collectLatest { managerState ->
when (managerState) {
UserRole.GUEST -> { showGuestScreen = true }
UserRole.MEMBER -> { showValidationScreen = true }
UserRole.MANAGER -> viewModel.getEventSurveyList()
viewModel.userRole.collectLatest { userRoleUiState ->
when (userRoleUiState) {
is ManagementViewModel.UserRoleUiState.Init -> { }
is ManagementViewModel.UserRoleUiState.Success -> {
when (userRoleUiState.userRole) {
UserRole.GUEST -> { showGuestScreen = true }
UserRole.MEMBER -> { showValidationScreen = true }
UserRole.MANAGER -> viewModel.getEventSurveyList()
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ private fun ManagementSurveyItemCard(
painter = painterResource(id = R.drawable.ic_forward),
contentDescription = stringResource(string.detail_icon_description),
tint = WappTheme.colors.yellow34,
modifier = Modifier
.clickable { onCardClicked(item.eventId) }
.size(20.dp),
modifier = Modifier.size(20.dp),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class ManagementViewModel @Inject constructor(
private val _errorFlow: MutableSharedFlow<Throwable> = MutableSharedFlow()
val errorFlow: SharedFlow<Throwable> = _errorFlow.asSharedFlow()

private val _userRole: MutableStateFlow<UserRole> =
MutableStateFlow(UserRole.GUEST)
val userRole: StateFlow<UserRole> = _userRole.asStateFlow()
private val _userRole: MutableStateFlow<UserRoleUiState> =
MutableStateFlow(UserRoleUiState.Init)
val userRole: StateFlow<UserRoleUiState> = _userRole.asStateFlow()

private val _surveyFormList: MutableStateFlow<SurveyFormsState> =
MutableStateFlow(SurveyFormsState.Init)
Expand All @@ -39,12 +39,14 @@ class ManagementViewModel @Inject constructor(
private val _eventList: MutableStateFlow<EventsState> = MutableStateFlow(EventsState.Init)
val eventList: StateFlow<EventsState> = _eventList.asStateFlow()

fun getUserRole() {
viewModelScope.launch {
getUserRoleUseCase()
.onSuccess { userRole -> _userRole.emit(userRole) }
.onFailure { exception -> _errorFlow.emit(exception) }
}
fun getUserRole() = viewModelScope.launch {
getUserRoleUseCase()
.onSuccess { userRole ->
_userRole.value = UserRoleUiState.Success(userRole)
}
.onFailure { exception ->
_errorFlow.emit(exception)
}
}

fun getEventSurveyList() = viewModelScope.launch {
Expand Down Expand Up @@ -74,6 +76,11 @@ class ManagementViewModel @Inject constructor(
}
}

sealed class UserRoleUiState {
data object Init : UserRoleUiState()
data class Success(val userRole: UserRole) : UserRoleUiState()
}

sealed class EventsState {
data object Init : EventsState()
data object Loading : EventsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ internal fun SurveyFormItemCard(
Text(
text = surveyForm.content,
color = WappTheme.colors.grayBD,
maxLines = 1,
style = WappTheme.typography.contentMedium,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ internal fun ObjectiveSurveyForm(
questionTitle: String,
answer: Rating,
onAnswerSelected: (Rating) -> Unit,
modifier: Modifier = Modifier,
) {
Column(
modifier = Modifier.fillMaxWidth(),
modifier = modifier,
verticalArrangement = Arrangement.spacedBy(32.dp),
) {
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ internal fun SubjectiveSurveyForm(
questionTitle: String,
answer: String,
onAnswerChanged: (String) -> Unit,
modifier: Modifier = Modifier,
) {
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(32.dp),
modifier = modifier,
verticalArrangement = Arrangement.spacedBy(40.dp),
) {
Text(
text = questionTitle,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.wap.wapp.feature.survey.answer

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.wap.designsystem.component.WappButton
import com.wap.wapp.core.model.survey.QuestionType
import com.wap.wapp.core.model.survey.Rating
import com.wap.wapp.core.model.survey.SurveyForm
import com.wap.wapp.feature.survey.R

@Composable
internal fun SurveyAnswerForm(
surveyForm: SurveyForm,
modifier: Modifier,
questionNumber: Int,
subjectiveAnswer: String,
objectiveAnswer: Rating,
onSubjectiveAnswerChanged: (String) -> Unit,
onObjectiveAnswerSelected: (Rating) -> Unit,
onNextQuestionButtonClicked: () -> Unit,
onPreviousQuestionButtonClicked: () -> Unit,
) {
Column(
verticalArrangement = Arrangement.spacedBy(40.dp),
modifier = modifier,
) {
val surveyQuestion = surveyForm.surveyQuestionList[questionNumber]
val lastQuestionNumber = surveyForm.surveyQuestionList.lastIndex

SurveyAnswerStateIndicator(
index = questionNumber + 1,
size = lastQuestionNumber + 1,
)

when (surveyQuestion.questionType) {
QuestionType.SUBJECTIVE -> {
SubjectiveSurveyForm(
questionTitle = surveyQuestion.questionTitle,
answer = subjectiveAnswer,
onAnswerChanged = onSubjectiveAnswerChanged,
modifier = Modifier.weight(1f),
)
}

QuestionType.OBJECTIVE -> {
ObjectiveSurveyForm(
questionTitle = surveyQuestion.questionTitle,
answer = objectiveAnswer,
onAnswerSelected = onObjectiveAnswerSelected,
modifier = Modifier.weight(1f),
)
}
}

val isGreaterThanFirstQuestion = questionNumber > 0
val isLastQuestion = questionNumber == lastQuestionNumber // 마지막 응답일 경우, 완료로 변경
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
WappButton(
textRes = R.string.previous,
onClick = onPreviousQuestionButtonClicked,
isEnabled = isGreaterThanFirstQuestion,
modifier = Modifier.weight(1f),
)

SurveyAnswerButton(
isLastQuestion = isLastQuestion,
onButtonClicked = onNextQuestionButtonClicked,
isEnabled = checkQuestionTypeAndSubjectiveAnswer(
questionType = surveyQuestion.questionType,
subjectiveAnswer = subjectiveAnswer,
),
modifier = Modifier.weight(1f),
)
}
}
}

@Composable
private fun SurveyAnswerButton(
isLastQuestion: Boolean,
isEnabled: Boolean,
onButtonClicked: () -> Unit,
modifier: Modifier,
) {
if (isLastQuestion) {
WappButton(
textRes = R.string.submit,
onClick = { onButtonClicked() },
isEnabled = isEnabled,
modifier = modifier,
)
} else {
WappButton(
textRes = R.string.next,
onClick = { onButtonClicked() },
isEnabled = isEnabled,
modifier = modifier,
)
}
}

private fun checkQuestionTypeAndSubjectiveAnswer(
questionType: QuestionType,
subjectiveAnswer: String,
): Boolean {
if (questionType == QuestionType.OBJECTIVE) {
return true
}
return subjectiveAnswer.length >= 10
}
Loading

0 comments on commit 7c41c14

Please sign in to comment.