From 1a731e2fada19dcbba2b46501ce9b529ee9fa03c 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: Wed, 17 Jan 2024 18:12:00 +0300 Subject: [PATCH] d --- Modules/MicX/MicItem/src/MicItem.Shoulds.swift | 13 +++++++++++++ Modules/MicX/MicItem/src/MicItem.V.swift | 4 ++-- Modules/MicX/MicItem/src/MicItem.WillBe.swift | 13 +++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 Modules/MicX/MicItem/src/MicItem.Shoulds.swift diff --git a/Modules/MicX/MicItem/src/MicItem.Shoulds.swift b/Modules/MicX/MicItem/src/MicItem.Shoulds.swift new file mode 100644 index 0000000..cb92034 --- /dev/null +++ b/Modules/MicX/MicItem/src/MicItem.Shoulds.swift @@ -0,0 +1,13 @@ +public extension MicItem { + static func shouldResetActivity(_ c: MicItemContext) -> Bool? { + if + c.activityDate.isRecent, + let end = c.activityDate.value, + let now = Date() + { + return now < end + } + + return nil + } +} diff --git a/Modules/MicX/MicItem/src/MicItem.V.swift b/Modules/MicX/MicItem/src/MicItem.V.swift index 42c7d77..780eda9 100644 --- a/Modules/MicX/MicItem/src/MicItem.V.swift +++ b/Modules/MicX/MicItem/src/MicItem.V.swift @@ -5,13 +5,13 @@ extension MicItem { public struct V: View { var id: String? @StateObject var isActive = BusUI.Value(K.isActive, false) - let ctrl = MicItem.Controller() let processors: [Any] public init(_ id: String? = nil) { self.id = id self.processors = [ - //Bus.Sync(shouldResetActivity, K.MI, K.isActive), + Bus.Sync(shouldResetActivity, K.MI, K.isActive), + MicItem.Controller() ] } diff --git a/Modules/MicX/MicItem/src/MicItem.WillBe.swift b/Modules/MicX/MicItem/src/MicItem.WillBe.swift index 285288f..3594b08 100644 --- a/Modules/MicX/MicItem/src/MicItem.WillBe.swift +++ b/Modules/MicX/MicItem/src/MicItem.WillBe.swift @@ -9,7 +9,9 @@ extension MicItem { public struct Model: MicItemContext { public var activityDate: MPAK.Recent = .init(nil) } +} +extension MicItem { final class Controller: MPAK.Controller { init() { /**/print("MicIC.init") @@ -24,6 +26,17 @@ extension MicItem { m .sink { v in Bus.send(K.MI, v) } .store(in: &subscriptions) + + pipeValue( + dbg: "activityD", + sub: nil, + Bus.events.compactMap { Bus.convertKeyValue(K.activityDate, $0) }.map { (k: String, v: Date?) in v }.eraseToAnyPublisher(), + { + $0.activityDate.value = $1 + $0.activityDate.isRecent = true + }, + { m, _ in m.activityDate.isRecent = false } + ) } } }