From 860ac001068fc527102d7293c80e0b92a7c291d3 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:04:56 +0300 Subject: [PATCH] d --- Modules/MeetupIdX/MeetupId.yml | 3 +++ .../MeetupIdX/src/MeetupId.Generated.swift | 19 +++++++++++++++++++ Modules/MeetupIdX/src/MeetupId.K.swift | 1 + Modules/MeetupIdX/src/MeetupId.Shoulds.swift | 12 ++++++++++++ Modules/MeetupIdX/src/MeetupId.V.swift | 17 +++++++++-------- 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/Modules/MeetupIdX/MeetupId.yml b/Modules/MeetupIdX/MeetupId.yml index d2f6d5f..e2bd0d3 100644 --- a/Modules/MeetupIdX/MeetupId.yml +++ b/Modules/MeetupIdX/MeetupId.yml @@ -1,13 +1,16 @@ version: 2 model: + isLoading: [Bool, false] join: [Bool, false] textUI: [String, ""] service: actions: busModel + 🚀shouldResetLoading: Bus.send(K.isLoading, v) pipes: + isLoading: [recent, K.isLoading] join: [toggle, K.join] textUI: [recent, K.textUI] diff --git a/Modules/MeetupIdX/src/MeetupId.Generated.swift b/Modules/MeetupIdX/src/MeetupId.Generated.swift index d6d27a4..c82a89b 100644 --- a/Modules/MeetupIdX/src/MeetupId.Generated.swift +++ b/Modules/MeetupIdX/src/MeetupId.Generated.swift @@ -12,6 +12,7 @@ import UIKit // MARK: - Context public protocol MeetupIdContext { + var isLoading: MPAK.Recent { get } var join: Bool { get } var textUI: MPAK.Recent { get } } @@ -34,6 +35,7 @@ extension MeetupId { // MARK: - Model public struct Model: MeetupIdContext { + public var isLoading: MPAK.Recent = .init(false) public var join: Bool = false public var textUI: MPAK.Recent = .init("") } @@ -83,10 +85,27 @@ extension MeetupId { ctrl.m .sink { v in Bus.send("MeetupId", v) } .store(in: &service.subscriptions) + ctrl.m + .compactMap { shouldResetLoading($0) } + .sink { v in Bus.send(K.isLoading, v) } + .store(in: &service.subscriptions) // MARK: - SectionGenerated Service Pipes + ctrl.pipeValue( + dbg: "isL", + sub: nil, + Bus.events.compactMap { Bus.convertKeyValue(K.isLoading, $0) }.map { (k: String, v: Bool) in v }.eraseToAnyPublisher(), + { + $0.isLoading.value = $1 + $0.isLoading.isRecent = true + }, + { m, _ in m.isLoading.isRecent = false } + ) + + + ctrl.pipe( dbg: "join", sub: nil, diff --git a/Modules/MeetupIdX/src/MeetupId.K.swift b/Modules/MeetupIdX/src/MeetupId.K.swift index 80e54fa..9c30417 100644 --- a/Modules/MeetupIdX/src/MeetupId.K.swift +++ b/Modules/MeetupIdX/src/MeetupId.K.swift @@ -1,6 +1,7 @@ public extension MeetupId { enum K { static let isJoinAvailable = "MeetupId.isJoinAvailable" + static let isLoading = "MeetupId.isLoading" static let join = "MeetupId.join" static let M = "MeetupId" static let textApp = "MeetupId.textApp" diff --git a/Modules/MeetupIdX/src/MeetupId.Shoulds.swift b/Modules/MeetupIdX/src/MeetupId.Shoulds.swift index 90afc03..361652b 100644 --- a/Modules/MeetupIdX/src/MeetupId.Shoulds.swift +++ b/Modules/MeetupIdX/src/MeetupId.Shoulds.swift @@ -15,4 +15,16 @@ public extension MeetupId { return nil } + + static func shouldResetLoading(_ c: MeetupIdContext) -> Bool? { + if + c.join, + !c.isLoading.value + { + return true + } + + return nil + } + } diff --git a/Modules/MeetupIdX/src/MeetupId.V.swift b/Modules/MeetupIdX/src/MeetupId.V.swift index 66ec048..36bedab 100644 --- a/Modules/MeetupIdX/src/MeetupId.V.swift +++ b/Modules/MeetupIdX/src/MeetupId.V.swift @@ -6,24 +6,25 @@ extension MeetupId { public struct V: View { @StateObject var fmt = MeetupId.Formatter(K.textUI, K.textApp) @StateObject var isJA = Cord.Receive(K.isJoinAvailable, false) + @StateObject var isL = Cord.Receive(K.isLoading, false) @StateObject var join = Cord.Button(K.join) @StateObject var txtF = Cord.TextField(K.textApp, K.textUI) - let joinA = Bus.Processor(shouldEnableJoin, K.M, K.isJoinAvailable) + let pSEJ = Bus.Processor(shouldEnableJoin, K.M, K.isJoinAvailable) + let pSRL = Bus.Processor(shouldResetLoading, K.M, K.isLoading) public init() { } public var body: some View { VStack { HStack { - Text("Check text field:") - Text("'\(txtF.value)'") - .fontWeight(.bold) + TextField("Binding-3", value: $txtF.value, formatter: Cord.TextFieldValueOwner()) + .padding(8) + .border(Color.blue, width: 2) + if isL.value { + ProgressView() + } } - TextField("Binding-3", value: $txtF.value, formatter: Cord.TextFieldValueOwner()) - .padding(8) - .border(Color.blue, width: 2) - Button(action: join.press.send) { Text("Join") .padding(8)