diff --git a/Schedule ICTIS/Assets.xcassets/AppIcon.appiconset/Contents.json b/Schedule ICTIS/Assets.xcassets/AppIcon.appiconset/Contents.json index 13613e3..080ba9c 100644 --- a/Schedule ICTIS/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/Schedule ICTIS/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,6 +1,7 @@ { "images" : [ { + "filename" : "ICTIS_logo.png", "idiom" : "universal", "platform" : "ios", "size" : "1024x1024" diff --git a/Schedule ICTIS/Assets.xcassets/AppIcon.appiconset/ICTIS_logo.png b/Schedule ICTIS/Assets.xcassets/AppIcon.appiconset/ICTIS_logo.png new file mode 100644 index 0000000..44b05e5 Binary files /dev/null and b/Schedule ICTIS/Assets.xcassets/AppIcon.appiconset/ICTIS_logo.png differ diff --git a/Schedule ICTIS/Assets.xcassets/turquoise.colorset/Contents.json b/Schedule ICTIS/Assets.xcassets/turquoise.colorset/Contents.json new file mode 100644 index 0000000..ba13876 --- /dev/null +++ b/Schedule ICTIS/Assets.xcassets/turquoise.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0xDE", + "green" : "0xE4", + "red" : "0x22" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0xDE", + "green" : "0xE4", + "red" : "0x22" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Schedule ICTIS/ContentView.swift b/Schedule ICTIS/ContentView.swift index dd68dca..789de6c 100644 --- a/Schedule ICTIS/ContentView.swift +++ b/Schedule ICTIS/ContentView.swift @@ -8,20 +8,33 @@ import SwiftUI struct ContentView: View { - @State private var selectedTab: TabBarModel = .schedule + @State private var selectedTab: Int = 1 @StateObject var vm = ViewModel() + var body: some View { - ZStack { - switch selectedTab { - case .schedule: - MainView(vm: vm) - case .tasks: - Text("Tasks") - case .settings: - Text("Settings") - } - TabBarView(selectedTab: $selectedTab) + TabView(selection: $selectedTab) { + Text("Tasks") + .tabItem { + Image(systemName: "books.vertical") + Text("Задания") + } + .tag(0) + + MainView(vm: vm) + .tabItem { + Image(systemName: "house") + Text("Расписание") + } + .tag(1) + + Text("Settings") + .tabItem { + Image(systemName: "gear") + Text("Настройки") + } + .tag(2) } + .accentColor(Color("blueColor")) } } diff --git a/Schedule ICTIS/Helpers/Date+Extensions.swift b/Schedule ICTIS/Helpers/Date+Extensions.swift index c4256ca..135fd62 100644 --- a/Schedule ICTIS/Helpers/Date+Extensions.swift +++ b/Schedule ICTIS/Helpers/Date+Extensions.swift @@ -75,6 +75,24 @@ extension Date { return month } + func createNextMonth() -> [MonthWeek] { + let calendar = Calendar.current + let startOfLastDate = calendar.startOfDay(for: self) + guard let nextDate = calendar.date(byAdding: .day, value: 1, to: startOfLastDate) else { + return [] + } + return fetchMonth(nextDate) + } + + func createPreviousMonth() -> [MonthWeek] { + let calendar = Calendar.current + let startOfFirstDate = calendar.startOfDay(for: self) + guard let previousDate = calendar.date(byAdding: .month, value: -1, to: startOfFirstDate) else { + return [] + } + return fetchMonth(previousDate) + } + func createNextWeek() -> [WeekDay] { let calendar = Calendar.current let startOfLastDate = calendar.startOfDay(for: self) diff --git a/Schedule ICTIS/Helpers/View+Extensions.swift b/Schedule ICTIS/Helpers/View+Extensions.swift index 07bd8e9..7b883dc 100644 --- a/Schedule ICTIS/Helpers/View+Extensions.swift +++ b/Schedule ICTIS/Helpers/View+Extensions.swift @@ -24,4 +24,50 @@ extension View { return currentMonth == dateMonth && currentYear == dateYear } + + func isSameWeek(_ date1: Date, _ date2: Date) -> Bool { + return Calendar.current.compare(date1, to: date2, toGranularity: .weekOfYear) == .orderedSame + } + + func weeksBetween(startDate: Date, endDate: Date) -> Int { + let calendar = Calendar.current + let startOfFirstDate = calendar.startOfDay(for: startDate) + let startOfEndDate = calendar.startOfDay(for: endDate) + + let weekForDate1 = calendar.dateInterval(of: .weekOfMonth, for: startOfFirstDate) + let weekForDate2 = calendar.dateInterval(of: .weekOfMonth, for: startOfEndDate) + + guard let startOfWeek1 = weekForDate1?.start else { + return 0 + } + + guard let startOfWeek2 = weekForDate2?.start else { + return 0 + } + + let components = calendar.dateComponents([.day], from: startOfWeek1, to: startOfWeek2) + let daysDifference = components.day ?? 0 + return Int(ceil(Double(abs(daysDifference)) / 7.0)) + } + + func convertTimeString(_ input: String) -> [String] { + let parts = input.split(separator: "-") + if let firstPart = parts.first, let lastPart = parts.last { + return [String(firstPart), String(lastPart)] + } else { + return [] + } + } + + func getColorForClass(_ str: String) -> Color { + if (str.contains("LMS")) { + return Color("blueForOnline") + } + else if (str.contains("ВПК")) { + return Color("turquoise") + } + else { + return Color("greenForOffline") + } + } } diff --git a/Schedule ICTIS/Main/LoadingView.swift b/Schedule ICTIS/Main/LoadingView.swift new file mode 100644 index 0000000..372f54e --- /dev/null +++ b/Schedule ICTIS/Main/LoadingView.swift @@ -0,0 +1,25 @@ +// +// LoadingView.swift +// Schedule ICTIS +// +// Created by G412 on 11.12.2024. +// + +import SwiftUI + +struct LoadingView: View { + @Binding var isLoading: Bool + var body: some View { + ZStack { + Color("background") + .ignoresSafeArea() + ProgressView() + .progressViewStyle(CircularProgressViewStyle(tint: .secondary)) + .scaleEffect(1.5) + } + } +} + +#Preview { + LoadingView(isLoading: .constant(true)) +} diff --git a/Schedule ICTIS/Main/MainView.swift b/Schedule ICTIS/Main/MainView.swift index e44e294..047bba4 100644 --- a/Schedule ICTIS/Main/MainView.swift +++ b/Schedule ICTIS/Main/MainView.swift @@ -9,10 +9,6 @@ import SwiftUI struct MainView: View { @State private var searchText: String = "" - @State private var currentDate: Date = Date() - @State private var weekSlider: [[Date.WeekDay]] = [] - @State private var currentWeekIndex: Int = 1 - @State private var createWeek: Bool = false @State private var isShowingMonthSlider: Bool = false @State private var isFirstAppearence = true @ObservedObject var vm: ViewModel @@ -20,7 +16,10 @@ struct MainView: View { var body: some View { VStack { SearchBarView(text: $searchText, vm: vm) - if (vm.isFirstStartOffApp) { + if (vm.isFirstStartOffApp && vm.isLoading) { + LoadingView(isLoading: $vm.isLoading) + } + else if (vm.isFirstStartOffApp) { FirstLaunchScheduleView() } else { @@ -34,23 +33,6 @@ struct MainView: View { Text(error.failureReason) } .background(Color("background")) - .onAppear(perform: { - currentDate = vm.selectedDay - vm.updateSelectedDayIndex(currentDate) - if weekSlider.isEmpty { - let currentWeek = Date().fetchWeek(vm.selectedDay) - - if let firstDate = currentWeek.first?.date { - weekSlider.append(firstDate.createPrevioustWeek()) - } - - weekSlider.append(currentWeek) - - if let lastDate = currentWeek.last?.date { - weekSlider.append(lastDate.createNextWeek()) - } - } - }) } @ViewBuilder @@ -58,14 +40,14 @@ struct MainView: View { VStack (alignment: .leading, spacing: 6) { HStack { VStack (alignment: .leading, spacing: 0) { - Text(currentDate.format("EEEE")) + Text(vm.selectedDay.format("EEEE")) .font(.system(size: 40, weight: .semibold)) .foregroundStyle(.black) HStack (spacing: 5) { - Text(currentDate.format("dd")) + Text(vm.selectedDay.format("dd")) .font(.system(size: 20, weight: .bold)) .foregroundStyle(Color("grayForDate")) - Text(currentDate.format("MMMM")) + Text(vm.selectedDay.format("MMMM")) .font(.system(size: 20, weight: .bold)) .foregroundStyle(Color("grayForDate")) Spacer() @@ -91,7 +73,7 @@ struct MainView: View { Spacer() } if (!isShowingMonthSlider) { - WeekTabView(currentWeekIndex: $currentWeekIndex, weekSlider: $weekSlider, currentDate: $currentDate, vm: vm) + WeekTabView(vm: vm) .transition(.opacity) } else { diff --git a/Schedule ICTIS/Main/ScheduleView.swift b/Schedule ICTIS/Main/ScheduleView.swift index 212ae75..2e319eb 100644 --- a/Schedule ICTIS/Main/ScheduleView.swift +++ b/Schedule ICTIS/Main/ScheduleView.swift @@ -10,75 +10,59 @@ import SwiftUI struct ScheduleView: View { @ObservedObject var vm: ViewModel var body: some View { - ZStack (alignment: .top) { - ScrollView(.vertical, showsIndicators: false) { - VStack (spacing: 20) { - ForEach(vm.classes.indices, id: \.self) { index in - if index != 0 && index != 1 && index == vm.selectedIndex { - let daySchedule = vm.classes[index] // Это массив строк для дня - ForEach(daySchedule.indices.dropFirst(), id: \.self) { lessonIndex in - let lesson = daySchedule[lessonIndex] // Это строка с расписанием одной пары - if !lesson.isEmpty { - HStack(spacing: 10) { - VStack { - Text(convertTimeString(vm.classes[1][lessonIndex])[0]) - .font(.system(size: 15, weight: .regular)) - Text(convertTimeString(vm.classes[1][lessonIndex])[1]) - .font(.system(size: 15, weight: .regular)) + if vm.isLoading { + LoadingView(isLoading: $vm.isLoading) + } + else { + ZStack (alignment: .top) { + ScrollView(.vertical, showsIndicators: false) { + VStack (spacing: 20) { + ForEach(vm.classes.indices, id: \.self) { index in + if index != 0 && index != 1 && index == vm.selectedIndex { + let daySchedule = vm.classes[index] // Это массив строк для дня + ForEach(daySchedule.indices.dropFirst(), id: \.self) { lessonIndex in + let lesson = daySchedule[lessonIndex] // Это строка с расписанием одной пары + if !lesson.isEmpty { + HStack(spacing: 10) { + VStack { + Text(convertTimeString(vm.classes[1][lessonIndex])[0]) + .font(.system(size: 15, weight: .regular)) + Text(convertTimeString(vm.classes[1][lessonIndex])[1]) + .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(getColorForClass(lesson)) + Text(lesson) + .font(.system(size: 18, weight: .regular)) + .padding(.top, 7) + .padding(.bottom, 7) + Spacer() } - .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(onlineOrOffline(lesson) ? Color("greenForOffline") : Color("blueForOnline")) - Text(lesson) - .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) } - .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) } } } } + .frame(width: UIScreen.main.bounds.width) + .padding(.bottom, 100) + .padding(.top, 30) } - .frame(width: UIScreen.main.bounds.width) - .padding(.bottom, 100) - .padding(.top, 30) + VStack { + LinearGradient(gradient: Gradient(colors: [Color("background").opacity(0.9), Color("background").opacity(0.89)]), startPoint: .top, endPoint: .bottom) + } + .frame(width: UIScreen.main.bounds.width, height: 15) } - VStack { - LinearGradient(gradient: Gradient(colors: [Color("background").opacity(0.9), Color("background").opacity(0.89)]), startPoint: .top, endPoint: .bottom) -// Rectangle() -// .frame(width: UIScreen.main.bounds.width, height: 25) -// .foregroundColor(Color("background").opacity(0.9)) - } - .frame(width: UIScreen.main.bounds.width, height: 15) - } - } - - func convertTimeString(_ input: String) -> [String] { - let parts = input.split(separator: "-") - if let firstPart = parts.first, let lastPart = parts.last { - return [String(firstPart), String(lastPart)] - } else { - return [] - } - } - - func onlineOrOffline(_ str: String) -> Bool { - if (MockData.onlineClasses.contains(str)) { - return false - } - else { - return true } } } diff --git a/Schedule ICTIS/Main/TabViews/MonthTabView.swift b/Schedule ICTIS/Main/TabViews/MonthTabView.swift index 539d24d..ed4ca89 100644 --- a/Schedule ICTIS/Main/TabViews/MonthTabView.swift +++ b/Schedule ICTIS/Main/TabViews/MonthTabView.swift @@ -11,7 +11,6 @@ struct MonthTabView: View { @State private var currentMonthIndex: Int = 1 @State private var monthSlider: [[Date.MonthWeek]] = [] @State private var createMonth: Bool = false - @State private var currentDate: Date = .init() @ObservedObject var vm: ViewModel var body: some View { VStack { @@ -39,32 +38,55 @@ struct MonthTabView: View { .tabViewStyle(.page(indexDisplayMode: .never)) //.background(Color.green) } + .onAppear(perform: { + vm.updateSelectedDayIndex() + if monthSlider.isEmpty { + let currentMonth = Date().fetchMonth(vm.selectedDay) + + if let firstDate = currentMonth.first?.week[0].date { + monthSlider.append(firstDate.createPreviousMonth()) + } + + monthSlider.append(currentMonth) + + if let lastDate = currentMonth.last?.week[6].date { + monthSlider.append(lastDate.createNextMonth()) + } + } + }) .onChange(of: currentMonthIndex, initial: false) { oldValue, newValue in if newValue == 0 || newValue == (monthSlider.count - 1) { createMonth = true } } - .onAppear(perform: { - currentDate = vm.selectedDay - vm.updateSelectedDayIndex(currentDate) - if monthSlider.isEmpty { - let currentMonth = Date().fetchMonth(vm.selectedDay) - - monthSlider.append(currentMonth) - } - }) } @ViewBuilder func MonthView(_ month: [Date.MonthWeek]) -> some View { - VStack { + VStack (spacing: 10) { ForEach(month.indices, id: \.self) { index in let week = month[index].week WeekView(week) } } + .background { + GeometryReader { + let minX = $0.frame(in: .global).minX + + Color.clear + .preference(key: OffsetKey.self, value: minX) + .onPreferenceChange(OffsetKey.self) { value in + if (abs(value.rounded()) - 20) < 5 && createMonth { + paginateMonth() + + createMonth = false + } + } + } + } } + @ViewBuilder func WeekView(_ week: [Date.WeekDay]) -> some View { HStack (spacing: 23) { @@ -72,18 +94,18 @@ struct MonthTabView: View { VStack { Text(day.date.format("dd")) .font(.system(size: 15, weight: .bold)) - .foregroundStyle(isDateInCurrentMonth(day.date) ? isSameDate(day.date, currentDate) ? Color.white : Color.black: isSameDate(day.date, currentDate) ? Color.white : Color("greyForDaysInMonthTabView")) + .foregroundStyle(isDateInCurrentMonth(day.date) ? isSameDate(day.date, vm.selectedDay) ? Color.white : Color.black: isSameDate(day.date, vm.selectedDay) ? Color.white : Color("greyForDaysInMonthTabView")) } .frame(width: 30, height: 30, alignment: .center) .background( content: { Group { - if isSameDate(day.date, currentDate) { + if isSameDate(day.date, vm.selectedDay) { Color("blueColor") } else { Color("background") } - if isSameDate(day.date, currentDate) { + if isSameDate(day.date, vm.selectedDay) { Color("blueColor") } } @@ -91,7 +113,7 @@ struct MonthTabView: View { ) .overlay ( Group { - if day.date.isToday && !isSameDate(day.date, currentDate) { + if day.date.isToday && !isSameDate(day.date, vm.selectedDay) { RoundedRectangle(cornerRadius: 100) .stroke(Color("blueColor"), lineWidth: 2) } @@ -99,12 +121,60 @@ struct MonthTabView: View { ) .cornerRadius(15) .onTapGesture { - currentDate = day.date - vm.updateSelectedDayIndex(currentDate) + if isSameWeek(day.date, vm.selectedDay) { + print("На одной неделе") + } + else { + var difBetweenWeeks = weeksBetween(startDate: vm.selectedDay, endDate: day.date) + if day.date < vm.selectedDay { + difBetweenWeeks = difBetweenWeeks * -1 + } + print(difBetweenWeeks) + vm.fetchWeekSchedule("", difBetweenWeeks) + } + vm.selectedDay = day.date + vm.updateSelectedDayIndex() } } } } + + func paginateMonth() { + let calendar = Calendar.current + if monthSlider.indices.contains(currentMonthIndex) { + if let firstDate = monthSlider[currentMonthIndex].first?.week[0].date, + currentMonthIndex == 0 { +// switch (vm.numOfGroup) { +// case "": +// vm.week -= 1 +// default: +// vm.fetchWeekSchedule("new week", -1) +// } + monthSlider.insert(firstDate.createPreviousMonth(), at: 0) + monthSlider.removeLast() + currentMonthIndex = 1 + vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -5, to: vm.selectedDay) ?? Date.init() + vm.updateSelectedDayIndex() + vm.fetchWeekSchedule("", -5) + } + + if let lastDate = monthSlider[currentMonthIndex].last?.week[6].date, + currentMonthIndex == (monthSlider.count - 1) { +// switch (vm.numOfGroup) { +// case "": +// vm.week += 1 +// default: +// vm.fetchWeekSchedule("new week", 1) +// } + monthSlider.append(lastDate.createNextMonth()) + monthSlider.removeFirst() + currentMonthIndex = monthSlider.count - 2 + vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 5, to: vm.selectedDay) ?? Date.init() + vm.updateSelectedDayIndex() + vm.fetchWeekSchedule("", 5) + } + } + } } #Preview { diff --git a/Schedule ICTIS/Main/TabViews/WeekTabView.swift b/Schedule ICTIS/Main/TabViews/WeekTabView.swift index 37a634b..4adc101 100644 --- a/Schedule ICTIS/Main/TabViews/WeekTabView.swift +++ b/Schedule ICTIS/Main/TabViews/WeekTabView.swift @@ -8,9 +8,8 @@ import SwiftUI struct WeekTabView: View { - @Binding var currentWeekIndex: Int - @Binding var weekSlider: [[Date.WeekDay]] - @Binding var currentDate: Date + @State private var currentWeekIndex: Int = 1 + @State private var weekSlider: [[Date.WeekDay]] = [] @State private var createWeek: Bool = false @ObservedObject var vm: ViewModel var body: some View { @@ -27,6 +26,22 @@ struct WeekTabView: View { .tabViewStyle(.page(indexDisplayMode: .never)) .frame(height: 90) } + .onAppear(perform: { + vm.updateSelectedDayIndex() + if weekSlider.isEmpty { + let currentWeek = Date().fetchWeek(vm.selectedDay) + + if let firstDate = currentWeek.first?.date { + weekSlider.append(firstDate.createPrevioustWeek()) + } + + weekSlider.append(currentWeek) + + if let lastDate = currentWeek.last?.date { + weekSlider.append(lastDate.createNextWeek()) + } + } + }) .onChange(of: currentWeekIndex, initial: false) { oldValue, newValue in if newValue == 0 || newValue == (weekSlider.count - 1) { createWeek = true @@ -41,24 +56,24 @@ struct WeekTabView: View { VStack (spacing: 1) { Text(day.date.format("E")) .font(.system(size: 15, weight: .semibold)) - .foregroundColor(day.date.format("E") == "Вс" ? Color(.red) : isSameDate(day.date, currentDate) ? Color("customGray1") : Color("customGray3")) + .foregroundColor(day.date.format("E") == "Вс" ? Color(.red) : isSameDate(day.date, vm.selectedDay) ? Color("customGray1") : Color("customGray3")) .padding(.top, 13) .foregroundColor(.gray) Text(day.date.format("dd")) .font(.system(size: 15, weight: .bold)) - .foregroundStyle(isSameDate(day.date, currentDate) ? .white : .black) + .foregroundStyle(isSameDate(day.date, vm.selectedDay) ? .white : .black) .padding(.bottom, 13) } .frame(width: 43, height: 55, alignment: .center) .background( content: { Group { - if isSameDate(day.date, currentDate) { + if isSameDate(day.date, vm.selectedDay) { Color("blueColor") } else { Color(.white) } - if isSameDate(day.date, currentDate) { + if isSameDate(day.date, vm.selectedDay) { Color("blueColor") } } @@ -66,7 +81,7 @@ struct WeekTabView: View { ) .overlay ( Group { - if day.date.isToday && !isSameDate(day.date, currentDate) { + if day.date.isToday && !isSameDate(day.date, vm.selectedDay) { RoundedRectangle(cornerRadius: 15) .stroke(Color("blueColor"), lineWidth: 2) } @@ -74,8 +89,8 @@ struct WeekTabView: View { ) .cornerRadius(15) .onTapGesture { - currentDate = day.date - vm.updateSelectedDayIndex(currentDate) + vm.selectedDay = day.date + vm.updateSelectedDayIndex() } } } @@ -111,7 +126,7 @@ struct WeekTabView: View { weekSlider.removeLast() currentWeekIndex = 1 vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -1, to: vm.selectedDay) ?? Date.init() - currentDate = vm.selectedDay + vm.updateSelectedDayIndex() } if let lastDate = weekSlider[currentWeekIndex].last?.date, @@ -126,8 +141,7 @@ struct WeekTabView: View { weekSlider.removeFirst() currentWeekIndex = weekSlider.count - 2 vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 1, to: vm.selectedDay) ?? Date.init() - currentDate = vm.selectedDay - print(currentDate) + vm.updateSelectedDayIndex() } } } diff --git a/Schedule ICTIS/Main/TabBar/TabBarModel.swift b/Schedule ICTIS/Model/TabBarModel.swift similarity index 100% rename from Schedule ICTIS/Main/TabBar/TabBarModel.swift rename to Schedule ICTIS/Model/TabBarModel.swift diff --git a/Schedule ICTIS/ViewModel/ViewModel.swift b/Schedule ICTIS/ViewModel/ViewModel.swift index 9bd3ff3..c4bf32b 100644 --- a/Schedule ICTIS/ViewModel/ViewModel.swift +++ b/Schedule ICTIS/ViewModel/ViewModel.swift @@ -26,9 +26,11 @@ final class ViewModel: ObservableObject { @Published var isFirstStartOffApp = true @Published var isShowingAlertForIncorrectGroup: Bool = false @Published var errorInNetwork: NetworkError? + @Published var isLoading: Bool = false //MARK: Methods func fetchWeekSchedule(_ group: String, _ num: Int = 0) { + isLoading = true Task { do { var schedule: Schedule @@ -45,6 +47,7 @@ final class ViewModel: ObservableObject { classes = weekSchedule.table self.isFirstStartOffApp = false self.isShowingAlertForIncorrectGroup = false + isLoading = false } catch { if let error = error as? NetworkError { @@ -57,15 +60,15 @@ final class ViewModel: ObservableObject { default: print(2) } + isLoading = false print(error) } } } } - func updateSelectedDayIndex(_ date: Date) { - selectedDay = date - switch date.format("E") { + func updateSelectedDayIndex() { + switch selectedDay.format("E") { case "Пн": selectedIndex = 2 case "Вт": @@ -81,7 +84,6 @@ final class ViewModel: ObservableObject { default: selectedIndex = 8 } - print(selectedIndex) } }