mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Show loading/failure states when setting/clearing user status. (#5993)
This commit is contained in:
@@ -162,35 +162,55 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func setUserStatus(_ status: UserStatus.Raw) async {
|
private func setUserStatus(_ status: UserStatus.Raw) async {
|
||||||
// Loading state tbc
|
showSavingIndicator()
|
||||||
|
defer { hideSavingIndicator() }
|
||||||
|
|
||||||
state.bindings.isPresentingStatusPicker = false
|
state.bindings.isPresentingStatusPicker = false
|
||||||
state.bindings.isShowingCustomStatusField = false
|
state.bindings.isShowingCustomStatusField = false
|
||||||
|
|
||||||
switch await clientProxy.setUserStatus(status) {
|
if case .failure = await clientProxy.setUserStatus(status) {
|
||||||
case .success:
|
showFailureIndicator()
|
||||||
break // Loading/error state tbc
|
|
||||||
case .failure:
|
|
||||||
userIndicatorController.submitIndicator(.init(id: UUID().uuidString,
|
|
||||||
type: .toast,
|
|
||||||
title: L10n.errorUnknown,
|
|
||||||
icon: \.close))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clears both the `UserStatus.Raw` and `UserStatus.Call` values simultaneously.
|
/// Clears both the `UserStatus.Raw` and `UserStatus.Call` values simultaneously.
|
||||||
private func clearUserStatus() async {
|
private func clearUserStatus() async {
|
||||||
// Loading state tbc
|
showSavingIndicator()
|
||||||
|
defer { hideSavingIndicator() }
|
||||||
|
|
||||||
state.bindings.isPresentingStatusPicker = false
|
state.bindings.isPresentingStatusPicker = false
|
||||||
state.bindings.isShowingCustomStatusField = false
|
state.bindings.isShowingCustomStatusField = false
|
||||||
|
|
||||||
switch await clientProxy.clearUserStatus() {
|
if case .failure = await clientProxy.clearUserStatus() {
|
||||||
case .success:
|
showFailureIndicator()
|
||||||
break // Loading/error state tbc
|
|
||||||
case .failure:
|
|
||||||
userIndicatorController.submitIndicator(.init(id: UUID().uuidString,
|
|
||||||
type: .toast,
|
|
||||||
title: L10n.errorUnknown,
|
|
||||||
icon: \.close))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Indicators
|
||||||
|
|
||||||
|
private static var savingIndicatorID: String {
|
||||||
|
"\(Self.self)-Saving"
|
||||||
|
}
|
||||||
|
|
||||||
|
private static var failureIndicatorID: String {
|
||||||
|
"\(Self.self)-Failure"
|
||||||
|
}
|
||||||
|
|
||||||
|
private func showSavingIndicator() {
|
||||||
|
userIndicatorController.submitIndicator(UserIndicator(id: Self.savingIndicatorID,
|
||||||
|
type: .toast(progress: .indeterminate),
|
||||||
|
title: L10n.commonSaving,
|
||||||
|
persistent: true))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func hideSavingIndicator() {
|
||||||
|
userIndicatorController.retractIndicatorWithId(Self.savingIndicatorID)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func showFailureIndicator() {
|
||||||
|
userIndicatorController.submitIndicator(UserIndicator(id: Self.failureIndicatorID,
|
||||||
|
type: .toast,
|
||||||
|
title: L10n.commonFailed,
|
||||||
|
icon: \.close))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user