Since I included comment in my code I will send few post with all relevant detail here are my question for this SWfit file
- you place the
projects = Modeldata().projects
while I was trying to do it under modelData.swift file because when I add it into Project.swift file it's not Parse since not in my JSON. should I also add into the JSON ? - to make the code cleaner I use a SetTimeKeyInView that I will share in next post
- creation of date and date range for my new datepickrange buttons
@State var isSet: [Bool] = [false, false, false, false, false,false,false,false]
is not needed@State private var hideTeco = false
is not needed I have also remove it isTECO means Technically close project meaning I don't need to work on it but keep them as reference if one day I want to go and see location, customer and other info- remove and change name for more clarity on code and like to point 2 I don't use it in here anymore
- Datepicker I will dedicate another threat POST as manyquestion I'm facing
- as you can see I don;t use the code
.onAppear() {
// <<-- Added
for (row, project) in filteredNonTECOProjects.enumerated() {
isSet[row] = !project.isTeco
}
}
so I'm not sure what is the code doing and I don't see the link with isTeco
import SwiftUI
struct TimeKeyinList: View, Observable {
@Environment(ModelData.self) var modelData
@Environment(TimesheetCalculation.self) var timesheetCalculation
//MARK: - Variable & Constants
// let projects = ModelData().projects // Now need a State var to be able to modify later I did not do that need to check with Claude
var listofpossibleHourstext = TimesheetCalculation().listOfPossibleHoursText
@State var isSet = ModelData().isSet // I think the code from claude is what I'm trying to do here
// @State var projects = [Project] () //CLAUDEADD Now need a State var to be able to modify
@State var date = TimesheetCalculation().date
@State var dateRange = TimesheetCalculation().dateRange
// @State var isSet: [Bool] = [false, false, false, false, false,false,false,false] // explain to claude that I I ahve more proejct in future and I don't increare this list then the app crash ... not very sure why but i believe it's due to the number of row link with the number of project dispaly
//CLAUDE SAY Not the correct var to keep hours for each project. @State var isSet: [Bool] = [true, false, false, true]
//Alreadydeleted @State private var hideTeco = false // What's the purpose of this ? Not used in code
// I remove the on appear as the code don't need it
//@State var filteredProjects: [Project] = []
/* { Init will be done in onAppear
// removeTECO project
projects.filter { project in
!project.isTeco
}
}*/
//MARK: - Body
var body: some View {
@Bindable var timesheetCalculation = timesheetCalculation
VStack {
HStack {
Text("TIME KEY_IN")
.font(.title)
.multilineTextAlignment(.leading)
.bold()
Spacer()
Button {
print(TimesheetCalculation().date)
} label: {
Label("SAVE", systemImage: "square.and.arrow.down")
.foregroundStyle(.blue )
.scaleEffect(1.2)
}
Spacer()
//findtheocde to remove intRemaining hours keep the full string into a flooting point and tronacte teh string to only 3character
let IntremainingHour = Int(timesheetCalculation.remainingHour)
Text("\(IntremainingHour)h")
.font(.title)
.multilineTextAlignment(.leading)
.bold()
}.padding()
Spacer()
VStack(spacing: 5){
HStack(alignment: .top) {
Text(" Project Name")
.multilineTextAlignment(.center)
.lineLimit(2)
.frame(width: 120.0) // <<-- To get proper alignment
//use the TimekeyinRow listofPossibleHour
ForEach((listofpossibleHourstext),id: \.self) { hour in
Text("\(hour)h")
}
Text("Time Left")
.multilineTextAlignment(.trailing)
.lineLimit(2)
.frame(width: 50)
}.environment(\.sizeCategory, .extraExtraExtraLarge)
SetTimeKeyInView()
}
HStack {
DatePickerStyle().environment(\.sizeCategory, .extraExtraExtraLarge)
Button {
//I need to clean the cache for
//clean all button
// remove all of date cvs
//remaining hour = 8
$timesheetCalculation.remainingHour
} label: {
Label("CLEAN", systemImage: "arrow.up.trash")
.labelStyle(.iconOnly)
.foregroundStyle(.blue )
.scaleEffect(1.2)
}
}
Spacer()
// .onAppear() {
// // <<-- Added
// for (row, project) in filteredNonTECOProjects.enumerated() {
// isSet[row] = !project.isTeco
// }
// }
let _ = print(modelData.isSet)
Spacer()
}
}
}
struct TimeKeyinList_Previews2: PreviewProvider {
static var previews: some View {
//#Preview
TimeKeyinList()
.environment(ModelData())
.environment(TimesheetCalculation())
}
}