1
0
mirror of git://jb55.com/damus synced 2024-09-16 02:03:45 +00:00

Add feedback message when user adds a relay already in the list

Changelog-Added: Added feedback when user adds a relay that is already on the list
Closes: https://github.com/damus-io/damus/issues/1053
Signed-off-by: Daniel D'Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
Daniel D'Aquino' via patches 2023-07-15 04:17:03 +00:00 committed by William Casarin
parent 7ae7584135
commit 29140d956b

View File

@ -12,6 +12,7 @@ struct RelayConfigView: View {
@State var new_relay: String = ""
@State var relays: [RelayDescriptor]
@State private var showActionButtons = false
@State var relayAddErrorMessage: String? = nil
@Environment(\.dismiss) var dismiss
@ -89,7 +90,14 @@ struct RelayConfigView: View {
let info = RelayInfo.rw
let descriptor = RelayDescriptor(url: url, info: info)
guard (try? state.pool.add_relay(descriptor)) != nil else {
do {
try state.pool.add_relay(descriptor)
relayAddErrorMessage = nil // Clear error message
} catch RelayError.RelayAlreadyExists {
relayAddErrorMessage = NSLocalizedString("This relay is already in your list", comment: "An error message that appears when the user attempts to add a relay that has already been added.")
return
} catch {
return
}
@ -115,6 +123,13 @@ struct RelayConfigView: View {
.padding(EdgeInsets(top: 15, leading: 0, bottom: 0, trailing: 0))
}
}
if let errorMessage = relayAddErrorMessage {
HStack {
Spacer()
Text(errorMessage)
.foregroundColor(Color.red)
}
}
}
}