Strip whitespace from URL input

This commit is contained in:
Justin Mazzocchi 2021-03-18 17:51:19 -07:00
parent 9ff60f65ad
commit 13a732b5e3
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C

View file

@ -30,7 +30,7 @@ public final class AddIdentityViewModel: ObservableObject {
.throttle(for: .seconds(Self.textFieldThrottleInterval), scheduler: DispatchQueue.global(), latest: true)
.removeDuplicates()
.flatMap {
instanceURLService.url(text: $0).publisher
instanceURLService.url(text: $0.trimmingCharacters(in: .whitespacesAndNewlines)).publisher
.map { $0 as URL? }
.replaceError(with: nil)
}
@ -82,7 +82,7 @@ public extension AddIdentityViewModel {
private extension AddIdentityViewModel {
private static let textFieldThrottleInterval: TimeInterval = 0.5
func addIdentity(kind: AllIdentitiesService.IdentityCreation) {
instanceURLService.url(text: urlFieldText).publisher
instanceURLService.url(text: urlFieldText.trimmingCharacters(in: .whitespacesAndNewlines)).publisher
.map { ($0, kind) }
.flatMap(allIdentitiesService.createIdentity(url:kind:))
.receive(on: DispatchQueue.main)