hi @Claude31 , I have created the following 3 files :```
//
// HourButton.swift
// MyPmV1
//
// Created by Sebastien BENAVIDES on 9/2/24.
//
import SwiftUI
struct HourButton: View {
var isSet: Bool
var taghour: String
var body: some View {
Button {
print(taghour)
} label: {
Label("Toggle \(taghour)", systemImage: isSet ? "circle.fill" : "circle")
.labelStyle(.iconOnly)
.foregroundStyle(isSet ? .blue : .gray)
}
}
}
#Preview {
HourButton(isSet: false, taghour: "1h")
}
this is my second file
//
// TimeKeyInRow.swift
// MyPmV1
//
// Created by Sebastien BENAVIDES on 9/2/24.
//
import SwiftUI
struct TimeKeyInRow: View {
@Binding var isSet: Bool
var projectshortname: String
var timeleft: Int
var body: some View {
HStack {
Text(projectshortname)
Spacer(minLength:30)
HourButton(isSet: isSet, taghour: "0.5h").tag("0.5h")
HourButton(isSet: isSet, taghour: "1h").tag("1h")
HourButton(isSet: isSet, taghour: "2h").tag("2h")
HourButton(isSet: isSet, taghour: "3h").tag("3h")
HourButton(isSet: isSet, taghour: "4h").tag("4h")
Text("\(timeleft)").padding()
}
}
}
#Preview {
let projects = ModelData().projects
return
TimeKeyInRow(isSet: .constant(true),projectshortname: projects[2].shortname, timeleft: projects[2].leftPMtime)
}
this is my 3rd file which is crashing
//
// TimeKeyinList.swift
// MyPmV1
//
// Created by Sebastien BENAVIDES on 9/2/24.
//
import SwiftUI
struct TimeKeyinList: View {
@Environment(ModelData.self) var modelData
let projects = ModelData().projects
@Binding var isSet: Bool
@State private var hideTeco = false
var filteredProjects: [Project] {
// If TECO and favorite are active then I would only see favourite and not TECO projects
modelData.projects.filter { project in
!project.isTeco
}}
var body: some View {
VStack {
HStack {
Text("TIME KEY_IN")
.font(.title)
.multilineTextAlignment(.leading)
.bold()
Spacer()
Text("8h")
.font(.title)
.multilineTextAlignment(.leading)
.bold()
}.padding()
List {
HStack(alignment: .top) {
Text("Project Name")
.frame(width: 80, height: 25)
.font(.caption)
.multilineTextAlignment(.center)
.lineLimit(8)
.allowsTightening(/*@START_MENU_TOKEN@*/true/*@END_MENU_TOKEN@*/)
.multilineTextAlignment(.center)
.bold()
Spacer(minLength:30)
Text("0.5h")
.font(.footnote)
Text("1h")
.font(.footnote)
.padding(/*@START_MENU_TOKEN@*/EdgeInsets()/*@END_MENU_TOKEN@*/)
Text("2h")
.font(.footnote)
.padding(/*@START_MENU_TOKEN@*/EdgeInsets()/*@END_MENU_TOKEN@*/)
Text("3h")
.font(.footnote)
.padding(/*@START_MENU_TOKEN@*/EdgeInsets()/*@END_MENU_TOKEN@*/)
Text("4h")
.font(.footnote)
.padding(/*@START_MENU_TOKEN@*/EdgeInsets()/*@END_MENU_TOKEN@*/)
Text("Time Left")
.frame(width: 60, height: 25)
.font(.caption)
.multilineTextAlignment(.center)
.lineLimit(8)
.allowsTightening(/*@START_MENU_TOKEN@*/true/*@END_MENU_TOKEN@*/)
.multilineTextAlignment(.center)
.bold()
}
ForEach (filteredProjects) { project in
TimeKeyInRow( isSet: $isSet, projectshortname: project.shortname, timeleft: project.leftPMtime)
}
Divider()
TimeKeyInRow(isSet: $isSet, projectshortname: "TRAINING", timeleft: 0)
TimeKeyInRow(isSet: $isSet, projectshortname: "MEETING", timeleft: 0)
TimeKeyInRow(isSet: $isSet, projectshortname: "NON ALLOCATED", timeleft:0)
TimeKeyInRow(isSet: $isSet, projectshortname: "HOLIDAY", timeleft:0)
}
.listStyle(.inset)
DatePicker(selection: /*@START_MENU_TOKEN@*/.constant(Date())/*@END_MENU_TOKEN@*/, label: { /*@START_MENU_TOKEN@*/Text("Date")/*@END_MENU_TOKEN@*/ })
}
}
}
#Preview {
TimeKeyinList( isSet: .constant(false))
}