Repository: thunderbird/thunderbird-android
File: feature/navigation/drawer/src/main/kotlin/app/k9mail/feature/navigation/drawer/ui/DrawerViewModel.kt (Kotlin)

Code before:
    }

    override fun event(event: Event) {
        when (event) {
            is Event.SelectAccount -> selectAccount(event.accountId)
            is Event.SelectFolder -> selectFolder(event.folderId)

            is Event.OnAccountClick -> openAccount(event.account)
            is Event.OnFolderClick -> openFolder(event.folder)
            is Event.OnAccountViewClick -> {
                openAccount(
                    state.value.accounts.nextOrFirst(event.account),
                )
            }

            Event.OnAccountSelectorClick -> {
                viewModelScope.launch {
                    saveDrawerConfig.invoke(
                        state.value.config.copy(showAccountSelector = state.value.config.showAccountSelector.not()),
                    ).collect {
                        updateState {
                            it.copy(
                                config = it.config.copy(showAccountSelector = it.config.showAccountSelector.not()),
                            )
                        }
                    }
                }
            }
            Event.OnManageFoldersClick -> emitEffect(Effect.OpenManageFolders)
            Event.OnSettingsClick -> emitEffect(Effect.OpenSettings)
            Event.OnSyncAccount -> onSyncAccount()
            Event.OnSyncAllAccounts -> onSyncAllAccounts()
        }
    }

    private fun selectAccount(accountId: String?) {
        updateState {
            it.copy(
                selectedAccountId = accountId,
            )
        }
    }

    private fun selectFolder(folderId: String?) {
        updateState {
            it.copy(
                selectedFolderId = folderId,
            )
        }
    }


Review comment (refactor):
This could be just:

```suggestion
                    saveDrawerConfig(
                        state.value.config.copy(showAccountSelector = state.value.config.showAccountSelector.not()),
                    )
```

The use case syntax of `operator fun invoke(...)` allows use of `saveDrawerConfig(...)` which makes the code better readable.

As we're aiming for a unidirectional data flow, the save state doesn't need to be collected (exception if error handling is necessary). Instead the `GetDrawerConfig` use case should emit the updated `DrawerConfig`. This is sadly not the case at the moment, hence the need for collect to propagate changes immediately.

I think https://github.com/thunderbird/thunderbird-android/pull/8763 shows a path how to do this without the need for collect. But rather than using the `GeneralSettingsManager` it should use an extracted version of the notification logic and make that available for use in feature configurations.

Code after:
        }
    }

    override fun event(event: Event) {
        when (event) {
            is Event.SelectAccount -> selectAccount(event.accountId)
            is Event.SelectFolder -> selectFolder(event.folderId)

            is Event.OnAccountClick -> openAccount(event.account)
            is Event.OnFolderClick -> openFolder(event.folder)
            is Event.OnAccountViewClick -> {
                openAccount(
                    state.value.accounts.nextOrFirst(event.account),
                )
            }

            Event.OnAccountSelectorClick -> {
                saveDrawerConfig(
                    state.value.config.copy(showAccountSelector = state.value.config.showAccountSelector.not()),
                ).launchIn(viewModelScope)
            }
            Event.OnManageFoldersClick -> emitEffect(Effect.OpenManageFolders)
            Event.OnSettingsClick -> emitEffect(Effect.OpenSettings)
            Event.OnSyncAccount -> onSyncAccount()
            Event.OnSyncAllAccounts -> onSyncAllAccounts()
        }
    }

    private fun selectAccount(accountId: String?) {
        updateState {
            it.copy(
                selectedAccountId = accountId,
            )
        }
    }

    private fun selectFolder(folderId: String?) {
        updateState {
            it.copy(
                selectedFolderId = folderId,
            )
        }
    }

    private fun openAccount(account: DisplayAccount?) {
        if (account != null) {
            emitEffect(Effect.OpenAccount(account.id))
        }
    }

    private fun ImmutableList<DisplayAccount>.nextOrFirst(account: DisplayAccount): DisplayAccount? {