|
| 1 | +package com.ninecraft.booket.core.ui.component |
| 2 | + |
| 3 | +import androidx.compose.foundation.layout.Box |
| 4 | +import androidx.compose.foundation.layout.Column |
| 5 | +import androidx.compose.foundation.layout.Spacer |
| 6 | +import androidx.compose.foundation.layout.fillMaxSize |
| 7 | +import androidx.compose.foundation.layout.height |
| 8 | +import androidx.compose.material3.Text |
| 9 | +import androidx.compose.runtime.Composable |
| 10 | +import androidx.compose.ui.Alignment |
| 11 | +import androidx.compose.ui.Modifier |
| 12 | +import androidx.compose.ui.res.stringResource |
| 13 | +import androidx.compose.ui.text.style.TextAlign |
| 14 | +import com.ninecraft.booket.core.common.utils.isNetworkError |
| 15 | +import com.ninecraft.booket.core.designsystem.ComponentPreview |
| 16 | +import com.ninecraft.booket.core.designsystem.component.button.ReedButton |
| 17 | +import com.ninecraft.booket.core.designsystem.component.button.ReedButtonColorStyle |
| 18 | +import com.ninecraft.booket.core.designsystem.component.button.mediumButtonStyle |
| 19 | +import com.ninecraft.booket.core.designsystem.theme.ReedTheme |
| 20 | +import com.ninecraft.booket.core.ui.R |
| 21 | + |
| 22 | +@Composable |
| 23 | +fun ReedErrorUi( |
| 24 | + exception: Throwable, |
| 25 | + onRetryClick: () -> Unit, |
| 26 | +) { |
| 27 | + val message = if (exception.isNetworkError()) stringResource(R.string.network_error_message) else stringResource(R.string.server_error_message) |
| 28 | + Box( |
| 29 | + modifier = Modifier.fillMaxSize(), |
| 30 | + contentAlignment = Alignment.Center, |
| 31 | + ) { |
| 32 | + Column(horizontalAlignment = Alignment.CenterHorizontally) { |
| 33 | + Text( |
| 34 | + text = message, |
| 35 | + color = ReedTheme.colors.contentSecondary, |
| 36 | + textAlign = TextAlign.Center, |
| 37 | + style = ReedTheme.typography.body1Medium, |
| 38 | + ) |
| 39 | + Spacer(modifier = Modifier.height(ReedTheme.spacing.spacing6)) |
| 40 | + ReedButton( |
| 41 | + onClick = { onRetryClick() }, |
| 42 | + text = stringResource(R.string.retry), |
| 43 | + colorStyle = ReedButtonColorStyle.PRIMARY, |
| 44 | + sizeStyle = mediumButtonStyle, |
| 45 | + ) |
| 46 | + } |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +@ComponentPreview |
| 51 | +@Composable |
| 52 | +private fun ReedNetworkErrorUiPreview() { |
| 53 | + ReedErrorUi( |
| 54 | + exception = java.io.IOException("네트워크 오류"), |
| 55 | + onRetryClick = {}, |
| 56 | + ) |
| 57 | +} |
| 58 | + |
| 59 | +@ComponentPreview |
| 60 | +@Composable |
| 61 | +private fun ReedServerErrorUiPreview() { |
| 62 | + ReedErrorUi( |
| 63 | + exception = Exception("알 수 없는 문제"), |
| 64 | + onRetryClick = {}, |
| 65 | + ) |
| 66 | +} |
0 commit comments