Lots of changes
This commit is contained in:
@ -20,20 +20,25 @@ struct MainView: View {
|
||||
var body: some View {
|
||||
VStack {
|
||||
SearchBarView(text: $searchText, vm: vm)
|
||||
CurrentDateView()
|
||||
if (vm.isFirstStartOffApp) {
|
||||
FirstLaunchScheduleView()
|
||||
}
|
||||
else {
|
||||
CurrentDateView()
|
||||
ScheduleView(vm: vm)
|
||||
}
|
||||
}
|
||||
.alert(isPresented: $vm.isShowingAlertForIncorrectGroup, error: vm.errorInNetwork) { error in
|
||||
|
||||
} message: { error in
|
||||
Text(error.failureReason)
|
||||
}
|
||||
.background(Color("background"))
|
||||
.onAppear(perform: {
|
||||
currentDate = vm.selectedDay
|
||||
vm.updateSelectedDayIndex(currentDate)
|
||||
if weekSlider.isEmpty {
|
||||
let currentWeek = Date().fetchWeek()
|
||||
let currentWeek = Date().fetchWeek(vm.selectedDay)
|
||||
|
||||
if let firstDate = currentWeek.first?.date {
|
||||
weekSlider.append(firstDate.createPrevioustWeek())
|
||||
@ -163,21 +168,37 @@ struct MainView: View {
|
||||
}
|
||||
|
||||
func paginateWeek() {
|
||||
let calendar = Calendar.current
|
||||
if weekSlider.indices.contains(currentWeekIndex) {
|
||||
if let firstDate = weekSlider[currentWeekIndex].first?.date,
|
||||
currentWeekIndex == 0 {
|
||||
vm.fetchWeekSchedule("new week", -1)
|
||||
switch (vm.numOfGroup) {
|
||||
case "":
|
||||
vm.week -= 1
|
||||
default:
|
||||
vm.fetchWeekSchedule("new week", -1)
|
||||
}
|
||||
weekSlider.insert(firstDate.createPrevioustWeek(), at: 0)
|
||||
weekSlider.removeLast()
|
||||
currentWeekIndex = 1
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -1, to: vm.selectedDay) ?? Date.init()
|
||||
currentDate = vm.selectedDay
|
||||
}
|
||||
|
||||
if let lastDate = weekSlider[currentWeekIndex].last?.date,
|
||||
currentWeekIndex == (weekSlider.count - 1) {
|
||||
vm.fetchWeekSchedule("new week", 1)
|
||||
switch (vm.numOfGroup) {
|
||||
case "":
|
||||
vm.week += 1
|
||||
default:
|
||||
vm.fetchWeekSchedule("new week", 1)
|
||||
}
|
||||
weekSlider.append(lastDate.createNextWeek())
|
||||
weekSlider.removeFirst()
|
||||
currentWeekIndex = weekSlider.count - 2
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 1, to: vm.selectedDay) ?? Date.init()
|
||||
currentDate = vm.selectedDay
|
||||
print(currentDate)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,16 +43,17 @@ struct ScheduleView: View {
|
||||
.frame(maxWidth: UIScreen.main.bounds.width - 40, maxHeight: 230)
|
||||
.background(Color.white)
|
||||
.cornerRadius(20)
|
||||
.shadow(color: .black.opacity(0.25), radius: 4, x: 4, y: 4)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(width: UIScreen.main.bounds.width)
|
||||
.padding(.bottom, 100)
|
||||
.padding(.top, 10)
|
||||
}
|
||||
}
|
||||
//ктбо2-6
|
||||
|
||||
func convertTimeString(_ input: String) -> [String] {
|
||||
let parts = input.split(separator: "-")
|
||||
|
@ -22,14 +22,14 @@ struct SearchBarView: View {
|
||||
TextField("Поиск группы", text: $text)
|
||||
.disableAutocorrection(true)
|
||||
.onTapGesture {
|
||||
isEditing = true
|
||||
self.isEditing = true
|
||||
}
|
||||
.onSubmit {
|
||||
isEditing = false
|
||||
self.isEditing = false
|
||||
if (!text.isEmpty) {
|
||||
vm.isFirstStartOffApp = false
|
||||
vm.fetchWeekSchedule(text)
|
||||
}
|
||||
self.text = ""
|
||||
}
|
||||
.submitLabel(.search)
|
||||
if isEditing {
|
||||
@ -53,19 +53,20 @@ struct SearchBarView: View {
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(.white)
|
||||
)
|
||||
Button {
|
||||
|
||||
} label: {
|
||||
ZStack {
|
||||
Rectangle()
|
||||
.frame(width: 40, height: 40)
|
||||
.foregroundStyle(Color("blueColor"))
|
||||
.cornerRadius(15)
|
||||
Image(systemName: "plus")
|
||||
.resizable()
|
||||
.foregroundStyle(.white)
|
||||
.scaledToFit()
|
||||
.frame(width: 16)
|
||||
if (!vm.isFirstStartOffApp && !vm.isShowingAlertForIncorrectGroup) {
|
||||
Button {
|
||||
} label: {
|
||||
ZStack {
|
||||
Rectangle()
|
||||
.frame(width: 40, height: 40)
|
||||
.foregroundStyle(Color("blueColor"))
|
||||
.cornerRadius(15)
|
||||
Image(systemName: "plus")
|
||||
.resizable()
|
||||
.foregroundStyle(.white)
|
||||
.scaledToFit()
|
||||
.frame(width: 16)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user