Skip to content

Commit

Permalink
Shared fix error when continue practicing (#719)
Browse files Browse the repository at this point in the history
^ALTAPPS-900
  • Loading branch information
vladkash authored Oct 24, 2023
1 parent c94f752 commit 90a8401
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,15 @@ class StepCompletionActionDispatcher(
) {
val topicProgress = progressesInteractor
.getTopicProgress(action.topicId)
.getOrElse { return onNewMessage(Message.CheckTopicCompletionStatus.Error) }
.getOrElse {
return onNewMessage(
Message.CheckTopicCompletionStatus.Error(
resourceProvider.getString(
SharedResources.strings.step_theory_failed_to_continue_practicing
)
)
)
}

if (topicProgress.isCompleted) {
topicCompletedFlow.notifyDataChanged(action.topicId)
Expand All @@ -138,7 +146,15 @@ class StepCompletionActionDispatcher(
}

val topic = topicDeferred.await()
.getOrElse { return@coroutineScope onNewMessage(Message.CheckTopicCompletionStatus.Error) }
.getOrElse {
return@coroutineScope onNewMessage(
Message.CheckTopicCompletionStatus.Error(
resourceProvider.getString(
SharedResources.strings.step_theory_failed_to_continue_practicing
)
)
)
}
val nextLearningActivity = nextLearningActivityDeferred.await()
.getOrNull()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface StepCompletionFeature {
StartPracticingButtonAction.FetchNextStepQuiz
},
continueButtonAction = if (stepRoute is StepRoute.Learn) {
ContinueButtonAction.FetchNextStepQuiz
ContinueButtonAction.CheckTopicCompletion
} else {
ContinueButtonAction.NavigateToBack
}
Expand All @@ -44,7 +44,6 @@ interface StepCompletionFeature {
sealed interface ContinueButtonAction {
object NavigateToStudyPlan : ContinueButtonAction
object NavigateToBack : ContinueButtonAction
object FetchNextStepQuiz : ContinueButtonAction
object CheckTopicCompletion : ContinueButtonAction
}

Expand All @@ -66,7 +65,7 @@ interface StepCompletionFeature {
val nextLearningActivity: LearningActivity?
) : CheckTopicCompletionStatus
object Uncompleted : CheckTopicCompletionStatus
object Error : CheckTopicCompletionStatus
data class Error(val errorMessage: String) : CheckTopicCompletionStatus
}

object TopicCompletedModalGoToStudyPlanClicked : Message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class StepCompletionReducer(private val stepRoute: StepRoute) : StateReducer<Sta
)
state.copy(
isPracticingLoading = when (state.continueButtonAction) {
is ContinueButtonAction.FetchNextStepQuiz,
is ContinueButtonAction.CheckTopicCompletion ->
true
ContinueButtonAction.NavigateToBack,
Expand All @@ -43,9 +42,6 @@ class StepCompletionReducer(private val stepRoute: StepRoute) : StateReducer<Sta
when (state.continueButtonAction) {
ContinueButtonAction.NavigateToBack -> Action.ViewAction.NavigateTo.Back
ContinueButtonAction.NavigateToStudyPlan -> Action.ViewAction.NavigateTo.StudyPlan
ContinueButtonAction.FetchNextStepQuiz -> Action.FetchNextRecommendedStep(
currentStep = state.currentStep
)
ContinueButtonAction.CheckTopicCompletion -> state.currentStep.topic?.let {
Action.CheckTopicCompletionStatus(it)
} ?: Action.ViewAction.NavigateTo.Back
Expand Down Expand Up @@ -93,12 +89,11 @@ class StepCompletionReducer(private val stepRoute: StepRoute) : StateReducer<Sta
)
}
is Message.CheckTopicCompletionStatus.Uncompleted ->
state.copy(isPracticingLoading = false) to emptySet()
state to setOf(Action.FetchNextRecommendedStep(currentStep = state.currentStep))
is Message.CheckTopicCompletionStatus.Error ->
state.copy(
continueButtonAction = ContinueButtonAction.CheckTopicCompletion,
isPracticingLoading = false
) to emptySet()
state.copy(isPracticingLoading = false) to setOf(
Action.ViewAction.ShowStartPracticingError(message.errorMessage)
)
is Message.TopicCompletedModalGoToStudyPlanClicked ->
state to setOf(
Action.ViewAction.NavigateTo.StudyPlan,
Expand Down Expand Up @@ -134,15 +129,10 @@ class StepCompletionReducer(private val stepRoute: StepRoute) : StateReducer<Sta
)
}
is Message.StepSolved ->
if (!state.isPracticingLoading &&
stepRoute is StepRoute.Learn &&
message.stepId == state.currentStep.id &&
state.currentStep.topic != null
if (stepRoute is StepRoute.Learn &&
message.stepId == state.currentStep.id
) {
state.copy(isPracticingLoading = true) to setOf(
Action.CheckTopicCompletionStatus(state.currentStep.topic),
Action.UpdateProblemsLimit
)
state to setOf(Action.UpdateProblemsLimit)
} else {
null
}
Expand Down

0 comments on commit 90a8401

Please sign in to comment.