Skip to content

Commit

Permalink
start adding to exams
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-tennert committed Sep 4, 2023
1 parent 6f8794e commit a331ca6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/src/main/java/io/github/jan/kex/ui/screen/AppScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ fun AppScreen(
}
}
composable(NavigationTarget.Exams.Create.destination) {
ExamCreateScreen { subject, date, theme, type ->
val subjectSuggestions by examVm.subjectSuggestions.collectAsStateWithLifecycle()
ExamCreateScreen(subjectSuggestions) { subject, date, theme, type ->
examVm.createExam(subject, date, theme, type)
navController.navigate(NavigationTarget.Exams.destination)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ import kotlin.time.Duration.Companion.milliseconds
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ExamCreateScreen(
suggestions: List<String>,
onCreate: (subject: String, date: String, theme: String, type: Exam.Type) -> Unit,
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
var subject by remember { mutableStateOf("") }
val filteredSuggestions by remember(subject, suggestions) {
suggestions.filter { it.contains(subject) }.take(2)
}
val datePickerState = rememberDatePickerState()
var showDatePicker by remember { mutableStateOf(false) }
val theme by remember { mutableStateOf(RichTextState()) }
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/io/github/jan/kex/vm/ExamViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import io.github.jan.kex.data.remote.toExam
import io.github.jan.supabase.exceptions.BadRequestRestException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
Expand All @@ -33,7 +35,7 @@ class ExamViewModel(
exams.filter { it.date > currentDate || showPastExams }.sortedBy { it.date }
}
val error = MutableStateFlow<Int?>(null)
val subjectSuggestions: Flow<List<String>> = subjectSuggestionDataSource.getSuggestionsAsFlow()
val subjectSuggestions: Flow<List<String>> = subjectSuggestionDataSource.getSuggestionsAsFlow().stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())

fun refreshExams(username: String?, password: String?) {
isLoading.value = true
Expand Down

0 comments on commit a331ca6

Please sign in to comment.