Skip to content

Commit

Permalink
topic completion bottom sheet continue with next topic logic
Browse files Browse the repository at this point in the history
^ALTAPPS-598 Fixed
  • Loading branch information
vladkash authored Feb 22, 2023
1 parent ab3897e commit f787714
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ enum class HyperskillAnalyticTarget(val targetName: String) {
TOPIC("topic"),
GO_BACK("go_back"),
GO_TO_HOME_SCREEN("go_to_home_screen"),
CONTINUE_WITH_NEXT_TOPIC("continue_with_next_topic"),
DAILY_STEP_COMPLETED_MODAL("daily_step_completed_modal"),
TOPIC_COMPLETED_MODAL("topic_completed_modal"),
CLOSE("close"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.hyperskill.app.step_completion.domain.analytic.topic_completed_modal

import org.hyperskill.app.analytic.domain.model.hyperskill.HyperskillAnalyticAction
import org.hyperskill.app.analytic.domain.model.hyperskill.HyperskillAnalyticEvent
import org.hyperskill.app.analytic.domain.model.hyperskill.HyperskillAnalyticPart
import org.hyperskill.app.analytic.domain.model.hyperskill.HyperskillAnalyticRoute
import org.hyperskill.app.analytic.domain.model.hyperskill.HyperskillAnalyticTarget

/**
* Represents click on the "Continue with next topic" button analytic event.
*
* JSON payload:
* ```
* {
* "route": "/learn/step/1",
* "action": "click",
* "part": "topic_completed_modal",
* "target": "continue_with_next_topic"
* }
* ```
* @see HyperskillAnalyticEvent
*/
class StepCompletionTopicCompletedModalClickedContinueNextTopicHyperskillAnalyticEvent(
route: HyperskillAnalyticRoute
) : HyperskillAnalyticEvent(
route,
HyperskillAnalyticAction.CLICK,
HyperskillAnalyticPart.TOPIC_COMPLETED_MODAL,
HyperskillAnalyticTarget.CONTINUE_WITH_NEXT_TOPIC
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class StepCompletionComponentImpl(
appGraph.analyticComponent.analyticInteractor,
appGraph.commonComponent.resourceProvider,
appGraph.sentryComponent.sentryInteractor,
appGraph.buildTopicsToDiscoverNextDataComponent().topicsToDiscoverNextInteractor,
appGraph.stepCompletionFlowDataComponent.topicCompletedFlow,
appGraph.progressesFlowDataComponent.topicProgressFlow,
appGraph.buildNotificationComponent().notificationInteractor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.hyperskill.app.step_completion.presentation

import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import org.hyperskill.app.SharedResources
Expand All @@ -18,6 +20,7 @@ import org.hyperskill.app.step_completion.domain.flow.TopicCompletedFlow
import org.hyperskill.app.step_completion.presentation.StepCompletionFeature.Action
import org.hyperskill.app.step_completion.presentation.StepCompletionFeature.Message
import org.hyperskill.app.topics.domain.interactor.TopicsInteractor
import org.hyperskill.app.topics_to_discover_next.domain.interactor.TopicsToDiscoverNextInteractor
import ru.nobird.app.presentation.redux.dispatcher.CoroutineActionDispatcher

class StepCompletionActionDispatcher(
Expand All @@ -28,6 +31,7 @@ class StepCompletionActionDispatcher(
private val analyticInteractor: AnalyticInteractor,
private val resourceProvider: ResourceProvider,
private val sentryInteractor: SentryInteractor,
private val topicsToDiscoverNextInteractor: TopicsToDiscoverNextInteractor,
private val topicCompletedFlow: TopicCompletedFlow,
private val topicProgressFlow: TopicProgressFlow,
notificationInteractor: NotificationInteractor,
Expand Down Expand Up @@ -76,19 +80,34 @@ class StepCompletionActionDispatcher(
if (topicProgress.isCompleted) {
topicCompletedFlow.notifyDataChanged(action.topicId)

val topicTitle = topicsInteractor
.getTopic(action.topicId)
.map { it.title }
.getOrElse { return onNewMessage(Message.CheckTopicCompletionStatus.Error) }
coroutineScope {
val topicResult = async {
topicsInteractor.getTopic(action.topicId)
}
val nextTopicToDiscoverResult = async {
topicsToDiscoverNextInteractor.getNextTopicToDiscover()
}

onNewMessage(
Message.CheckTopicCompletionStatus.Completed(
resourceProvider.getString(
SharedResources.strings.step_quiz_topic_completed_modal_text,
topicTitle
val topicTitle = topicResult.await()
.map { it.title }
.getOrElse {
onNewMessage(Message.CheckTopicCompletionStatus.Error)
return@coroutineScope
}
val nextStepId = nextTopicToDiscoverResult.await()
.getOrNull()
?.theoryId

onNewMessage(
Message.CheckTopicCompletionStatus.Completed(
modalText = resourceProvider.getString(
SharedResources.strings.step_quiz_topic_completed_modal_text,
topicTitle
),
nextStepId = nextStepId
)
)
)
}
} else {
topicProgressFlow.notifyDataChanged(topicProgress)
onNewMessage(Message.CheckTopicCompletionStatus.Uncompleted)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ interface StepCompletionFeature {
data class State(
val currentStep: Step,
val continueButtonAction: ContinueButtonAction,
val isPracticingLoading: Boolean = false
val isPracticingLoading: Boolean = false,
val nextStepRoute: StepRoute? = null
)

sealed interface ContinueButtonAction {
Expand All @@ -42,12 +43,13 @@ interface StepCompletionFeature {
*/

sealed interface CheckTopicCompletionStatus : Message {
data class Completed(val modalText: String) : CheckTopicCompletionStatus
data class Completed(val modalText: String, val nextStepId: Long?) : CheckTopicCompletionStatus
object Uncompleted : CheckTopicCompletionStatus
object Error : CheckTopicCompletionStatus
}

object TopicCompletedModalGoToHomeScreenClicked : Message
object TopicCompletedModalContinueNextTopicClicked : Message

sealed interface FetchNextRecommendedStepResult : Message {
data class Success(val newStepRoute: StepRoute) : FetchNextRecommendedStepResult
Expand All @@ -69,7 +71,7 @@ interface StepCompletionFeature {
data class CheckTopicCompletionStatus(val topicId: Long) : Action

sealed interface ViewAction : Action {
data class ShowTopicCompletedModal(val modalText: String) : ViewAction
data class ShowTopicCompletedModal(val modalText: String, val isNextStepAvailable: Boolean) : ViewAction

data class ShowStartPracticingError(val message: String) : ViewAction

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.hyperskill.app.step_completion.presentation.StepCompletionFeature.Act
import org.hyperskill.app.step_completion.presentation.StepCompletionFeature.ContinueButtonAction
import org.hyperskill.app.step_completion.presentation.StepCompletionFeature.Message
import org.hyperskill.app.step_completion.presentation.StepCompletionFeature.State
import org.hyperskill.app.step_completion.domain.analytic.topic_completed_modal.StepCompletionTopicCompletedModalClickedContinueNextTopicHyperskillAnalyticEvent
import ru.nobird.app.presentation.redux.reducer.StateReducer

class StepCompletionReducer(private val stepRoute: StepRoute) : StateReducer<State, Message, Action> {
Expand Down Expand Up @@ -59,8 +60,9 @@ class StepCompletionReducer(private val stepRoute: StepRoute) : StateReducer<Sta
is Message.CheckTopicCompletionStatus.Completed ->
state.copy(
continueButtonAction = ContinueButtonAction.NavigateToHomeScreen,
isPracticingLoading = false
) to setOf(Action.ViewAction.ShowTopicCompletedModal(message.modalText))
isPracticingLoading = false,
nextStepRoute = message.nextStepId?.let { StepRoute.Learn(it) }
) to setOf(Action.ViewAction.ShowTopicCompletedModal(message.modalText, message.nextStepId != null))
is Message.CheckTopicCompletionStatus.Uncompleted ->
state.copy(isPracticingLoading = false) to emptySet()
is Message.CheckTopicCompletionStatus.Error ->
Expand All @@ -77,6 +79,19 @@ class StepCompletionReducer(private val stepRoute: StepRoute) : StateReducer<Sta
)
)
)
is Message.TopicCompletedModalContinueNextTopicClicked ->
if (state.nextStepRoute != null) {
state to setOf(
Action.ViewAction.ReloadStep(state.nextStepRoute),
Action.LogAnalyticEvent(
StepCompletionTopicCompletedModalClickedContinueNextTopicHyperskillAnalyticEvent(
route = stepRoute.analyticRoute
)
)
)
} else {
null
}
is Message.StepSolved ->
if (!state.isPracticingLoading &&
stepRoute is StepRoute.Learn &&
Expand Down

0 comments on commit f787714

Please sign in to comment.