mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-13 18:27:00 +05:30
refactor(android): decouple LoadError
from AndroidX Paging
This commit is contained in:
parent
1ba9cefda6
commit
24afea0412
2 changed files with 10 additions and 6 deletions
|
@ -17,17 +17,17 @@ import androidx.compose.ui.Modifier
|
|||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.paging.LoadState
|
||||
|
||||
@Composable
|
||||
fun LoadError(
|
||||
data: LoadState.Error,
|
||||
label: String,
|
||||
error: Throwable,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
var showDialog by remember { mutableStateOf(false) }
|
||||
Column(verticalArrangement = Arrangement.spacedBy(4.dp), modifier = modifier) {
|
||||
Text(
|
||||
text = "Failed to load posts",
|
||||
text = label,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally),
|
||||
)
|
||||
|
@ -47,14 +47,14 @@ fun LoadError(
|
|||
text = "Copy stacktrace",
|
||||
modifier =
|
||||
Modifier.clickable {
|
||||
clipboard.setText(AnnotatedString(data.error.stackTraceToString()))
|
||||
clipboard.setText(AnnotatedString(error.stackTraceToString()))
|
||||
showDialog = false
|
||||
}
|
||||
)
|
||||
},
|
||||
text = {
|
||||
Text(
|
||||
text = "${data.error.message}",
|
||||
text = "${error.message}",
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -49,7 +49,11 @@ fun NetworkPosts(
|
|||
if (items.itemCount == 0) {
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
if (loadState is LoadState.Error) {
|
||||
LoadError(data = loadState, modifier = Modifier.align(Alignment.Center))
|
||||
LoadError(
|
||||
label = "Failed to load posts",
|
||||
error = loadState.error,
|
||||
modifier = Modifier.align(Alignment.Center),
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue