fix: answer reveal and question category UI/state fixes
This commit is contained in:
parent
a0fd1d56f6
commit
c89e4f6bba
|
|
@ -55,7 +55,13 @@ fun AnswerRevealScreen(
|
|||
questionId = questionId,
|
||||
onReveal = viewModel::revealAnswer,
|
||||
onAnswerQuestion = {
|
||||
onNavigate(AppRoute.questionThread("couple", questionId))
|
||||
val coupleId = state.coupleId
|
||||
if (coupleId != null) {
|
||||
onNavigate(AppRoute.questionThread(coupleId, questionId))
|
||||
} else {
|
||||
// Discussing requires a paired partner; send unpaired users to invite one.
|
||||
onNavigate(AppRoute.CREATE_INVITE)
|
||||
}
|
||||
},
|
||||
onHistory = { onNavigate(AppRoute.ANSWER_HISTORY) },
|
||||
onHome = { onNavigate(AppRoute.HOME) }
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import app.closer.domain.model.LocalAnswer
|
||||
import app.closer.domain.model.Question
|
||||
import app.closer.domain.repository.AuthRepository
|
||||
import app.closer.domain.repository.CoupleRepository
|
||||
import app.closer.domain.repository.LocalAnswerRepository
|
||||
import app.closer.domain.repository.QuestionRepository
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
|
|
@ -19,13 +21,16 @@ data class AnswerRevealUiState(
|
|||
val isLoading: Boolean = true,
|
||||
val error: String? = null,
|
||||
val question: Question? = null,
|
||||
val answer: LocalAnswer? = null
|
||||
val answer: LocalAnswer? = null,
|
||||
val coupleId: String? = null
|
||||
)
|
||||
|
||||
@HiltViewModel
|
||||
class AnswerRevealViewModel @Inject constructor(
|
||||
private val questionRepository: QuestionRepository,
|
||||
private val localAnswerRepository: LocalAnswerRepository,
|
||||
private val authRepository: AuthRepository,
|
||||
private val coupleRepository: CoupleRepository,
|
||||
savedStateHandle: SavedStateHandle
|
||||
) : ViewModel() {
|
||||
|
||||
|
|
@ -43,10 +48,14 @@ class AnswerRevealViewModel @Inject constructor(
|
|||
viewModelScope.launch {
|
||||
_uiState.value = AnswerRevealUiState(isLoading = true)
|
||||
try {
|
||||
val coupleId = authRepository.currentUserId?.let { uid ->
|
||||
runCatching { coupleRepository.getCoupleForUser(uid)?.id }.getOrNull()
|
||||
}
|
||||
_uiState.value = AnswerRevealUiState(
|
||||
isLoading = false,
|
||||
question = questionRepository.getQuestionById(questionId),
|
||||
answer = localAnswerRepository.getAnswer(questionId)
|
||||
answer = localAnswerRepository.getAnswer(questionId),
|
||||
coupleId = coupleId
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
_uiState.value = AnswerRevealUiState(
|
||||
|
|
|
|||
|
|
@ -21,7 +21,13 @@ fun DailyQuestionScreen(
|
|||
subtitle = "Answer privately first, then choose whether to reveal it or keep the conversation going.",
|
||||
primaryRouteLabel = "Discuss",
|
||||
onPrimaryRoute = { question ->
|
||||
onNavigate(AppRoute.questionThread(state.coupleId ?: "couple", question.id))
|
||||
val coupleId = state.coupleId
|
||||
if (coupleId != null) {
|
||||
onNavigate(AppRoute.questionThread(coupleId, question.id))
|
||||
} else {
|
||||
// Discussing requires a paired partner; send unpaired users to invite one.
|
||||
onNavigate(AppRoute.CREATE_INVITE)
|
||||
}
|
||||
},
|
||||
onSecondaryRoute = state.question?.let {
|
||||
{ onNavigate(AppRoute.answerReveal(it.id)) }
|
||||
|
|
|
|||
|
|
@ -55,7 +55,13 @@ fun QuestionCategoryScreen(
|
|||
categoryId = categoryId,
|
||||
state = state,
|
||||
onQuestionSelected = { question ->
|
||||
onNavigate(AppRoute.questionThread("couple", question.id))
|
||||
val coupleId = state.coupleId
|
||||
if (coupleId != null) {
|
||||
onNavigate(AppRoute.questionThread(coupleId, question.id))
|
||||
} else {
|
||||
// Discussing requires a paired partner; send unpaired users to invite one.
|
||||
onNavigate(AppRoute.CREATE_INVITE)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import app.closer.domain.model.Question
|
||||
import app.closer.domain.model.QuestionCategory
|
||||
import app.closer.domain.repository.AuthRepository
|
||||
import app.closer.domain.repository.CoupleRepository
|
||||
import app.closer.domain.repository.QuestionRepository
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import javax.inject.Inject
|
||||
|
|
@ -17,12 +19,15 @@ data class QuestionCategoryUiState(
|
|||
val isLoading: Boolean = true,
|
||||
val error: String? = null,
|
||||
val category: QuestionCategory? = null,
|
||||
val questions: List<Question> = emptyList()
|
||||
val questions: List<Question> = emptyList(),
|
||||
val coupleId: String? = null
|
||||
)
|
||||
|
||||
@HiltViewModel
|
||||
class QuestionCategoryViewModel @Inject constructor(
|
||||
private val repository: QuestionRepository,
|
||||
private val authRepository: AuthRepository,
|
||||
private val coupleRepository: CoupleRepository,
|
||||
savedStateHandle: SavedStateHandle
|
||||
) : ViewModel() {
|
||||
|
||||
|
|
@ -41,10 +46,14 @@ class QuestionCategoryViewModel @Inject constructor(
|
|||
try {
|
||||
val category = repository.getCategoryById(categoryId)
|
||||
val questions = repository.getQuestionsByCategory(categoryId)
|
||||
val coupleId = authRepository.currentUserId?.let { uid ->
|
||||
runCatching { coupleRepository.getCoupleForUser(uid)?.id }.getOrNull()
|
||||
}
|
||||
_uiState.value = QuestionCategoryUiState(
|
||||
isLoading = false,
|
||||
category = category,
|
||||
questions = questions
|
||||
questions = questions,
|
||||
coupleId = coupleId
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
_uiState.value = QuestionCategoryUiState(
|
||||
|
|
|
|||
Loading…
Reference in New Issue