Merge pull request #7444 from thunderbird/special_folders_fix_1

Don't delay when user clicks 'Next' in special folders screen
This commit is contained in:
cketti 2024-01-02 21:12:30 +01:00 committed by GitHub
commit 8b21d9a239
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 38 deletions

View file

@ -58,8 +58,6 @@ interface SpecialFoldersContract {
sealed interface Failure {
val message: String
data class MissingIncomingServerSettings(override val message: String) : Failure
data class LoadFoldersFailed(override val message: String) : Failure
data class SaveFailed(override val message: String) : Failure
}
}

View file

@ -9,7 +9,6 @@ import app.k9mail.feature.account.common.domain.entity.SpecialFolderSettings
import app.k9mail.feature.account.setup.domain.DomainContract.UseCase
import app.k9mail.feature.account.setup.ui.specialfolders.SpecialFoldersContract.Effect
import app.k9mail.feature.account.setup.ui.specialfolders.SpecialFoldersContract.Event
import app.k9mail.feature.account.setup.ui.specialfolders.SpecialFoldersContract.Failure.SaveFailed
import app.k9mail.feature.account.setup.ui.specialfolders.SpecialFoldersContract.FormEvent
import app.k9mail.feature.account.setup.ui.specialfolders.SpecialFoldersContract.State
import app.k9mail.feature.account.setup.ui.specialfolders.SpecialFoldersContract.ViewModel
@ -78,7 +77,11 @@ class SpecialFoldersViewModel(
isSuccess = true,
)
}
saveSpecialFolderSettings()
delay(CONTINUE_NEXT_DELAY)
navigateNext()
}
}
}
@ -100,44 +103,28 @@ class SpecialFoldersViewModel(
}
}
@Suppress("TooGenericExceptionCaught")
private suspend fun saveSpecialFolderSettings() {
private fun saveSpecialFolderSettings() {
val formState = state.value.formState
try {
accountStateRepository.setSpecialFolderSettings(
SpecialFolderSettings(
archiveSpecialFolderOption = formState.selectedArchiveSpecialFolderOption,
draftsSpecialFolderOption = formState.selectedDraftsSpecialFolderOption,
sentSpecialFolderOption = formState.selectedSentSpecialFolderOption,
spamSpecialFolderOption = formState.selectedSpamSpecialFolderOption,
trashSpecialFolderOption = formState.selectedTrashSpecialFolderOption,
),
accountStateRepository.setSpecialFolderSettings(
SpecialFolderSettings(
archiveSpecialFolderOption = formState.selectedArchiveSpecialFolderOption,
draftsSpecialFolderOption = formState.selectedDraftsSpecialFolderOption,
sentSpecialFolderOption = formState.selectedSentSpecialFolderOption,
spamSpecialFolderOption = formState.selectedSpamSpecialFolderOption,
trashSpecialFolderOption = formState.selectedTrashSpecialFolderOption,
),
)
updateState { state ->
state.copy(
isLoading = false,
)
updateState { state ->
state.copy(
isLoading = false,
)
}
} catch (exception: Exception) {
Timber.e(exception, "Error while saving special folders")
updateState { state ->
state.copy(
isLoading = false,
error = SaveFailed(exception.message ?: "unknown error"),
)
}
return
}
delay(CONTINUE_NEXT_DELAY)
navigateNext()
}
private fun onNextClicked() {
viewModelScope.launch {
saveSpecialFolderSettings()
}
saveSpecialFolderSettings()
navigateNext()
}
private fun navigateNext() {

View file

@ -197,9 +197,7 @@ class SpecialFoldersViewModelTest {
testSubject.event(Event.OnNextClicked)
turbines.assertThatAndStateTurbineConsumed {
isEqualTo(initialState.copy(isLoading = false))
}
assertThat(turbines.awaitStateItem()).isEqualTo(initialState.copy(isLoading = false))
turbines.assertThatAndEffectTurbineConsumed {
isEqualTo(Effect.NavigateNext)
@ -245,7 +243,7 @@ class SpecialFoldersViewModelTest {
@Test
fun `should show form when OnRetryClicked event received`() = runTest {
val initialState = State(error = SpecialFoldersContract.Failure.SaveFailed("error"))
val initialState = State(error = SpecialFoldersContract.Failure.LoadFoldersFailed("irrelevant"))
val testSubject = createTestSubject(initialState = initialState)
val turbines = turbinesWithInitialStateCheck(testSubject, initialState)