Alomost done with CreateClassView
This commit is contained in:
parent
4c3a46d40e
commit
4a295b9b88
@ -1,17 +1,17 @@
|
|||||||
//
|
//
|
||||||
// Field.swift
|
// AuditoryFieldView.swift
|
||||||
// Schedule ICTIS
|
// Schedule ICTIS
|
||||||
//
|
//
|
||||||
// Created by G412 on 16.12.2024.
|
// Created by G412 on 23.01.2025.
|
||||||
//
|
//
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct ProfessorAuditoryClassFieldView: View {
|
struct AuditoryFieldView: View {
|
||||||
@Binding var text: String
|
@Binding var text: String
|
||||||
var nameOfImage: String
|
var nameOfImage: String
|
||||||
var labelForField: String
|
var labelForField: String
|
||||||
@FocusState private var isFocused: Bool
|
@FocusState var isFocused: Bool
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack(spacing: 0) {
|
HStack(spacing: 0) {
|
||||||
Image(systemName: nameOfImage)
|
Image(systemName: nameOfImage)
|
@ -9,7 +9,7 @@ import SwiftUI
|
|||||||
|
|
||||||
struct CommentFieldView: View {
|
struct CommentFieldView: View {
|
||||||
@Binding var textForComment: String
|
@Binding var textForComment: String
|
||||||
@FocusState private var isFocused: Bool
|
@FocusState var isFocused: Bool
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack {
|
HStack {
|
||||||
|
48
Schedule ICTIS/Main/Views/Fields/ProfessorFieldView.swift
Normal file
48
Schedule ICTIS/Main/Views/Fields/ProfessorFieldView.swift
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
//
|
||||||
|
// ProfessorFieldView.swift
|
||||||
|
// Schedule ICTIS
|
||||||
|
//
|
||||||
|
// Created by G412 on 23.01.2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct ProfessorFieldView: View {
|
||||||
|
@Binding var text: String
|
||||||
|
var nameOfImage: String
|
||||||
|
var labelForField: String
|
||||||
|
@FocusState var isFocused: Bool
|
||||||
|
var body: some View {
|
||||||
|
HStack(spacing: 0) {
|
||||||
|
Image(systemName: nameOfImage)
|
||||||
|
.foregroundColor(Color.gray)
|
||||||
|
.padding(.leading, 12)
|
||||||
|
.padding(.trailing, 7)
|
||||||
|
TextField(labelForField, text: $text)
|
||||||
|
.font(.system(size: 18, weight: .regular))
|
||||||
|
.disableAutocorrection(true)
|
||||||
|
.submitLabel(.done)
|
||||||
|
.focused($isFocused)
|
||||||
|
if isFocused {
|
||||||
|
Button {
|
||||||
|
self.text = ""
|
||||||
|
self.isFocused = false
|
||||||
|
} label: {
|
||||||
|
Image(systemName: "xmark.circle.fill")
|
||||||
|
.padding(.trailing, 20)
|
||||||
|
.offset(x: 10)
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(height: 40)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: 10)
|
||||||
|
.fill(.white)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
ContentView()
|
||||||
|
}
|
@ -13,20 +13,19 @@ struct StartEndTimeFieldView: View {
|
|||||||
@Binding var selectedTime: Date
|
@Binding var selectedTime: Date
|
||||||
var imageName: String
|
var imageName: String
|
||||||
var text: String
|
var text: String
|
||||||
@State private var isTimeSelected: Bool = false
|
@Binding var isTimeSelected: Bool
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack {
|
HStack {
|
||||||
Image(systemName: imageName)
|
Image(systemName: imageName)
|
||||||
.foregroundColor(isIncorrectDate ? .red : Color("grayForFields"))
|
.foregroundColor(isIncorrectDate ? .red : Color("grayForFields"))
|
||||||
.padding(.leading, 12)
|
.padding(.leading, 12)
|
||||||
|
|
||||||
if !isTimeSelected {
|
if !isTimeSelected || isIncorrectDate {
|
||||||
Text(text)
|
Text(text)
|
||||||
.font(.system(size: 17, weight: .regular))
|
.font(.system(size: 17, weight: .regular))
|
||||||
.foregroundColor(.gray.opacity(0.5))
|
.foregroundColor(.gray.opacity(0.5))
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if isTimeSelected {
|
|
||||||
Text("\(selectedTime, formatter: timeFormatter)")
|
Text("\(selectedTime, formatter: timeFormatter)")
|
||||||
.foregroundColor(isIncorrectDate ? .red : .black)
|
.foregroundColor(isIncorrectDate ? .red : .black)
|
||||||
.font(.system(size: 17, weight: .medium))
|
.font(.system(size: 17, weight: .medium))
|
||||||
@ -40,7 +39,7 @@ struct StartEndTimeFieldView: View {
|
|||||||
.fill(.white)
|
.fill(.white)
|
||||||
)
|
)
|
||||||
.overlay {
|
.overlay {
|
||||||
if isSameDate(selectedTime, selectedDay) {
|
if selectedDay.isToday {
|
||||||
DatePicker("", selection: $selectedTime, in: Date()..., displayedComponents: .hourAndMinute)
|
DatePicker("", selection: $selectedTime, in: Date()..., displayedComponents: .hourAndMinute)
|
||||||
.padding(.trailing, 35)
|
.padding(.trailing, 35)
|
||||||
.blendMode(.destinationOver)
|
.blendMode(.destinationOver)
|
||||||
|
66
Schedule ICTIS/Main/Views/Fields/SubjectFieldView.swift
Normal file
66
Schedule ICTIS/Main/Views/Fields/SubjectFieldView.swift
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
//
|
||||||
|
// Field.swift
|
||||||
|
// Schedule ICTIS
|
||||||
|
//
|
||||||
|
// Created by G412 on 16.12.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct SubjectFieldView: View {
|
||||||
|
@Binding var text: String
|
||||||
|
@Binding var isShowingSubjectFieldRed: Bool
|
||||||
|
var nameOfImage: String
|
||||||
|
@Binding var labelForField: String
|
||||||
|
@FocusState var isFocused: Bool
|
||||||
|
var body: some View {
|
||||||
|
HStack(spacing: 0) {
|
||||||
|
Image(systemName: nameOfImage)
|
||||||
|
.foregroundColor(Color.gray)
|
||||||
|
.padding(.leading, 12)
|
||||||
|
.padding(.trailing, 7)
|
||||||
|
TextField(labelForField, text: $text)
|
||||||
|
.font(.system(size: 18, weight: .regular))
|
||||||
|
.disableAutocorrection(true)
|
||||||
|
.submitLabel(.done)
|
||||||
|
.focused($isFocused)
|
||||||
|
.onChange(of: isFocused, initial: false) { oldValue, newValue in
|
||||||
|
if newValue {
|
||||||
|
self.isShowingSubjectFieldRed = false
|
||||||
|
self.labelForField = "Предмет"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.background {
|
||||||
|
Group {
|
||||||
|
if isShowingSubjectFieldRed {
|
||||||
|
Text("Поле должно быть заполнено!")
|
||||||
|
.font(.system(size: 18, weight: .regular))
|
||||||
|
.foregroundColor(.red)
|
||||||
|
.frame(width: 290)
|
||||||
|
.padding(.leading, -42)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if isFocused {
|
||||||
|
Button {
|
||||||
|
self.text = ""
|
||||||
|
self.isFocused = false
|
||||||
|
} label: {
|
||||||
|
Image(systemName: "xmark.circle.fill")
|
||||||
|
.padding(.trailing, 20)
|
||||||
|
.offset(x: 10)
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(height: 40)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: 10)
|
||||||
|
.fill(.white)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
ContentView()
|
||||||
|
}
|
@ -81,7 +81,7 @@ struct ScheduleView: View {
|
|||||||
selectedClass = nil
|
selectedClass = nil
|
||||||
},
|
},
|
||||||
content: { _class in
|
content: { _class in
|
||||||
CreateEditClassView(vm: .init(provider: provider, _class: _class))
|
CreateEditClassView(vm: .init(provider: provider, _class: _class), day: vm.selectedDay)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -77,7 +77,7 @@ struct SearchBarView: View {
|
|||||||
.frame(height: 40)
|
.frame(height: 40)
|
||||||
.accentColor(.blue)
|
.accentColor(.blue)
|
||||||
.sheet(isPresented: $isShowingSheet) {
|
.sheet(isPresented: $isShowingSheet) {
|
||||||
CreateEditClassView(vm: .init(provider: provider))
|
CreateEditClassView(vm: .init(provider: provider), day: vm.selectedDay)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,19 +11,63 @@ struct CreateEditClassView: View {
|
|||||||
@Environment(\.dismiss) private var dismiss
|
@Environment(\.dismiss) private var dismiss
|
||||||
@State private var isShowingDatePickerForDate: Bool = false
|
@State private var isShowingDatePickerForDate: Bool = false
|
||||||
@ObservedObject var vm: EditClassViewModel
|
@ObservedObject var vm: EditClassViewModel
|
||||||
|
var day: Date
|
||||||
@State private var isIncorrectDate1: Bool = false
|
@State private var isIncorrectDate1: Bool = false
|
||||||
@State private var isIncorrectDate2: 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 provider = ClassProvider.shared
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
ScrollView(.vertical, showsIndicators: false) {
|
ScrollView(.vertical, showsIndicators: false) {
|
||||||
VStack {
|
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)
|
.padding(.bottom, 10)
|
||||||
ProfessorAuditoryClassFieldView(text: $vm._class.auditory, nameOfImage: "mappin.and.ellipse", labelForField: "Корпус-аудитория")
|
HStack {
|
||||||
.padding(.bottom, 10)
|
Text("Тип")
|
||||||
ProfessorAuditoryClassFieldView(text: $vm._class.professor, nameOfImage: "book", labelForField: "Преподаватель")
|
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)
|
.padding(.bottom, 10)
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
Image(systemName: "calendar")
|
Image(systemName: "calendar")
|
||||||
.foregroundColor(Color.gray)
|
.foregroundColor(Color.gray)
|
||||||
@ -46,46 +90,55 @@ struct CreateEditClassView: View {
|
|||||||
.overlay {
|
.overlay {
|
||||||
DatePicker("", selection: $vm._class.day, in: Date()..., displayedComponents: .date)
|
DatePicker("", selection: $vm._class.day, in: Date()..., displayedComponents: .date)
|
||||||
.blendMode(.destinationOver)
|
.blendMode(.destinationOver)
|
||||||
|
|
||||||
}
|
}
|
||||||
.padding(.bottom, 10)
|
.padding(.bottom, 10)
|
||||||
HStack {
|
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
|
.onChange(of: vm._class.starttime) { oldValue, newValue in
|
||||||
if !checkStartTimeLessThenEndTime(vm._class.starttime, vm._class.endtime) {
|
if !checkStartTimeLessThenEndTime(vm._class.starttime, vm._class.endtime) {
|
||||||
self.isIncorrectDate1 = true
|
self.isIncorrectDate1 = true
|
||||||
|
self.isSelectedTime1 = false
|
||||||
|
print("Первый")
|
||||||
|
print(self.isSelectedTime1)
|
||||||
|
print(self.isSelectedTime2)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self.isIncorrectDate1 = false
|
self.isIncorrectDate1 = false
|
||||||
self.isIncorrectDate2 = false
|
self.isIncorrectDate2 = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.overlay {
|
// .overlay {
|
||||||
if isIncorrectDate1 {
|
// if isIncorrectDate1 {
|
||||||
Rectangle()
|
// Rectangle()
|
||||||
.frame(maxWidth: 300, maxHeight: 1)
|
// .frame(maxWidth: 300, maxHeight: 1)
|
||||||
.foregroundColor(.red)
|
// .foregroundColor(.red)
|
||||||
.padding(.horizontal)
|
// .padding(.horizontal)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
Spacer()
|
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
|
.onChange(of: vm._class.endtime) { oldValue, newValue in
|
||||||
if !checkStartTimeLessThenEndTime(vm._class.starttime, vm._class.endtime) {
|
if !checkStartTimeLessThenEndTime(vm._class.starttime, vm._class.endtime) {
|
||||||
self.isIncorrectDate2 = true
|
self.isIncorrectDate2 = true
|
||||||
|
self.isSelectedTime2 = false
|
||||||
|
print("Второй")
|
||||||
|
print(self.isSelectedTime1)
|
||||||
|
print(self.isSelectedTime2)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self.isIncorrectDate1 = false
|
self.isIncorrectDate1 = false
|
||||||
self.isIncorrectDate2 = false
|
self.isIncorrectDate2 = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.overlay {
|
// .overlay {
|
||||||
if isIncorrectDate2 {
|
// if isIncorrectDate2 {
|
||||||
Rectangle()
|
// Rectangle()
|
||||||
.frame(maxWidth: 300, maxHeight: 1)
|
// .frame(maxWidth: 300, maxHeight: 1)
|
||||||
.foregroundColor(.red)
|
// .foregroundColor(.red)
|
||||||
.padding(.horizontal)
|
// .padding(.horizontal)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
.frame(height: 40)
|
.frame(height: 40)
|
||||||
.padding(.bottom, 10)
|
.padding(.bottom, 10)
|
||||||
@ -115,25 +168,8 @@ struct CreateEditClassView: View {
|
|||||||
.fill(.white)
|
.fill(.white)
|
||||||
)
|
)
|
||||||
.padding(.bottom, 10)
|
.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)
|
.padding(.bottom, 20)
|
||||||
|
|
||||||
|
|
||||||
@ -172,21 +208,51 @@ struct CreateEditClassView: View {
|
|||||||
}
|
}
|
||||||
ToolbarItem(placement: .navigationBarTrailing) {
|
ToolbarItem(placement: .navigationBarTrailing) {
|
||||||
Button("Сохранить") {
|
Button("Сохранить") {
|
||||||
do {
|
isFocusedSubject = false
|
||||||
try vm.save()
|
isFocusedProfessor = false
|
||||||
dismiss()
|
isFocusedAuditory = false
|
||||||
} catch {
|
isFocusedComment = false
|
||||||
print(error)
|
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 ? "Новая пара" : "Изменить данные")
|
.navigationTitle(vm.isNew ? "Новая пара" : "Изменить данные")
|
||||||
.background(Color("background"))
|
.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 {
|
#Preview {
|
||||||
CreateEditClassView(vm: .init(provider: .shared))
|
let day: Date = .init()
|
||||||
|
CreateEditClassView(vm: .init(provider: .shared), day: day)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user