Made Message more generic

This commit is contained in:
dankito 2020-07-17 19:57:38 +02:00
parent 2c0e7bfc08
commit af1e155106
2 changed files with 24 additions and 3 deletions

View File

@ -1,8 +1,29 @@
import Foundation
import SwiftUI
struct Message: Identifiable {
let id = UUID()
let text: String
let title: Text
let message: Text?
init(title: Text = Text(""), message: Text? = nil) {
self.title = title
self.message = message
}
init(title: String = "", message: String? = nil) {
self.title = Text(title)
if let text = message {
self.message = Text(text)
}
else {
self.message = nil
}
}
}

View File

@ -48,7 +48,7 @@ struct AddAccountDialog: View {
}
}
.alert(item: $errorMessage) { message in
Alert(title: Text("Could not add account"), message: Text("Error message from your bank \(message.text)"), dismissButton: Alert.Button.cancel())
Alert(title: message.title, message: message.message, dismissButton: Alert.Button.cancel()))
}
.navigationBarTitle(Text("Add account"), displayMode: NavigationBarItem.TitleDisplayMode.inline)
}
@ -77,7 +77,7 @@ struct AddAccountDialog: View {
presentation.wrappedValue.dismiss()
}
else {
self.errorMessage = Message(text: (response.errorToShowToUser ?? ""))
self.errorMessage = Message(title: Text("Could not add account"), message: Text("Error message from your bank \(response.errorToShowToUser ?? "")"))
}
}
}