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

Fix load more #3090

Merged
merged 2 commits into from
Sep 6, 2024
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 @@ -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 {
Copy link
Contributor

@malinajirka malinajirka Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️⚠️⚠️ @atorresveiga This code is used by the WPAndroid app as well - have we made sure it works there as expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out @malinajirka. I tested the changes on the WPAndroid app and the pagination keeps working as expected

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
Loading