Skip to content

Commit

Permalink
Merge pull request #3090 from wordpress-mobile/issue/12491-fix-load-more
Browse files Browse the repository at this point in the history
Fix load more
  • Loading branch information
atorresveiga authored Sep 6, 2024
2 parents 3d8b46e + 3d6d1df commit a77c116
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum class ListState(val value: Int) {
fun isLoadingMore() = this == LOADING_MORE

companion object {
val defaultState = ListState.NEEDS_REFRESH
val defaultState = NEEDS_REFRESH
val notExpiredStates = setOf(CAN_LOAD_MORE, FETCHED)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,17 @@ class ListStore @Inject constructor(
/**
* A helper function that returns the [ListState] for the given [ListDescriptor].
*/
private fun getListState(listDescriptor: ListDescriptor): ListState {
fun getListState(listDescriptor: ListDescriptor): ListState {
val listModel = listSqlUtils.getList(listDescriptor)
return if (listModel != null && !isListStateOutdated(listModel)) {
requireNotNull(ListState.values().firstOrNull { it.value == listModel.stateDbValue }) {
val currentState = listModel?.let {
requireNotNull(ListState.entries.firstOrNull { it.value == listModel.stateDbValue }) {
"The stateDbValue of the ListModel didn't match any of the `ListState`s. This likely happened " +
"because the ListState values were altered without a DB migration."
}
} else ListState.defaultState
}
val isListStateValid = currentState != null
&& (isListStateOutdated(listModel).not() || (currentState in ListState.notExpiredStates))
return if (isListStateValid) currentState!! else ListState.defaultState
}

/**
Expand Down

0 comments on commit a77c116

Please sign in to comment.