feat: add pull to refresh
This commit is contained in:
parent
ab727dd061
commit
ef52e39c0d
1 changed files with 5 additions and 4 deletions
|
@ -2,7 +2,6 @@ package xyz.leomurca.csgomatches.ui.screens.matches
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
@ -14,6 +13,7 @@ import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.material3.TopAppBarDefaults
|
import androidx.compose.material3.TopAppBarDefaults
|
||||||
|
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
|
@ -22,7 +22,6 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import xyz.leomurca.csgomatches.domain.model.Match
|
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.components.MatchCard
|
||||||
import xyz.leomurca.csgomatches.ui.navigation.MatchDetailsRoute
|
import xyz.leomurca.csgomatches.ui.navigation.MatchDetailsRoute
|
||||||
import xyz.leomurca.csgomatches.ui.screens.matches.MatchesViewModel.MatchesUiState
|
import xyz.leomurca.csgomatches.ui.screens.matches.MatchesViewModel.MatchesUiState
|
||||||
|
@ -55,7 +54,9 @@ fun MatchesScreen(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}) { innerPadding ->
|
}) { innerPadding ->
|
||||||
Box(
|
PullToRefreshBox(
|
||||||
|
isRefreshing = uiState.value is MatchesUiState.Loading,
|
||||||
|
onRefresh = { viewModel.loadUpcomingMatches() },
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(innerPadding)
|
.padding(innerPadding)
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
|
@ -63,9 +64,9 @@ fun MatchesScreen(
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
when (val value = uiState.value) {
|
when (val value = uiState.value) {
|
||||||
is MatchesUiState.Loading -> LoadingIndicator()
|
|
||||||
is MatchesUiState.Success -> MatchesList(value.matches, onTapCard)
|
is MatchesUiState.Success -> MatchesList(value.matches, onTapCard)
|
||||||
is MatchesUiState.Error -> Text(value.message)
|
is MatchesUiState.Error -> Text(value.message)
|
||||||
|
else -> Unit // Do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue