Skip to content

Commit 5f70bee

Browse files
Pururunalbin-mullvad
authored andcommitted
Fix issues with dns dialog showing wrong state after submitting
1 parent 90cb3c3 commit 5f70bee

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DnsDialogViewModel.kt

+8-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.SharingStarted
1616
import kotlinx.coroutines.flow.StateFlow
1717
import kotlinx.coroutines.flow.combine
1818
import kotlinx.coroutines.flow.filterNotNull
19+
import kotlinx.coroutines.flow.first
1920
import kotlinx.coroutines.flow.receiveAsFlow
2021
import kotlinx.coroutines.flow.stateIn
2122
import kotlinx.coroutines.launch
@@ -55,11 +56,12 @@ class DnsDialogViewModel(
5556
) : ViewModel() {
5657
private val navArgs = DnsDestination.argsFrom(savedStateHandle)
5758

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

6163
val uiState: StateFlow<DnsDialogViewState> =
62-
combine(_ipAddressInput, currentIndex, repository.settingsUpdates.filterNotNull()) {
64+
combine(_ipAddressInput, currentIndex, settings.filterNotNull()) {
6365
input,
6466
currentIndex,
6567
settings ->
@@ -74,6 +76,10 @@ class DnsDialogViewModel(
7476
private val _uiSideEffect = Channel<DnsDialogSideEffect>()
7577
val uiSideEffect = _uiSideEffect.receiveAsFlow()
7678

79+
init {
80+
viewModelScope.launch { settings.emit(repository.settingsUpdates.filterNotNull().first()) }
81+
}
82+
7783
private fun createViewState(
7884
customDnsList: List<InetAddress>,
7985
currentIndex: Int?,
@@ -116,7 +122,7 @@ class DnsDialogViewModel(
116122
if (index != null) {
117123
repository.setCustomDns(index = index, address = address)
118124
} else {
119-
repository.addCustomDns(address = address).onRight { currentIndex.value = it }
125+
repository.addCustomDns(address = address)
120126
}
121127

122128
result.fold(

0 commit comments

Comments
 (0)