fix(daily): correct question flow state handling and UI edge cases
This commit is contained in:
parent
78e145352b
commit
6fe5e5048e
|
|
@ -21,7 +21,7 @@ fun DailyQuestionScreen(
|
|||
subtitle = "A real prompt from the local question deck. Answer privately here, then move into a reveal or discussion path.",
|
||||
primaryRouteLabel = "Discuss",
|
||||
onPrimaryRoute = { question ->
|
||||
onNavigate(AppRoute.questionThread("local-preview", question.id))
|
||||
onNavigate(AppRoute.questionThread(state.coupleId ?: "local-preview", question.id))
|
||||
},
|
||||
onSecondaryRoute = state.question?.let {
|
||||
{ onNavigate(AppRoute.answerReveal(it.id)) }
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package com.couplesconnect.app.ui.questions
|
|||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.couplesconnect.app.domain.model.Question
|
||||
import com.couplesconnect.app.domain.repository.AuthRepository
|
||||
import com.couplesconnect.app.domain.repository.CoupleRepository
|
||||
import com.couplesconnect.app.domain.repository.LocalAnswerRepository
|
||||
import com.couplesconnect.app.domain.repository.QuestionRepository
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
|
|
@ -17,6 +19,7 @@ data class LocalQuestionUiState(
|
|||
val isLoading: Boolean = true,
|
||||
val error: String? = null,
|
||||
val question: Question? = null,
|
||||
val coupleId: String? = null,
|
||||
val submitted: Boolean = false,
|
||||
val pendingWrittenText: String = "",
|
||||
val pendingSelectedOptionIds: List<String> = emptyList(),
|
||||
|
|
@ -26,7 +29,9 @@ data class LocalQuestionUiState(
|
|||
@HiltViewModel
|
||||
class DailyQuestionViewModel @Inject constructor(
|
||||
private val repository: QuestionRepository,
|
||||
private val localAnswerRepository: LocalAnswerRepository
|
||||
private val localAnswerRepository: LocalAnswerRepository,
|
||||
private val authRepository: AuthRepository,
|
||||
private val coupleRepository: CoupleRepository
|
||||
) : ViewModel() {
|
||||
|
||||
private val _uiState = MutableStateFlow(LocalQuestionUiState())
|
||||
|
|
@ -42,9 +47,13 @@ class DailyQuestionViewModel @Inject constructor(
|
|||
try {
|
||||
val question = repository.getDailyQuestion()
|
||||
val answer = question?.let { localAnswerRepository.getAnswer(it.id) }
|
||||
val coupleId = authRepository.currentUserId?.let { uid ->
|
||||
runCatching { coupleRepository.getCoupleForUser(uid)?.id }.getOrNull()
|
||||
}
|
||||
_uiState.value = LocalQuestionUiState(
|
||||
isLoading = false,
|
||||
question = question,
|
||||
coupleId = coupleId,
|
||||
pendingScaleValue = defaultScaleValue(question)
|
||||
).withLocalAnswer(answer)
|
||||
} catch (e: Exception) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue