Backport: Update alert

The alert backport was updated for simplicity. Reflect this inside
Ferrite's source code.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri 2023-01-11 12:23:19 -05:00
parent e31f9a07fe
commit 6b0f90178b
4 changed files with 8 additions and 12 deletions

View file

@ -29,9 +29,9 @@ struct AlertButton: Identifiable {
}
// Used for buttons with no action
init(_ label: String = "Cancel", role: Role? = nil) {
init(_ label: String? = nil, role: Role? = nil) {
id = UUID()
self.label = label
self.label = label ?? (role == .cancel ? "Cancel" : "OK")
action = {}
self.role = role
}

View file

@ -20,7 +20,7 @@ extension View {
}
extension Backport where Content: View {
@ViewBuilder func alert(isPresented: Binding<Bool>, title: String, message: String?, buttons: [AlertButton]) -> some View {
@ViewBuilder func alert(isPresented: Binding<Bool>, title: String, message: String?, buttons: [AlertButton] = []) -> some View {
if #available(iOS 15, *) {
content
.alert(
@ -55,7 +55,7 @@ extension Backport where Content: View {
return Alert(
title: Text(title),
message: message.map { Text($0) } ?? nil,
dismissButton: buttons[0].toActionButton()
dismissButton: buttons[safe: 0].map { $0.toActionButton() } ?? .cancel()
)
}
}

View file

@ -35,8 +35,7 @@ struct SourceListEditorView: View {
.backport.alert(
isPresented: $sourceManager.showUrlErrorAlert,
title: "Error",
message: sourceManager.urlErrorAlertText,
buttons: [AlertButton("OK")]
message: sourceManager.urlErrorAlertText
)
.navigationTitle("Editing source list")
.navigationBarTitleDisplayMode(.inline)

View file

@ -118,10 +118,7 @@ struct MainView: View {
title: "Backup restored",
message: backupManager.backupSourceNames.isEmpty ?
"No sources need to be reinstalled" :
"Reinstall sources: \(backupManager.backupSourceNames.joined(separator: ", "))",
buttons: [
.init("OK") {}
]
"Reinstall sources: \(backupManager.backupSourceNames.joined(separator: ", "))"
)
// Updater alert
.backport.alert(
@ -129,14 +126,14 @@ struct MainView: View {
title: "Update available",
message: "Ferrite \(releaseVersionString) can be downloaded. \n\n This alert can be disabled in Settings.",
buttons: [
AlertButton("Download") {
.init("Download") {
guard let releaseUrl = URL(string: releaseUrlString) else {
return
}
UIApplication.shared.open(releaseUrl)
},
AlertButton(role: .cancel)
.init(role: .cancel)
]
)
.overlay {