Skip to content

Commit

Permalink
Merge branch 'adding-custom-dns-briefly-shows-error-on-submit-droid-1…
Browse files Browse the repository at this point in the history
…230'
  • Loading branch information
albin-mullvad committed Aug 15, 2024
2 parents 90cb3c3 + 5f70bee commit 1d893ca
Showing 1 changed file with 8 additions and 2 deletions.
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

0 comments on commit 1d893ca

Please sign in to comment.