Skip to content
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
74 changes: 42 additions & 32 deletions app/src/main/java/com/cornellappdev/score/components/ErrorState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package com.cornellappdev.score.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
Expand All @@ -29,50 +33,56 @@ fun ErrorState(
message: String,
modifier: Modifier = Modifier
) {
Column(
Box(
modifier = modifier
.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(100.dp)
.fillMaxSize()
.defaultMinSize(minHeight = 740.dp),
contentAlignment = Alignment.BottomCenter
) {
Spacer(modifier = Modifier.height(200.dp))
Column(
horizontalAlignment = Alignment.CenterHorizontally
modifier = Modifier
.padding(bottom = 270.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(100.dp)
) {
Image(
painter = painterResource(R.drawable.ic_feedback),
contentDescription = "feedback bubble"
)
Spacer(modifier = Modifier.height(16.dp))
Text(
text = message,
style = heading2.copy(color = GrayPrimary)
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = "Please try again later.",
style = bodyNormal.copy(color = GrayMedium)
)
}

Button(
colors = ButtonDefaults.buttonColors(containerColor = CrimsonPrimary),
onClick = onRefresh
) {
Row(
verticalAlignment = Alignment.CenterVertically
Column(
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
painter = painterResource(R.drawable.ic_cached),
contentDescription = "refresh icon"
painter = painterResource(R.drawable.ic_feedback),
contentDescription = "feedback bubble"
)
Spacer(modifier = Modifier.height(16.dp))
Text(
text = message,
style = heading2.copy(color = GrayPrimary)
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = "Please try again later.",
style = bodyNormal.copy(color = GrayMedium)
)
Text("Try again")
}

Button(
colors = ButtonDefaults.buttonColors(containerColor = CrimsonPrimary),
onClick = onRefresh
) {
Row(
verticalAlignment = Alignment.CenterVertically
) {
Image(
painter = painterResource(R.drawable.ic_cached),
contentDescription = "refresh icon"
)
Text("Try again")
}
}
}
Spacer(modifier = Modifier.height(70.dp))
}
}


@Preview
@Composable
private fun ErrorStatePreview() = ScorePreview {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -23,7 +24,7 @@ import com.cornellappdev.score.theme.Style.heading2
fun NavigationHeader(title: String, onBackPressed: () -> Unit) {
Box(
modifier = Modifier
//.shadow(elevation = 8.dp, clip = false, spotColor = Color.Black.copy(0.05f))
.shadow(elevation = 8.dp, clip = false, spotColor = Color.Black.copy(0.05f))
.background(Color.White)
) {
Box(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ fun GameDetailsScreen(
}

is ApiResponse.Error -> {
ErrorState(gameDetailsViewModel::onRefresh, "Failed to load game details")
ErrorState(
{ gameDetailsViewModel.onRefresh() },
"Oops! Details failed to load."
)
}

is ApiResponse.Success -> {
Expand Down