fix: stop the connect card from flashing on every screen open

hasPermission started false while the async permission check ran, so the
"Share your workouts" connect card flashed for ~1s on every open before the
check confirmed permission was already granted. Make permission a tri-state
(null = not checked yet) and render nothing until it resolves, so the connect
prompt only appears once we actually know permission is missing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015qgqQKHSewRHVM8vSCLt9P
This commit is contained in:
Claude
2026-06-16 23:29:12 +00:00
parent fdf7682409
commit a9cb2f464b
2 changed files with 10 additions and 3 deletions
@@ -125,7 +125,11 @@ fun WorkoutSuggestions(
val hasPermission by state.hasPermission.collectAsStateWithLifecycle()
var connectDismissed by rememberSaveable(pubkeyHex) { mutableStateOf(false) }
if (suggestions.isEmpty() && (hasPermission || connectDismissed)) return
// Not checked yet: render nothing so the connect prompt never flashes during the check.
val granted = hasPermission ?: return
val showConnect = !granted && !connectDismissed
if (suggestions.isEmpty() && !showConnect) return
Column(
modifier =
@@ -135,7 +139,7 @@ fun WorkoutSuggestions(
.animateContentSize(),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
if (!hasPermission && !connectDismissed) {
if (showConnect) {
ConnectHealthCard(
onConnect = { permissionLauncher.launch(HealthConnectManager.PERMISSIONS) },
onDismiss = { connectDismissed = true },
@@ -53,7 +53,10 @@ class WorkoutSuggestionState(
private val _suggestions = MutableStateFlow<List<DetectedWorkout>>(emptyList())
val suggestions = _suggestions.asStateFlow()
private val _hasPermission = MutableStateFlow(false)
// null = not checked yet. Kept distinct from false so the connect prompt is only shown
// once we actually know permission is missing, never during the async check (which would
// otherwise flash the prompt every time the screen opens for an already-granted user).
private val _hasPermission = MutableStateFlow<Boolean?>(null)
val hasPermission = _hasPermission.asStateFlow()
suspend fun refresh() {