You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LeCountdown/LeCountdown/Views/LiveTimerView.swift

70 lines
1.9 KiB

//
// LiveTimerView.swift
// LeCountdown
//
// Created by Laurent Morvillier on 03/02/2023.
//
import SwiftUI
struct LiveTimerView: View {
@Environment(\.managedObjectContext) private var viewContext
@EnvironmentObject var conductor: Conductor
var body: some View {
LazyVStack {
ForEach(conductor.liveTimers) { liveTimer in
let timer = liveTimer.timer(context: self.viewContext)
HStack {
Text(timer?.displayName.uppercased() ?? "missing")
Spacer()
Text(liveTimer.date, style: .timer)
Spacer()
Button {
self._stopTimer(timer)
} label: {
Text("STOP")
.padding(8.0)
.foregroundColor(.red)
.background(.white)
.fontWeight(.semibold)
.cornerRadius(8.0)
}//.buttonStyle(.bordered).tint(.red)
}
.padding()
.frame(height: 55.0)
.foregroundColor(.white)
.monospaced()
.background(.cyan)
.cornerRadius(16.0)
}
}.padding(8.0)
}
fileprivate func _stopTimer(_ timer: AbstractTimer?) {
guard let timer else {
return
}
TimerRouter.stopTimer(timer: timer)
}
}
struct LiveTimerView_Previews: PreviewProvider {
init() {
Conductor.maestro.currentCountdowns["fef"] = DateInterval(start: Date(), end: Date())
}
static var previews: some View {
LiveTimerView().environmentObject(Conductor.maestro)
}
}