feat: add pull to refresh

This commit is contained in:
Leonardo Murça 2025-07-19 14:44:58 -03:00
parent ab727dd061
commit ef52e39c0d

View file

@ -2,7 +2,6 @@ package xyz.leomurca.csgomatches.ui.screens.matches
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
@ -14,6 +13,7 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment
@ -22,7 +22,6 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import xyz.leomurca.csgomatches.domain.model.Match
import xyz.leomurca.csgomatches.ui.components.LoadingIndicator
import xyz.leomurca.csgomatches.ui.components.MatchCard
import xyz.leomurca.csgomatches.ui.navigation.MatchDetailsRoute
import xyz.leomurca.csgomatches.ui.screens.matches.MatchesViewModel.MatchesUiState
@ -55,7 +54,9 @@ fun MatchesScreen(
)
)
}) { innerPadding ->
Box(
PullToRefreshBox(
isRefreshing = uiState.value is MatchesUiState.Loading,
onRefresh = { viewModel.loadUpcomingMatches() },
modifier = Modifier
.padding(innerPadding)
.fillMaxSize()
@ -63,9 +64,9 @@ fun MatchesScreen(
contentAlignment = Alignment.Center
) {
when (val value = uiState.value) {
is MatchesUiState.Loading -> LoadingIndicator()
is MatchesUiState.Success -> MatchesList(value.matches, onTapCard)
is MatchesUiState.Error -> Text(value.message)
else -> Unit // Do nothing
}
}
}