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
1 changed files with 2 additions and 2 deletions

View File

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