Alomost done with CreateClassView
This commit is contained in:
@ -11,19 +11,63 @@ struct CreateEditClassView: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@State private var isShowingDatePickerForDate: Bool = false
|
||||
@ObservedObject var vm: EditClassViewModel
|
||||
var day: Date
|
||||
@State private var isIncorrectDate1: Bool = false
|
||||
@State private var isIncorrectDate2: Bool = false
|
||||
@State private var isShowingSubjectFieldRed: Bool = false
|
||||
@State private var isSelectedTime1 = false
|
||||
@State private var isSelectedTime2 = false
|
||||
@State private var textForLabelInSubjectField: String = "Предмет"
|
||||
@FocusState private var isFocusedSubject: Bool
|
||||
@FocusState private var isFocusedAuditory: Bool
|
||||
@FocusState private var isFocusedProfessor: Bool
|
||||
@FocusState private var isFocusedComment: Bool
|
||||
var provider = ClassProvider.shared
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
VStack {
|
||||
ProfessorAuditoryClassFieldView(text: $vm._class.subject, nameOfImage: "book", labelForField: "Предмет")
|
||||
SubjectFieldView(text: $vm._class.subject, isShowingSubjectFieldRed: $isShowingSubjectFieldRed, nameOfImage: "book", labelForField: $textForLabelInSubjectField, isFocused: _isFocusedSubject)
|
||||
.padding(.bottom, 10)
|
||||
ProfessorAuditoryClassFieldView(text: $vm._class.auditory, nameOfImage: "mappin.and.ellipse", labelForField: "Корпус-аудитория")
|
||||
.padding(.bottom, 10)
|
||||
ProfessorAuditoryClassFieldView(text: $vm._class.professor, nameOfImage: "book", labelForField: "Преподаватель")
|
||||
HStack {
|
||||
Text("Тип")
|
||||
Spacer()
|
||||
Picker("Тип", selection: $vm._class.online, content: {
|
||||
ForEach(MockData.onlineOrOffline, id: \.self) {
|
||||
Text($0)
|
||||
}
|
||||
})
|
||||
.accentColor(Color("grayForFields"))
|
||||
}
|
||||
.frame(height: 40)
|
||||
.padding(.horizontal)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(.white)
|
||||
)
|
||||
.padding(.bottom, 10)
|
||||
|
||||
|
||||
ZStack {
|
||||
if vm._class.online == "Оффлайн" {
|
||||
AuditoryFieldView(text: $vm._class.auditory, nameOfImage: "mappin.and.ellipse", labelForField: "Корпус-аудитория", isFocused: _isFocusedAuditory)
|
||||
.padding(.bottom, 10)
|
||||
.transition(.asymmetric(
|
||||
insertion: .offset(y: -50).combined(with: .identity),
|
||||
removal: .offset(y: -50).combined(with: .opacity)
|
||||
))
|
||||
}
|
||||
}
|
||||
.animation(
|
||||
vm._class.online == "Оффлайн" ?
|
||||
.linear(duration: 0.3) : // Анимация для появления
|
||||
.linear(duration: 0.2), // Анимация для исчезновения
|
||||
value: vm._class.online
|
||||
)
|
||||
|
||||
ProfessorFieldView(text: $vm._class.professor, nameOfImage: "book", labelForField: "Преподаватель", isFocused: _isFocusedProfessor)
|
||||
.padding(.bottom, 10)
|
||||
|
||||
HStack {
|
||||
Image(systemName: "calendar")
|
||||
.foregroundColor(Color.gray)
|
||||
@ -46,46 +90,55 @@ struct CreateEditClassView: View {
|
||||
.overlay {
|
||||
DatePicker("", selection: $vm._class.day, in: Date()..., displayedComponents: .date)
|
||||
.blendMode(.destinationOver)
|
||||
|
||||
}
|
||||
.padding(.bottom, 10)
|
||||
HStack {
|
||||
StartEndTimeFieldView(isIncorrectDate: $isIncorrectDate1, selectedDay: $vm._class.day, selectedTime: $vm._class.starttime, imageName: "clock", text: "Начало")
|
||||
StartEndTimeFieldView(isIncorrectDate: $isIncorrectDate1, selectedDay: $vm._class.day, selectedTime: $vm._class.starttime, imageName: "clock", text: "Начало", isTimeSelected: $isSelectedTime1)
|
||||
.onChange(of: vm._class.starttime) { oldValue, newValue in
|
||||
if !checkStartTimeLessThenEndTime(vm._class.starttime, vm._class.endtime) {
|
||||
self.isIncorrectDate1 = true
|
||||
self.isSelectedTime1 = false
|
||||
print("Первый")
|
||||
print(self.isSelectedTime1)
|
||||
print(self.isSelectedTime2)
|
||||
}
|
||||
else {
|
||||
self.isIncorrectDate1 = false
|
||||
self.isIncorrectDate2 = false
|
||||
}
|
||||
}
|
||||
.overlay {
|
||||
if isIncorrectDate1 {
|
||||
Rectangle()
|
||||
.frame(maxWidth: 300, maxHeight: 1)
|
||||
.foregroundColor(.red)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
}
|
||||
// .overlay {
|
||||
// if isIncorrectDate1 {
|
||||
// Rectangle()
|
||||
// .frame(maxWidth: 300, maxHeight: 1)
|
||||
// .foregroundColor(.red)
|
||||
// .padding(.horizontal)
|
||||
// }
|
||||
// }
|
||||
Spacer()
|
||||
StartEndTimeFieldView(isIncorrectDate: $isIncorrectDate2, selectedDay: $vm._class.day, selectedTime: $vm._class.endtime, imageName: "clock.badge.xmark", text: "Конец")
|
||||
StartEndTimeFieldView(isIncorrectDate: $isIncorrectDate2, selectedDay: $vm._class.day, selectedTime: $vm._class.endtime, imageName: "clock.badge.xmark", text: "Конец", isTimeSelected: $isSelectedTime2)
|
||||
.onChange(of: vm._class.endtime) { oldValue, newValue in
|
||||
if !checkStartTimeLessThenEndTime(vm._class.starttime, vm._class.endtime) {
|
||||
self.isIncorrectDate2 = true
|
||||
self.isSelectedTime2 = false
|
||||
print("Второй")
|
||||
print(self.isSelectedTime1)
|
||||
print(self.isSelectedTime2)
|
||||
}
|
||||
else {
|
||||
self.isIncorrectDate1 = false
|
||||
self.isIncorrectDate2 = false
|
||||
}
|
||||
}
|
||||
.overlay {
|
||||
if isIncorrectDate2 {
|
||||
Rectangle()
|
||||
.frame(maxWidth: 300, maxHeight: 1)
|
||||
.foregroundColor(.red)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
}
|
||||
// .overlay {
|
||||
// if isIncorrectDate2 {
|
||||
// Rectangle()
|
||||
// .frame(maxWidth: 300, maxHeight: 1)
|
||||
// .foregroundColor(.red)
|
||||
// .padding(.horizontal)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
.frame(height: 40)
|
||||
.padding(.bottom, 10)
|
||||
@ -115,25 +168,8 @@ struct CreateEditClassView: View {
|
||||
.fill(.white)
|
||||
)
|
||||
.padding(.bottom, 10)
|
||||
HStack {
|
||||
Text("Тип")
|
||||
Spacer()
|
||||
Picker("Тип", selection: $vm._class.online, content: {
|
||||
ForEach(MockData.onlineOrOffline, id: \.self) {
|
||||
Text($0)
|
||||
}
|
||||
})
|
||||
.accentColor(Color("grayForFields"))
|
||||
}
|
||||
.frame(height: 40)
|
||||
.padding(.horizontal)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(.white)
|
||||
)
|
||||
.padding(.bottom, 10)
|
||||
|
||||
CommentFieldView(textForComment: $vm._class.comment)
|
||||
CommentFieldView(textForComment: $vm._class.comment, isFocused: _isFocusedComment)
|
||||
.padding(.bottom, 20)
|
||||
|
||||
|
||||
@ -172,21 +208,51 @@ struct CreateEditClassView: View {
|
||||
}
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button("Сохранить") {
|
||||
do {
|
||||
try vm.save()
|
||||
dismiss()
|
||||
} catch {
|
||||
print(error)
|
||||
isFocusedSubject = false
|
||||
isFocusedProfessor = false
|
||||
isFocusedAuditory = false
|
||||
isFocusedComment = false
|
||||
if (vm._class.subject.isEmpty || (isIncorrectDate1 || isIncorrectDate2) || (!isSelectedTime1 || !isSelectedTime2)) {
|
||||
if (vm._class.subject.isEmpty) {
|
||||
self.isShowingSubjectFieldRed = true
|
||||
self.textForLabelInSubjectField = ""
|
||||
}
|
||||
if !isSelectedTime1 {
|
||||
self.isIncorrectDate1 = true
|
||||
}
|
||||
if !isSelectedTime2 {
|
||||
self.isIncorrectDate2 = true
|
||||
}
|
||||
}
|
||||
else {
|
||||
do {
|
||||
try vm.save()
|
||||
dismiss()
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle(vm.isNew ? "Новая пара" : "Изменить данные")
|
||||
.background(Color("background"))
|
||||
.onAppear {
|
||||
if day >= Calendar.current.startOfDay(for: Date()) {
|
||||
vm._class.day = day
|
||||
}
|
||||
}
|
||||
.onTapGesture {
|
||||
isFocusedSubject = false
|
||||
isFocusedProfessor = false
|
||||
isFocusedAuditory = false
|
||||
isFocusedComment = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
CreateEditClassView(vm: .init(provider: .shared))
|
||||
let day: Date = .init()
|
||||
CreateEditClassView(vm: .init(provider: .shared), day: day)
|
||||
}
|
||||
|
Reference in New Issue
Block a user