Skip to content

Commit

Permalink
Add loading state to saved trips
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharma-xyz committed Nov 24, 2024
1 parent 3f4e7b5 commit 3bb6c89
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import xyz.ksharma.krail.trip.planner.ui.state.timetable.Trip

data class SavedTripsState(val savedTrips: ImmutableList<Trip> = persistentListOf())
data class SavedTripsState(
val savedTrips: ImmutableList<Trip> = persistentListOf(),
val isLoading: Boolean = true,
)
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fun SavedTripsScreen(
Spacer(modifier = Modifier.height(12.dp))
}

if (savedTripsState.savedTrips.isEmpty()) {
if (savedTripsState.savedTrips.isEmpty() && savedTripsState.isLoading.not()) {
item(key = "empty_state") {
ErrorMessage(
emoji = "🌟",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SavedTripsViewModel(

private fun loadSavedTrips() {
viewModelScope.launch(context = Dispatchers.IO) {
updateUiState { copy(isLoading = true) }
val trips = mutableSetOf<Trip>()

val savedTrips = sandook.selectAllTrips()
Expand All @@ -42,7 +43,7 @@ class SavedTripsViewModel(
println("\t SavedTrip: #$index ${trip.fromStopName} -> ${trip.toStopName}")
}

updateUiState { copy(savedTrips = trips.toImmutableList()) }
updateUiState { copy(savedTrips = trips.toImmutableList(), isLoading = false) }
}
}

Expand Down

0 comments on commit 3bb6c89

Please sign in to comment.