Change toast messages.
This commit is contained in:
parent
f277162831
commit
7a19585308
|
@ -135,11 +135,11 @@ public class AuthorizationService {
|
|||
try await self.refreshAccessToken(accountData: account)
|
||||
|
||||
#if DEBUG
|
||||
ToastrService.shared.showSuccess("New access tokens has been retrieved", imageSystemName: "key.fill")
|
||||
ToastrService.shared.showSuccess("New access tokens has been retrieved.", imageSystemName: "key.fill")
|
||||
#endif
|
||||
} catch {
|
||||
#if DEBUG
|
||||
ErrorService.shared.handle(error, message: "Error during refreshing access token for account '\(account.acct)'.", showToastr: true)
|
||||
ErrorService.shared.handle(error, message: "Refresh token failed: '\(account.acct)'.", showToastr: true)
|
||||
#else
|
||||
ErrorService.shared.handle(error, message: "Error during refreshing access token for account '\(account.acct)'.")
|
||||
#endif
|
||||
|
@ -232,10 +232,6 @@ public class AuthorizationService {
|
|||
}
|
||||
}
|
||||
|
||||
// We have to be sure that account id is saved as default account.
|
||||
let defaultSettings = ApplicationSettingsHandler.shared.getDefaultSettings()
|
||||
defaultSettings.currentAccount = dbAccount.id
|
||||
|
||||
// Save account data in database and in application state.
|
||||
CoreDataHandler.shared.save()
|
||||
}
|
||||
|
|
|
@ -13,9 +13,10 @@ public class ErrorService {
|
|||
|
||||
public func handle(_ error: Error, message: String, showToastr: Bool = false) {
|
||||
if showToastr {
|
||||
if error is NetworkError {
|
||||
ToastrService.shared.showError(subtitle: "\(message) \(error.localizedDescription)")
|
||||
} else {
|
||||
switch error {
|
||||
case is NetworkError, is URLError:
|
||||
ToastrService.shared.showError(title: message, subtitle: error.localizedDescription)
|
||||
default:
|
||||
ToastrService.shared.showError(subtitle: message)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,12 +16,13 @@ public class ToastrService {
|
|||
let drop = Drop(
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
subtitleNumberOfLines: 2,
|
||||
icon: self.createImage(systemName: imageSystemName, color: ApplicationState.shared.tintColor.uiColor()),
|
||||
action: .init {
|
||||
Drops.hideCurrent()
|
||||
},
|
||||
position: .top,
|
||||
duration: 2.0,
|
||||
duration: 3.0,
|
||||
accessibility: ""
|
||||
)
|
||||
|
||||
|
@ -30,14 +31,15 @@ public class ToastrService {
|
|||
|
||||
public func showError(title: String = "Unexpected error", imageSystemName: String = "ant.circle.fill", subtitle: String? = nil) {
|
||||
let drop = Drop(
|
||||
title: "Unexpected error",
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
subtitleNumberOfLines: 2,
|
||||
icon: self.createImage(systemName: imageSystemName, color: Color.red.toUIColor()),
|
||||
action: .init {
|
||||
Drops.hideCurrent()
|
||||
},
|
||||
position: .top,
|
||||
duration: 2.0,
|
||||
duration: 3.0,
|
||||
accessibility: ""
|
||||
)
|
||||
|
||||
|
|
|
@ -101,10 +101,10 @@ struct AccountsView: View {
|
|||
self.state = .loaded
|
||||
} catch {
|
||||
if !Task.isCancelled {
|
||||
ErrorService.shared.handle(error, message: "Error during download followers from server.", showToastr: true)
|
||||
ErrorService.shared.handle(error, message: "Followers not retrieved.", showToastr: true)
|
||||
self.state = .error(error)
|
||||
} else {
|
||||
ErrorService.shared.handle(error, message: "Error during download followers from server.", showToastr: false)
|
||||
ErrorService.shared.handle(error, message: "Followers not retrieved.", showToastr: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,10 +134,10 @@ struct HomeFeedView: View {
|
|||
self.state = .loaded
|
||||
} catch {
|
||||
if !Task.isCancelled {
|
||||
ErrorService.shared.handle(error, message: "Error during download statuses from server.", showToastr: true)
|
||||
ErrorService.shared.handle(error, message: "Statuses not retrieved.", showToastr: true)
|
||||
self.state = .error(error)
|
||||
} else {
|
||||
ErrorService.shared.handle(error, message: "Error during download statuses from server.", showToastr: false)
|
||||
ErrorService.shared.handle(error, message: "Statuses not retrieved.", showToastr: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,10 +86,10 @@ struct NotificationsView: View {
|
|||
}
|
||||
} catch {
|
||||
if !Task.isCancelled {
|
||||
ErrorService.shared.handle(error, message: "Error during download notifications from server.", showToastr: true)
|
||||
ErrorService.shared.handle(error, message: "Notifications not retrieved.", showToastr: true)
|
||||
self.state = .error(error)
|
||||
} else {
|
||||
ErrorService.shared.handle(error, message: "Error during download notifications from server.", showToastr: false)
|
||||
ErrorService.shared.handle(error, message: "Notifications not retrieved.", showToastr: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,16 +99,19 @@ struct SignInView: View {
|
|||
ErrorService.shared.handle(error, message: error.localizedDescription, showToastr: true)
|
||||
}
|
||||
catch {
|
||||
ErrorService.shared.handle(error, message: "Error during communication with server.", showToastr: true)
|
||||
ErrorService.shared.handle(error, message: "Communication with server failed.", showToastr: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func getServerAddress(uri: String) -> String {
|
||||
if !uri.starts(with: "https://") {
|
||||
return "https://\(uri)"
|
||||
var address = uri.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
address = address.trimmingCharacters(in: CharacterSet.init(charactersIn: "/\\"))
|
||||
|
||||
if !address.starts(with: "https://") {
|
||||
return "https://\(address)"
|
||||
}
|
||||
|
||||
return uri
|
||||
return address
|
||||
}
|
||||
}
|
||||
|
|
|
@ -186,10 +186,10 @@ struct StatusView: View {
|
|||
}
|
||||
catch {
|
||||
if !Task.isCancelled {
|
||||
ErrorService.shared.handle(error, message: "Error during download status from server.", showToastr: true)
|
||||
ErrorService.shared.handle(error, message: "Status not retreived.", showToastr: true)
|
||||
self.state = .loaded
|
||||
} else {
|
||||
ErrorService.shared.handle(error, message: "Error during download status from server.", showToastr: false)
|
||||
ErrorService.shared.handle(error, message: "Status not retreived.", showToastr: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -252,7 +252,7 @@ struct StatusesView: View {
|
|||
self.tag = try await self.client.tags?.follow(tag: hashtag)
|
||||
ToastrService.shared.showSuccess("You are following the tag.", imageSystemName: "number.square.fill")
|
||||
} catch {
|
||||
ErrorService.shared.handle(error, message: "Error during following tag.", showToastr: true)
|
||||
ErrorService.shared.handle(error, message: "Follow tag failed.", showToastr: true)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -261,7 +261,7 @@ struct StatusesView: View {
|
|||
self.tag = try await self.client.tags?.unfollow(tag: hashtag)
|
||||
ToastrService.shared.showSuccess("Tag has been unfollowed.", imageSystemName: "number.square")
|
||||
} catch {
|
||||
ErrorService.shared.handle(error, message: "Error during unfollowing tag.", showToastr: true)
|
||||
ErrorService.shared.handle(error, message: "Unfollow tag failed.", showToastr: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue