Skip to content

Commit

Permalink
Merge pull request #7444 from thunderbird/special_folders_fix_1
Browse files Browse the repository at this point in the history
Don't delay when user clicks 'Next' in special folders screen
  • Loading branch information
cketti authored Jan 2, 2024
2 parents cd8274a + 6749326 commit 8b21d9a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,7 +77,11 @@ class SpecialFoldersViewModel(
isSuccess = true,
)
}

saveSpecialFolderSettings()

delay(CONTINUE_NEXT_DELAY)
navigateNext()
}
}
}
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 8b21d9a

Please sign in to comment.