Commit
This commit is contained in:
@ -41,6 +41,3 @@ struct CommentFieldView: View {
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
SheetCreateClassView(isShowingSheet: .constant(true))
|
||||
}
|
||||
|
@ -46,12 +46,6 @@ struct StartEndTimeFieldView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var timeFormatter: DateFormatter {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = "HH:mm"
|
||||
return formatter
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
|
@ -11,7 +11,7 @@ struct MainView: View {
|
||||
@State private var searchText: String = ""
|
||||
@State private var isShowingMonthSlider: Bool = false
|
||||
@State private var isFirstAppearence = true
|
||||
@ObservedObject var vm: ViewModel
|
||||
@ObservedObject var vm: ScheduleViewModel
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
@ -64,7 +64,7 @@ struct MainView: View {
|
||||
Image(isShowingMonthSlider ? "arrowup" : "arrowdown")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 15, height: 15) // Установите размер изображения
|
||||
.frame(width: 15, height: 15)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,8 @@ import SwiftUI
|
||||
|
||||
struct ScheduleView: View {
|
||||
@State private var isShowingSheet: Bool = false
|
||||
@ObservedObject var vm: ViewModel
|
||||
@ObservedObject var vm: ScheduleViewModel
|
||||
@FetchRequest(fetchRequest: ClassModel.all()) private var classes
|
||||
var body: some View {
|
||||
if vm.isLoading {
|
||||
LoadingView(isLoading: $vm.isLoading)
|
||||
@ -58,6 +59,39 @@ struct ScheduleView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
ForEach(classes) { _class in
|
||||
if datesAreEqual(_class.day, vm.selectedDay) {
|
||||
HStack(spacing: 10) {
|
||||
VStack {
|
||||
Text(getTimeString(_class.starttime))
|
||||
.font(.system(size: 15, weight: .regular))
|
||||
Text(getTimeString(_class.endtime))
|
||||
.font(.system(size: 15, weight: .regular))
|
||||
}
|
||||
.padding(.top, 7)
|
||||
.padding(.bottom, 7)
|
||||
.padding(.leading, 10)
|
||||
Rectangle()
|
||||
.frame(width: 2)
|
||||
.frame(maxHeight: UIScreen.main.bounds.height - 18)
|
||||
.padding(.top, 7)
|
||||
.padding(.bottom, 7)
|
||||
.foregroundColor(_class.important ? Color("redForImportant") : onlineOrNot(_class.online))
|
||||
Text(getSubjectName(_class.subject, _class.professor, _class.auditory))
|
||||
.font(.system(size: 18, weight: .regular))
|
||||
.padding(.top, 7)
|
||||
.padding(.bottom, 7)
|
||||
Spacer()
|
||||
}
|
||||
.frame(maxWidth: UIScreen.main.bounds.width - 40, maxHeight: 230)
|
||||
.background(Color.white)
|
||||
.cornerRadius(20)
|
||||
.shadow(color: .black.opacity(0.25), radius: 4, x: 2, y: 2)
|
||||
.onTapGesture {
|
||||
isShowingSheet = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(width: UIScreen.main.bounds.width)
|
||||
.padding(.bottom, 100)
|
||||
|
@ -11,7 +11,9 @@ struct SearchBarView: View {
|
||||
@Binding var text: String
|
||||
@State private var isEditing = false
|
||||
@State private var isShowingSheet: Bool = false
|
||||
@ObservedObject var vm: ViewModel
|
||||
@ObservedObject var vm: ScheduleViewModel
|
||||
|
||||
var provider = ClassProvider.shared
|
||||
|
||||
var body: some View {
|
||||
HStack (spacing: 11) {
|
||||
@ -28,6 +30,9 @@ struct SearchBarView: View {
|
||||
.onSubmit {
|
||||
self.isEditing = false
|
||||
if (!text.isEmpty) {
|
||||
if !vm.numOfGroup.isEmpty {
|
||||
|
||||
}
|
||||
vm.fetchWeekSchedule(text)
|
||||
vm.group = text
|
||||
}
|
||||
@ -78,7 +83,7 @@ struct SearchBarView: View {
|
||||
.frame(height: 40)
|
||||
.accentColor(.blue)
|
||||
.sheet(isPresented: $isShowingSheet) {
|
||||
SheetCreateClassView(isShowingSheet: $isShowingSheet)
|
||||
SheetCreateClassView(isShowingSheet: $isShowingSheet, vm: .init(provider: provider))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,22 +13,21 @@ struct SheetCreateClassView: View {
|
||||
@State private var textForNameOfAuditory = ""
|
||||
@State private var textForNameOfProfessor = ""
|
||||
@State private var isShowingDatePickerForDate: Bool = false
|
||||
@State private var selectedDay: Date = Date()
|
||||
@State private var selectedStartTime: Date = Date()
|
||||
@State private var selectedEndTime: Date = Date()
|
||||
@State private var isImportant: Bool = false
|
||||
@State private var selectedOption: String = "Нет"
|
||||
@State private var selectedOptionForNotification: String = "Нет"
|
||||
@State private var selectedOptionForOnline: String = "Оффлайн"
|
||||
@State private var textForComment: String = ""
|
||||
@ObservedObject var vm: EditClassViewModel
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
VStack {
|
||||
ProfessorAuditoryClassFieldView(text: $textForNameOfClass, nameOfImage: "book", labelForField: "Предмет")
|
||||
ProfessorAuditoryClassFieldView(text: $vm._class.subject, nameOfImage: "book", labelForField: "Предмет")
|
||||
.padding(.bottom, 10)
|
||||
ProfessorAuditoryClassFieldView(text: $textForNameOfAuditory, nameOfImage: "mappin.and.ellipse", labelForField: "Корпус-аудитория")
|
||||
ProfessorAuditoryClassFieldView(text: $vm._class.auditory, nameOfImage: "mappin.and.ellipse", labelForField: "Корпус-аудитория")
|
||||
.padding(.bottom, 10)
|
||||
ProfessorAuditoryClassFieldView(text: $textForNameOfProfessor, nameOfImage: "book", labelForField: "Преподаватель")
|
||||
ProfessorAuditoryClassFieldView(text: $vm._class.professor, nameOfImage: "book", labelForField: "Преподаватель")
|
||||
.padding(.bottom, 10)
|
||||
HStack {
|
||||
Image(systemName: "calendar")
|
||||
@ -39,7 +38,7 @@ struct SheetCreateClassView: View {
|
||||
.foregroundColor(Color("grayForFields").opacity(0.5))
|
||||
.font(.system(size: 18, weight: .regular))
|
||||
Spacer()
|
||||
Text("\(selectedDay, formatter: dateFormatter)")
|
||||
Text("\(vm._class.day, formatter: dateFormatter)")
|
||||
.foregroundColor(.black)
|
||||
.font(.system(size: 18, weight: .medium))
|
||||
.padding(.trailing, 20)
|
||||
@ -50,18 +49,30 @@ struct SheetCreateClassView: View {
|
||||
.fill(.white)
|
||||
)
|
||||
.overlay {
|
||||
DatePicker("", selection: $selectedDay, in: Date()..., displayedComponents: .date)
|
||||
DatePicker("", selection: $vm._class.day, in: Date()..., displayedComponents: .date)
|
||||
.blendMode(.destinationOver)
|
||||
}
|
||||
.padding(.bottom, 10)
|
||||
HStack {
|
||||
StartEndTimeFieldView(selectedTime: $selectedStartTime, imageName: "clock", text: "Начало")
|
||||
StartEndTimeFieldView(selectedTime: $vm._class.starttime, imageName: "clock", text: "Начало")
|
||||
.onChange(of: vm._class.starttime) { oldValue, newValue in
|
||||
if !checkStartTimeLessThenEndTime(vm._class.starttime, vm._class.endtime) {
|
||||
print("Values \(oldValue) - \(newValue) 1")
|
||||
print(vm._class.starttime)
|
||||
vm._class.starttime = oldValue
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
StartEndTimeFieldView(selectedTime: $selectedEndTime, imageName: "clock.badge.xmark", text: "Конец")
|
||||
StartEndTimeFieldView(selectedTime: $vm._class.endtime, imageName: "clock.badge.xmark", text: "Конец")
|
||||
.onChange(of: vm._class.endtime) { oldValue, newValue in
|
||||
print("Values \(oldValue) - \(newValue) 2")
|
||||
print(vm._class.endtime)
|
||||
validateTime(old: oldValue, new: newValue, isStartChanged: false)
|
||||
}
|
||||
}
|
||||
.frame(height: 40)
|
||||
.padding(.bottom, 10)
|
||||
Toggle("Пометить как важную", isOn: $isImportant)
|
||||
Toggle("Пометить как важную", isOn: $vm._class.important)
|
||||
.frame(height: 40)
|
||||
.padding(.horizontal)
|
||||
.background(
|
||||
@ -73,7 +84,7 @@ struct SheetCreateClassView: View {
|
||||
HStack {
|
||||
Text("Напоминанние")
|
||||
Spacer()
|
||||
Picker("Напоминание", selection: $selectedOption, content: {
|
||||
Picker("Напоминание", selection: $vm._class.notification, content: {
|
||||
ForEach(MockData.notifications, id: \.self) {
|
||||
Text($0)
|
||||
}
|
||||
@ -87,8 +98,25 @@ struct SheetCreateClassView: 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: $textForComment)
|
||||
CommentFieldView(textForComment: $vm._class.comment)
|
||||
Spacer()
|
||||
}
|
||||
.padding(.horizontal)
|
||||
@ -102,6 +130,11 @@ struct SheetCreateClassView: View {
|
||||
}
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button("Сохранить") {
|
||||
do {
|
||||
try vm.save()
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
isShowingSheet = false
|
||||
}
|
||||
}
|
||||
@ -110,14 +143,18 @@ struct SheetCreateClassView: View {
|
||||
.background(Color("background"))
|
||||
}
|
||||
}
|
||||
private var dateFormatter: DateFormatter {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .medium
|
||||
formatter.timeStyle = .none
|
||||
return formatter
|
||||
func validateTime(old oldValue: Date, new newValue: Date, isStartChanged: Bool) {
|
||||
if !checkStartTimeLessThenEndTime(vm._class.starttime, vm._class.endtime) {
|
||||
if isStartChanged {
|
||||
vm._class.starttime = Date()
|
||||
} else {
|
||||
vm._class.starttime = Date()
|
||||
}
|
||||
print("Invalid time selected. Reverting to old value.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
SheetCreateClassView(isShowingSheet: .constant(true))
|
||||
SheetCreateClassView(isShowingSheet: .constant(true), vm: .init(provider: .shared))
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
// MonthTabView.swift
|
||||
// Schedule ICTIS
|
||||
//
|
||||
// Created by G412 on 10.12.2024.
|
||||
// Created by Mironov Egor on 10.12.2024.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
@ -12,7 +12,7 @@ struct MonthTabView: View {
|
||||
@State private var monthSlider: [[Date.MonthWeek]] = []
|
||||
@State private var createMonth: Bool = false
|
||||
@State private var currentWeekIndex: Int = 0
|
||||
@ObservedObject var vm: ViewModel
|
||||
@ObservedObject var vm: ScheduleViewModel
|
||||
var body: some View {
|
||||
VStack {
|
||||
HStack (spacing: 34) {
|
||||
@ -25,7 +25,6 @@ struct MonthTabView: View {
|
||||
}
|
||||
}
|
||||
.padding(.top, 14)
|
||||
//.background(Color.red)
|
||||
TabView(selection: $currentMonthIndex) {
|
||||
ForEach(monthSlider.indices, id: \.self) { index in
|
||||
let month = monthSlider[index]
|
||||
@ -37,7 +36,6 @@ struct MonthTabView: View {
|
||||
.padding(.bottom, -10)
|
||||
.padding(.horizontal, -15)
|
||||
.tabViewStyle(.page(indexDisplayMode: .never))
|
||||
//.background(Color.green)
|
||||
}
|
||||
.onAppear(perform: {
|
||||
vm.updateSelectedDayIndex()
|
||||
|
@ -11,7 +11,7 @@ struct WeekTabView: View {
|
||||
@State private var currentWeekIndex: Int = 1
|
||||
@State private var weekSlider: [[Date.WeekDay]] = []
|
||||
@State private var createWeek: Bool = false
|
||||
@ObservedObject var vm: ViewModel
|
||||
@ObservedObject var vm: ScheduleViewModel
|
||||
var body: some View {
|
||||
HStack {
|
||||
TabView(selection: $currentWeekIndex) {
|
||||
|
Reference in New Issue
Block a user