Commit
This commit is contained in:
parent
57e241292f
commit
1de531abc8
@ -1,6 +1,7 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "ICTIS_logo.png",
|
||||
"idiom" : "universal",
|
||||
"platform" : "ios",
|
||||
"size" : "1024x1024"
|
||||
|
BIN
Schedule ICTIS/Assets.xcassets/AppIcon.appiconset/ICTIS_logo.png
Normal file
BIN
Schedule ICTIS/Assets.xcassets/AppIcon.appiconset/ICTIS_logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
@ -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
|
||||
}
|
||||
}
|
@ -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:
|
||||
TabView(selection: $selectedTab) {
|
||||
Text("Tasks")
|
||||
case .settings:
|
||||
.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("Настройки")
|
||||
}
|
||||
TabBarView(selectedTab: $selectedTab)
|
||||
.tag(2)
|
||||
}
|
||||
.accentColor(Color("blueColor"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
25
Schedule ICTIS/Main/LoadingView.swift
Normal file
25
Schedule ICTIS/Main/LoadingView.swift
Normal file
@ -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))
|
||||
}
|
@ -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 {
|
||||
|
@ -10,6 +10,10 @@ import SwiftUI
|
||||
struct ScheduleView: View {
|
||||
@ObservedObject var vm: ViewModel
|
||||
var body: some View {
|
||||
if vm.isLoading {
|
||||
LoadingView(isLoading: $vm.isLoading)
|
||||
}
|
||||
else {
|
||||
ZStack (alignment: .top) {
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
VStack (spacing: 20) {
|
||||
@ -34,7 +38,7 @@ struct ScheduleView: View {
|
||||
.frame(maxHeight: UIScreen.main.bounds.height - 18)
|
||||
.padding(.top, 7)
|
||||
.padding(.bottom, 7)
|
||||
.foregroundColor(onlineOrOffline(lesson) ? Color("greenForOffline") : Color("blueForOnline"))
|
||||
.foregroundColor(getColorForClass(lesson))
|
||||
Text(lesson)
|
||||
.font(.system(size: 18, weight: .regular))
|
||||
.padding(.top, 7)
|
||||
@ -56,30 +60,10 @@ struct ScheduleView: View {
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,31 +38,54 @@ 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 {
|
||||
@ -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,9 +121,57 @@ 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user