增删改防止重复点击
This commit is contained in:
@@ -94,12 +94,16 @@ class CountdownViewModel(
|
||||
private fun addCountdown(countdown: Countdown) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
if (state.value.isProcessing) return@launch
|
||||
updateState { copy(isLoading = false, isProcessing = true) }
|
||||
countdownRepository.insertCountdown(countdown)
|
||||
sendEvent(CountdownEffect.ShowMessage(getString(Res.string.countdown_add_success)))
|
||||
sendEvent(CountdownEffect.NavigateBack)
|
||||
} catch (e: Exception) {
|
||||
val errStr = getString(Res.string.countdown_add_failed)
|
||||
updateState { copy(isLoading = false, error = e.message ?: errStr) }
|
||||
updateState { copy(error = e.message ?: errStr) }
|
||||
} finally {
|
||||
updateState { copy(isLoading = false, isProcessing = false) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,12 +111,16 @@ class CountdownViewModel(
|
||||
private fun updateCountdown(countdown: Countdown) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
if (state.value.isProcessing) return@launch
|
||||
updateState { copy(isLoading = false, isProcessing = true) }
|
||||
countdownRepository.updateCountdown(countdown)
|
||||
sendEvent(CountdownEffect.ShowMessage(getString(Res.string.countdown_update_success)))
|
||||
sendEvent(CountdownEffect.NavigateBack)
|
||||
} catch (e: Exception) {
|
||||
val errStr = getString(Res.string.countdown_update_failed)
|
||||
updateState { copy(isLoading = false, error = e.message ?: errStr) }
|
||||
updateState { copy(error = e.message ?: errStr) }
|
||||
} finally {
|
||||
updateState { copy(isLoading = false, isProcessing = false) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,11 +128,15 @@ class CountdownViewModel(
|
||||
private fun deleteCountdown(countdownId: String) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
if (state.value.isProcessing) return@launch
|
||||
updateState { copy(isLoading = false, isProcessing = true) }
|
||||
countdownRepository.deleteCountdown(countdownId)
|
||||
sendEvent(CountdownEffect.ShowMessage(getString(Res.string.countdown_delete_success)))
|
||||
} catch (e: Exception) {
|
||||
val errStr = getString(Res.string.countdown_delete_failed)
|
||||
updateState { copy(isLoading = false, error = e.message ?: errStr) }
|
||||
updateState { copy(error = e.message ?: errStr) }
|
||||
} finally {
|
||||
updateState { copy(isLoading = false, isProcessing = false) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user