itch.io browse: let a failed page be retried instead of ending the list

This commit is contained in:
FX192 committed 2026-10-24 13:02:17 +03:00
1 parent 7e87cdacb5
commit 5838587639
3 files changed
+13 -6

No files matched your search

@@ -151,8 +151,9 @@ internal object ItchBrowseState {
if (active) more(context)
}
fun more(context: Context) {
if (loading || ended || !active) return
/** Asks for the next page. A page that failed is only asked for again when [retry] is set, so scrolling can't loop on it. */
fun more(context: Context, retry: Boolean = false) {
if (loading || ended || !active || (failed && !retry)) return
loading = true
failed = false
val app = context.applicationContext
@@ -164,13 +165,12 @@ internal object ItchBrowseState {
StoresState.post {
if (mine != generation) return@post
loading = false
if (answer == null) {
failed = items.isEmpty()
ended = items.isNotEmpty()
// A thrown or non-2xx fetch leaves the list open so the same page can be asked for again.
if (answer == null || answer.code !in 200..299) {
failed = true
return@post
}
if (answer.items.isEmpty()) {
failed = items.isEmpty() && answer.code !in 200..299
ended = true
return@post
}
@@ -56,6 +56,9 @@ internal fun ItchLoadMore() {
val count = ItchBrowseState.items.size
LaunchedEffect(count) { ItchBrowseState.more(ctx) }
if (ItchBrowseState.loading) LinearProgressIndicator(Modifier.fillMaxWidth().padding(vertical = 12.dp))
else if (ItchBrowseState.failed) Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {
BrowseChip(stringResource(R.string.stores_dl_retry), false) { ItchBrowseState.more(ctx, retry = true) }
}
else if (!ItchBrowseState.ended && count > 0) Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {
BrowseChip(stringResource(R.string.stores_itch_load_more), false) { ItchBrowseState.more(ctx) }
}