Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with dns dialog showing wrong state after submitting #6617

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -55,11 +56,12 @@ class DnsDialogViewModel(
) : ViewModel() {
private val navArgs = DnsDestination.argsFrom(savedStateHandle)

private val settings = MutableStateFlow<Settings?>(null)
private val currentIndex = MutableStateFlow(navArgs.index)
private val _ipAddressInput = MutableStateFlow(navArgs.initialValue ?: EMPTY_STRING)

val uiState: StateFlow<DnsDialogViewState> =
combine(_ipAddressInput, currentIndex, repository.settingsUpdates.filterNotNull()) {
combine(_ipAddressInput, currentIndex, settings.filterNotNull()) {
input,
currentIndex,
settings ->
Expand All @@ -74,6 +76,10 @@ class DnsDialogViewModel(
private val _uiSideEffect = Channel<DnsDialogSideEffect>()
val uiSideEffect = _uiSideEffect.receiveAsFlow()

init {
viewModelScope.launch { settings.emit(repository.settingsUpdates.filterNotNull().first()) }
}

private fun createViewState(
customDnsList: List<InetAddress>,
currentIndex: Int?,
Expand Down Expand Up @@ -116,7 +122,7 @@ class DnsDialogViewModel(
if (index != null) {
repository.setCustomDns(index = index, address = address)
} else {
repository.addCustomDns(address = address).onRight { currentIndex.value = it }
repository.addCustomDns(address = address)
}

result.fold(
Expand Down
Loading