Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALTAPPS-1333: Shared load more bug with pagination for root topics section #1170

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ object StudyPlanWidgetFeature {
ERROR,

FIRST_PAGE_LOADING,
FIRST_PAGE_LOADED,
NEXT_PAGE_LOADING,
PAGE_LOADED,
ALL_PAGES_LOADED
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class StudyPlanWidgetReducer : StateReducer<State, Message, Action> {
studyPlanSection = studyPlanSection,
isExpanded = studyPlanSection.id == currentSectionId,
sectionContentStatus = if (studyPlanSection.id == currentSectionId) {
SectionContentStatus.PAGE_LOADED
SectionContentStatus.FIRST_PAGE_LOADED
} else {
SectionContentStatus.IDLE
}
Expand Down Expand Up @@ -245,29 +245,41 @@ class StudyPlanWidgetReducer : StateReducer<State, Message, Action> {
sectionId: Long,
activities: List<LearningActivity>
): StudyPlanWidgetReducerResult {
val nextState = state.copy(
// ALTAPPS-786: We should hide sections without available activities to avoid blocking study plan
studyPlanSections = if (activities.isEmpty()) {
state.studyPlanSections.mutate {
remove(sectionId)
val sectionContentStatus = state.studyPlanSections[sectionId]?.sectionContentStatus
val nextState =
when {
// ALTAPPS-786: We should hide sections without available activities to avoid blocking study plan
activities.isEmpty() && sectionContentStatus == SectionContentStatus.FIRST_PAGE_LOADING -> {
state.copy(
studyPlanSections = state.studyPlanSections.mutate {
remove(sectionId)
}
)
}
} else {
state.studyPlanSections.update(sectionId) { sectionInfo ->
val canLoadMoreActivities =
sectionInfo
.studyPlanSection
.getActivitiesToBeLoaded(state.activities.values)
.isNotEmpty()
sectionInfo.copy(
sectionContentStatus = if (canLoadMoreActivities) {
SectionContentStatus.PAGE_LOADED
} else {
SectionContentStatus.ALL_PAGES_LOADED
else -> {
state.copy(
studyPlanSections = state.studyPlanSections.update(sectionId) { sectionInfo ->
sectionInfo.copy(
sectionContentStatus = when (sectionContentStatus) {
SectionContentStatus.FIRST_PAGE_LOADED -> {
val canLoadMoreActivities =
sectionInfo
.studyPlanSection
.getActivitiesToBeLoaded(state.activities.values)
.isNotEmpty()
if (canLoadMoreActivities) {
SectionContentStatus.FIRST_PAGE_LOADED
} else {
SectionContentStatus.ALL_PAGES_LOADED
}
}
else -> SectionContentStatus.ALL_PAGES_LOADED
}
)
}
)
}
}
)

val isFetchedActivitiesForCurrentSection = sectionId == state.getCurrentSection()?.id

Expand Down Expand Up @@ -313,8 +325,8 @@ class StudyPlanWidgetReducer : StateReducer<State, Message, Action> {
SectionContentStatus.ERROR,
SectionContentStatus.FIRST_PAGE_LOADING -> SectionContentStatus.ERROR
SectionContentStatus.NEXT_PAGE_LOADING,
SectionContentStatus.PAGE_LOADED,
SectionContentStatus.ALL_PAGES_LOADED -> SectionContentStatus.PAGE_LOADED
SectionContentStatus.FIRST_PAGE_LOADED,
SectionContentStatus.ALL_PAGES_LOADED -> SectionContentStatus.FIRST_PAGE_LOADED
}
)
}
Expand Down Expand Up @@ -408,7 +420,7 @@ class StudyPlanWidgetReducer : StateReducer<State, Message, Action> {
// activities are loading at the moment or already loaded
SectionContentStatus.FIRST_PAGE_LOADING,
SectionContentStatus.NEXT_PAGE_LOADING,
SectionContentStatus.PAGE_LOADED,
SectionContentStatus.FIRST_PAGE_LOADED,
SectionContentStatus.ALL_PAGES_LOADED -> {
updateSectionState(contentStatus) to setOfNotNull(logAnalyticEventAction)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import org.hyperskill.app.learning_activities.domain.model.LearningActivity
import org.hyperskill.app.learning_activities.domain.model.LearningActivityState
import org.hyperskill.app.learning_activities.view.mapper.LearningActivityTextsMapper
import org.hyperskill.app.study_plan.widget.presentation.StudyPlanWidgetFeature
import org.hyperskill.app.study_plan.widget.presentation.StudyPlanWidgetFeature.SectionContentStatus
import org.hyperskill.app.study_plan.widget.presentation.StudyPlanWidgetFeature.SectionContentStatus.ALL_PAGES_LOADED
import org.hyperskill.app.study_plan.widget.presentation.StudyPlanWidgetFeature.SectionContentStatus.ERROR
import org.hyperskill.app.study_plan.widget.presentation.StudyPlanWidgetFeature.SectionContentStatus.FIRST_PAGE_LOADED
import org.hyperskill.app.study_plan.widget.presentation.StudyPlanWidgetFeature.SectionContentStatus.FIRST_PAGE_LOADING
import org.hyperskill.app.study_plan.widget.presentation.StudyPlanWidgetFeature.SectionContentStatus.IDLE
import org.hyperskill.app.study_plan.widget.presentation.StudyPlanWidgetFeature.SectionContentStatus.NEXT_PAGE_LOADING
import org.hyperskill.app.study_plan.widget.presentation.StudyPlanWidgetFeature.SectionStatus
import org.hyperskill.app.study_plan.widget.presentation.getCurrentActivity
import org.hyperskill.app.study_plan.widget.presentation.getCurrentSection
Expand Down Expand Up @@ -74,19 +79,19 @@ class StudyPlanWidgetViewStateMapper(private val dateFormatter: SharedDateFormat
): SectionContent =
if (sectionInfo.isExpanded) {
when (sectionInfo.sectionContentStatus) {
SectionContentStatus.IDLE -> SectionContent.Collapsed
SectionContentStatus.ERROR -> SectionContent.Error
SectionContentStatus.FIRST_PAGE_LOADING,
SectionContentStatus.NEXT_PAGE_LOADING -> {
IDLE -> SectionContent.Collapsed
ERROR -> SectionContent.Error
FIRST_PAGE_LOADING,
NEXT_PAGE_LOADING -> {
getContent(
state = state,
sectionInfo = sectionInfo,
currentActivityId = currentActivityId,
emptyActivitiesState = SectionContent.Loading
)
}
SectionContentStatus.PAGE_LOADED,
SectionContentStatus.ALL_PAGES_LOADED -> {
FIRST_PAGE_LOADED,
ALL_PAGES_LOADED -> {
getContent(
state = state,
sectionInfo = sectionInfo,
Expand Down Expand Up @@ -114,8 +119,8 @@ class StudyPlanWidgetViewStateMapper(private val dateFormatter: SharedDateFormat
activities = loadedActivities,
currentActivityId = currentActivityId,
unlockedActivitiesCount = state.getUnlockedActivitiesCount(sectionId),
isLoadAllTopicsButtonVisible = sectionInfo.sectionContentStatus == SectionContentStatus.PAGE_LOADED,
isNextPageLoadingShowed = sectionInfo.sectionContentStatus == SectionContentStatus.NEXT_PAGE_LOADING
isLoadAllTopicsButtonVisible = sectionInfo.sectionContentStatus == FIRST_PAGE_LOADED,
isNextPageLoadingShowed = sectionInfo.sectionContentStatus == NEXT_PAGE_LOADING
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class StudyPlanWidgetTest {
studyPlanSections = mapOf(
currentSectionId to StudyPlanWidgetFeature.StudyPlanSectionInfo(
studyPlanSection = studyPlanSectionStub(currentSectionId),
sectionContentStatus = SectionContentStatus.NEXT_PAGE_LOADING,
sectionContentStatus = SectionContentStatus.FIRST_PAGE_LOADING,
isExpanded = true
),
nextSectionId to StudyPlanWidgetFeature.StudyPlanSectionInfo(
Expand All @@ -334,27 +334,30 @@ class StudyPlanWidgetTest {
@Test
fun `Not current section should be removed if no available activities loaded`() {
val currentSectionId = 0L
val notCurrent = 1L
val notCurrentSectionId = 1L
val initialState = StudyPlanWidgetFeature.State(
studyPlanSections = mapOf(
currentSectionId to StudyPlanWidgetFeature.StudyPlanSectionInfo(
studyPlanSection = studyPlanSectionStub(currentSectionId),
sectionContentStatus = SectionContentStatus.ALL_PAGES_LOADED,
isExpanded = true
),
notCurrent to StudyPlanWidgetFeature.StudyPlanSectionInfo(
studyPlanSection = studyPlanSectionStub(notCurrent),
sectionContentStatus = SectionContentStatus.NEXT_PAGE_LOADING,
notCurrentSectionId to StudyPlanWidgetFeature.StudyPlanSectionInfo(
studyPlanSection = studyPlanSectionStub(notCurrentSectionId),
sectionContentStatus = SectionContentStatus.FIRST_PAGE_LOADING,
isExpanded = false
)
)
)
val (state, _) =
reducer.reduce(
initialState,
StudyPlanWidgetFeature.LearningActivitiesFetchResult.Success(sectionId = notCurrent, emptyList())
StudyPlanWidgetFeature.LearningActivitiesFetchResult.Success(
sectionId = notCurrentSectionId,
activities = emptyList()
)
)
assertTrue(state.studyPlanSections.containsKey(notCurrent).not())
assertTrue(state.studyPlanSections.containsKey(notCurrentSectionId).not())
}

@Test
Expand Down
Loading