From 4ae712be4c45bf4c2887f750bed11796ae74f741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Fri, 29 Dec 2023 13:40:43 +0300 Subject: [PATCH] d --- Modules/MeetupIdX/MeetupId.yml | 2 ++ ...pId.Formatter.swift => MeetupId.Debounce.swift} | 14 ++++++++------ Modules/MeetupIdX/src/MeetupId.K.swift | 1 + Modules/MeetupIdX/src/MeetupId.Shoulds.swift | 9 +++++++++ Modules/MeetupIdX/src/MeetupId.V.swift | 14 ++++++++++---- app/Podfile.lock | 4 ++-- 6 files changed, 32 insertions(+), 12 deletions(-) rename Modules/MeetupIdX/src/{MeetupId.Formatter.swift => MeetupId.Debounce.swift} (51%) diff --git a/Modules/MeetupIdX/MeetupId.yml b/Modules/MeetupIdX/MeetupId.yml index e2bd0d3..eb91127 100644 --- a/Modules/MeetupIdX/MeetupId.yml +++ b/Modules/MeetupIdX/MeetupId.yml @@ -1,6 +1,7 @@ version: 2 model: + finishLoading: [Bool, false] isLoading: [Bool, false] join: [Bool, false] textUI: [String, ""] @@ -10,6 +11,7 @@ service: busModel 🚀shouldResetLoading: Bus.send(K.isLoading, v) pipes: + finishLoading: [toggle, K.finishLoading] isLoading: [recent, K.isLoading] join: [toggle, K.join] textUI: [recent, K.textUI] diff --git a/Modules/MeetupIdX/src/MeetupId.Formatter.swift b/Modules/MeetupIdX/src/MeetupId.Debounce.swift similarity index 51% rename from Modules/MeetupIdX/src/MeetupId.Formatter.swift rename to Modules/MeetupIdX/src/MeetupId.Debounce.swift index 481fb66..33de3c7 100644 --- a/Modules/MeetupIdX/src/MeetupId.Formatter.swift +++ b/Modules/MeetupIdX/src/MeetupId.Debounce.swift @@ -2,25 +2,27 @@ import BusX import Combine extension MeetupId { - final class Formatter: ObservableObject { - let text = PassthroughSubject() + final class Debounce { + let v = PassthroughSubject() var subscriptions = [AnyCancellable]() init( + _ sec: Double, + _ handler: @escaping ((Src) -> Dst?), _ src: String, _ dst: String ) { Bus.receive( [src], - { [weak self] _, v in self?.text.send(v) }, + { [weak self] _, v in self?.v.send(v) }, sub: &subscriptions ) Bus.send( dst, - text - .debounce(for: .seconds(0.2), scheduler: DispatchQueue.main) - .compactMap(formatId) + v + .debounce(for: .seconds(sec), scheduler: DispatchQueue.main) + .compactMap { (v: Src) in handler(v) } .eraseToAnyPublisher(), sub: &subscriptions ) diff --git a/Modules/MeetupIdX/src/MeetupId.K.swift b/Modules/MeetupIdX/src/MeetupId.K.swift index 9c30417..fa4f223 100644 --- a/Modules/MeetupIdX/src/MeetupId.K.swift +++ b/Modules/MeetupIdX/src/MeetupId.K.swift @@ -1,5 +1,6 @@ public extension MeetupId { enum K { + static let finishLoading = "MeetupId.finishLoading" static let isJoinAvailable = "MeetupId.isJoinAvailable" static let isLoading = "MeetupId.isLoading" static let join = "MeetupId.join" diff --git a/Modules/MeetupIdX/src/MeetupId.Shoulds.swift b/Modules/MeetupIdX/src/MeetupId.Shoulds.swift index 361652b..13fbb4d 100644 --- a/Modules/MeetupIdX/src/MeetupId.Shoulds.swift +++ b/Modules/MeetupIdX/src/MeetupId.Shoulds.swift @@ -2,6 +2,8 @@ import Foundation public extension MeetupId { static func shouldEnableJoin(_ c: MeetupIdContext) -> Bool? { + guard !c.isLoading.value else { return nil } + if c.textUI.isRecent, let sid = formatId(c.textUI.value) @@ -12,6 +14,13 @@ public extension MeetupId { if c.join { return false } + + if + c.isLoading.isRecent, + !c.isLoading.value + { + return true + } return nil } diff --git a/Modules/MeetupIdX/src/MeetupId.V.swift b/Modules/MeetupIdX/src/MeetupId.V.swift index 3ba44c0..a68e81b 100644 --- a/Modules/MeetupIdX/src/MeetupId.V.swift +++ b/Modules/MeetupIdX/src/MeetupId.V.swift @@ -4,12 +4,14 @@ import SwiftUI extension MeetupId { public struct V: View { - @StateObject var fmt = MeetupId.Formatter(K.textUI, K.textApp) + let fmt = MeetupId.Debounce(5, formatId, K.textUI, K.textApp) @StateObject var isJoinAvailable = Cord.Receive(K.isJoinAvailable, false) @StateObject var isLoading = Cord.Receive(K.isLoading, false) @StateObject var join = Cord.Button(K.join) @StateObject var textField = Cord.TextField(K.textApp, K.textUI) - let pSEJ = Bus.Processor(shouldEnableJoin, K.M, K.isJoinAvailable) + let procs: [Any] = [ + Bus.Processor(shouldEnableJoin, K.M, K.isJoinAvailable), + ] public init() { } @@ -17,8 +19,12 @@ extension MeetupId { VStack(spacing: 8) { HStack { TextField("Binding-3", value: $textField.v, formatter: Cord.TextFieldValueOwner()) + .disabled(isLoading.v) .padding(8) - .border(Color.blue, width: 2) + .border( + !isLoading.v ? Color.black : Color.gray, + width: !isLoading.v ? 2 : 1 + ) if isLoading.v { ProgressView() .padding(8) @@ -30,7 +36,7 @@ extension MeetupId { .padding(8) .border( isJoinAvailable.v ? Color.green : Color.gray, - width: isJoinAvailable.v ? 4 : 1 + width: isJoinAvailable.v ? 2 : 1 ) } .disabled(!isJoinAvailable.v) diff --git a/app/Podfile.lock b/app/Podfile.lock index e87631d..5ba5278 100644 --- a/app/Podfile.lock +++ b/app/Podfile.lock @@ -1,7 +1,7 @@ PODS: - AELog (0.6.3) - BusX (2023.12.28) - - CordX (2023.12.28): + - CordX (2023.12.29): - BusX - MeetupIdX (2023.12.28): - AELog @@ -34,7 +34,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: AELog: f732b70f7a9d1b4c6a3676304192b3908f362133 BusX: fd22c04ad544d131e66315c1a33d87d85b19712e - CordX: 63515d366b217366b9562edcfef34630a7be1171 + CordX: f8ba6a8db42f9f27142948b536b9b8272f9b977c MeetupIdX: b214163e32acffd0a5283062e9d69aaf5a5b66e6 MPAKX: dc592434f55edf34709f6e4f37c9ec90dcd95185