Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Insights page flashes from "Nothing to display" to showing logged workouts #81

Open
2 tasks done
matt-auckland opened this issue Jul 19, 2021 · 1 comment
Open
2 tasks done
Labels
bug Something isn't working

Comments

@matt-auckland
Copy link

Describe the bug
When I go to look at my logged workouts, the page displays a "Nothing to show" screen for a split second before it displays my logged workouts. I assume it's not trying to wait and load data before displaying the "nothing to show" screen

To Reproduce
Steps to reproduce the behavior:

  1. Go to insights (when you have at least one workout logged)
  2. The screen should flash "nothing to show"

Expected behavior
Perhaps show a blank screen to begin with and then display "nothing to show" or the list of logged workouts, instead of showing "nothing to show" before you have loaded (or tried to load) logged workouts.

Screenshots / Screen recordings
If applicable, add screenshots or screen recordings to help explain your problem.

Smartphone (please complete the following information):

  • Device: OnePlus 6
  • Android version: Android 10

Additional notes:

I'm not a Kotlin dev but if this is a simple fix I could try my hand at fixing it, just point me in the correct direction with a few instructions and I'll give it a go.

@matt-auckland matt-auckland added the bug Something isn't working label Jul 19, 2021
@noahjutz noahjutz reopened this Jul 20, 2021
@noahjutz
Copy link
Owner

noahjutz commented Jul 20, 2021

woops. Thanks for the bug report. If you'd like to try fixing it, here's the source of the bug:

val workouts by viewModel.presenter.workouts.collectAsState(initial = emptyList())
if (workouts.isEmpty()) NothingHereYet("Insights will be available when you finish your first workout.")
else WorkoutInsightsContent(viewModel, navToWorkoutEditor)

workouts is initially an empty list, which causes NothingHereYet to be displayed. A possible solution would be to make it null initially, in order to differentiate the state of loading with the state of no results.

I'm not a huge fan of that solution since now we have to handle that workouts is nullable. Another solution could be to create a sealed class for the state of the screen in its ViewModel:

sealed class State {
  object Loading : State()
  data class Found(val workouts: List<Workout>) : State()
  object Empty : State()
}

A value of type MutableStateFlow<State> could be declared in the ViewModel and listened to from the composable.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants