Commit
This commit is contained in:
parent
13de6fa302
commit
15fbe5895c
@ -36,15 +36,23 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
.accentColor(Color("blueColor"))
|
.accentColor(Color("blueColor"))
|
||||||
.onAppear {
|
.onAppear {
|
||||||
let group = UserDefaults.standard.string(forKey: "group")
|
let group1 = UserDefaults.standard.string(forKey: "group")
|
||||||
if let nameGroup = group {
|
let group2 = UserDefaults.standard.string(forKey: "group2")
|
||||||
vm.group = nameGroup
|
let group3 = UserDefaults.standard.string(forKey: "group3")
|
||||||
vm.fetchWeekSchedule(group: nameGroup)
|
if let nameGroup1 = group1, nameGroup1 != "" {
|
||||||
|
vm.nameGroups.append(nameGroup1)
|
||||||
}
|
}
|
||||||
|
if let nameGroup2 = group2, nameGroup2 != "" {
|
||||||
|
vm.nameGroups.append(nameGroup2)
|
||||||
|
}
|
||||||
|
if let nameGroup3 = group3, nameGroup3 != "" {
|
||||||
|
vm.nameGroups.append(nameGroup3)
|
||||||
|
}
|
||||||
|
print("\(group1) - \(group2) - \(group3)")
|
||||||
|
vm.fetchWeekSchedule()
|
||||||
if let vpkStr = UserDefaults.standard.string(forKey: "vpk") {
|
if let vpkStr = UserDefaults.standard.string(forKey: "vpk") {
|
||||||
vm.fetchWeekVPK(vpk: vpkStr)
|
vm.fetchWeekVPK(vpk: vpkStr)
|
||||||
}
|
}
|
||||||
print(vm.vpks)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,6 @@ struct ScheduleView: View {
|
|||||||
@State private var isShowingMyPairs = false
|
@State private var isShowingMyPairs = false
|
||||||
@Binding var isScrolling: Bool
|
@Binding var isScrolling: Bool
|
||||||
var provider = ClassProvider.shared
|
var provider = ClassProvider.shared
|
||||||
var hasLessons: Bool {
|
|
||||||
return vm.classes.indices.contains(vm.selectedIndex) &&
|
|
||||||
vm.classes[vm.selectedIndex].dropFirst().contains { !$0.isEmpty }
|
|
||||||
}
|
|
||||||
var hasVPK: Bool {
|
var hasVPK: Bool {
|
||||||
return vm.vpks.indices.contains(vm.selectedIndex) && vm.vpks[vm.selectedIndex].dropFirst().contains { !$0.isEmpty }
|
return vm.vpks.indices.contains(vm.selectedIndex) && vm.vpks[vm.selectedIndex].dropFirst().contains { !$0.isEmpty }
|
||||||
}
|
}
|
||||||
@ -32,23 +28,20 @@ struct ScheduleView: View {
|
|||||||
ZStack (alignment: .top) {
|
ZStack (alignment: .top) {
|
||||||
ScrollView(.vertical, showsIndicators: false) {
|
ScrollView(.vertical, showsIndicators: false) {
|
||||||
VStack (spacing: 30) {
|
VStack (spacing: 30) {
|
||||||
VStack (alignment: .leading, spacing: 20 ) {
|
VStack (alignment: .leading, spacing: 10) {
|
||||||
if hasLessons {
|
ForEach(0..<vm.classesGroups.count, id: \.self) { dayIndex in
|
||||||
Text("Учебное расписание")
|
if dayIndex == vm.selectedIndex {
|
||||||
.font(.custom("Montserrat-Bold", fixedSize: 20))
|
ForEach(vm.classesGroups[dayIndex]) { info in
|
||||||
}
|
VStack (alignment: .trailing) {
|
||||||
ForEach(vm.classes.indices, id: \.self) { index in
|
Text(info.group)
|
||||||
if index != 0 && index != 1 && index == vm.selectedIndex {
|
.font(.custom("Montserrat-Regular", fixedSize: 11))
|
||||||
let daySchedule = vm.classes[index] // Это массив строк для дня
|
.foregroundColor(Color("grayForNameGroup"))
|
||||||
ForEach(daySchedule.indices.dropFirst(), id: \.self) { lessonIndex in
|
|
||||||
let lesson = daySchedule[lessonIndex] // Это строка с расписанием одной пары
|
|
||||||
if !lesson.isEmpty {
|
|
||||||
HStack(spacing: 15) {
|
HStack(spacing: 15) {
|
||||||
VStack {
|
VStack {
|
||||||
Text(convertTimeString(vm.classes[1][lessonIndex])[0])
|
Text(convertTimeString(info.time)[0])
|
||||||
.font(.custom("Montserrat-Regular", fixedSize: 15))
|
.font(.custom("Montserrat-Regular", fixedSize: 15))
|
||||||
.padding(.bottom, 1)
|
.padding(.bottom, 1)
|
||||||
Text(convertTimeString(vm.classes[1][lessonIndex])[1])
|
Text(convertTimeString(info.time)[1])
|
||||||
.font(.custom("Montserrat-Regular", fixedSize: 15))
|
.font(.custom("Montserrat-Regular", fixedSize: 15))
|
||||||
.padding(.top, 1)
|
.padding(.top, 1)
|
||||||
}
|
}
|
||||||
@ -61,8 +54,8 @@ struct ScheduleView: View {
|
|||||||
.frame(maxHeight: UIScreen.main.bounds.height - 18)
|
.frame(maxHeight: UIScreen.main.bounds.height - 18)
|
||||||
.padding(.top, 7)
|
.padding(.top, 7)
|
||||||
.padding(.bottom, 7)
|
.padding(.bottom, 7)
|
||||||
.foregroundColor(getColorForClass(lesson))
|
.foregroundColor(getColorForClass(info.subject))
|
||||||
Text(lesson)
|
Text(info.subject)
|
||||||
.font(.custom("Montserrat-Medium", fixedSize: 16))
|
.font(.custom("Montserrat-Medium", fixedSize: 16))
|
||||||
.lineSpacing(3)
|
.lineSpacing(3)
|
||||||
.padding(.top, 9)
|
.padding(.top, 9)
|
||||||
@ -92,54 +85,6 @@ struct ScheduleView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if UserDefaults.standard.string(forKey: "vpk") != nil {
|
|
||||||
VStack (alignment: .leading, spacing: 20 ) {
|
|
||||||
if hasVPK {
|
|
||||||
Text("ВПК")
|
|
||||||
.font(.custom("Montserrat-Bold", fixedSize: 20))
|
|
||||||
}
|
|
||||||
ForEach(vm.vpks.indices, id: \.self) { index in
|
|
||||||
if index != 0 && index != 1 && index == vm.selectedIndex {
|
|
||||||
let dayVPK = vm.vpks[index] // Это массив строк для дня
|
|
||||||
ForEach(dayVPK.indices.dropFirst(), id: \.self) { lessonIndex in
|
|
||||||
let lesson = dayVPK[lessonIndex] // Это строка с расписанием одной пары
|
|
||||||
if !lesson.isEmpty {
|
|
||||||
HStack(spacing: 15) {
|
|
||||||
VStack {
|
|
||||||
Text(convertTimeString(vm.vpks[1][lessonIndex])[0])
|
|
||||||
.font(.custom("Montserrat-Regular", fixedSize: 15))
|
|
||||||
.padding(.bottom, 1)
|
|
||||||
Text(convertTimeString(vm.vpks[1][lessonIndex])[1])
|
|
||||||
.font(.custom("Montserrat-Regular", fixedSize: 15))
|
|
||||||
.padding(.top, 1)
|
|
||||||
}
|
|
||||||
.frame(width: 48)
|
|
||||||
.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(.custom("Montserrat-Medium", fixedSize: 16))
|
|
||||||
.lineSpacing(3)
|
|
||||||
.padding(.top, 9)
|
|
||||||
.padding(.bottom, 9)
|
|
||||||
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(width: UIScreen.main.bounds.width)
|
.frame(width: UIScreen.main.bounds.width)
|
||||||
.padding(.bottom, 100)
|
.padding(.bottom, 100)
|
||||||
|
@ -29,7 +29,7 @@ struct SearchBarView: View {
|
|||||||
.onSubmit {
|
.onSubmit {
|
||||||
self.isFocused = false
|
self.isFocused = false
|
||||||
if (!text.isEmpty) {
|
if (!text.isEmpty) {
|
||||||
vm.fetchWeekSchedule(group: text)
|
//vm.fetchWeekSchedule(group: text)
|
||||||
}
|
}
|
||||||
self.text = ""
|
self.text = ""
|
||||||
}
|
}
|
||||||
|
@ -21,3 +21,10 @@ struct Table: Decodable {
|
|||||||
let table: [[String]]
|
let table: [[String]]
|
||||||
let link: String
|
let link: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ClassInfo: Identifiable {
|
||||||
|
let id = UUID()
|
||||||
|
let subject: String
|
||||||
|
let group: String
|
||||||
|
let time: String
|
||||||
|
}
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"colors" : [
|
||||||
|
{
|
||||||
|
"color" : {
|
||||||
|
"color-space" : "srgb",
|
||||||
|
"components" : {
|
||||||
|
"alpha" : "1.000",
|
||||||
|
"blue" : "0x89",
|
||||||
|
"green" : "0x89",
|
||||||
|
"red" : "0x89"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"idiom" : "universal"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"appearances" : [
|
||||||
|
{
|
||||||
|
"appearance" : "luminosity",
|
||||||
|
"value" : "dark"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"color" : {
|
||||||
|
"color-space" : "srgb",
|
||||||
|
"components" : {
|
||||||
|
"alpha" : "1.000",
|
||||||
|
"blue" : "0x89",
|
||||||
|
"green" : "0x89",
|
||||||
|
"red" : "0x89"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"idiom" : "universal"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
95
Schedule ICTIS/Settings/FavGroupsView.swift
Normal file
95
Schedule ICTIS/Settings/FavGroupsView.swift
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
//
|
||||||
|
// FavGroupsView.swift
|
||||||
|
// Schedule ICTIS
|
||||||
|
//
|
||||||
|
// Created by G412 on 05.03.2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct FavGroupsView: View {
|
||||||
|
@ObservedObject var vm: ScheduleViewModel
|
||||||
|
var firstFavGroup = (UserDefaults.standard.string(forKey: "group") ?? "")
|
||||||
|
var secondFavGroup = (UserDefaults.standard.string(forKey: "group2") ?? "")
|
||||||
|
var thirdFavGroup = (UserDefaults.standard.string(forKey: "group3") ?? "")
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
List {
|
||||||
|
if firstFavGroup != "" {
|
||||||
|
HStack {
|
||||||
|
Text(firstFavGroup)
|
||||||
|
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.background(Color.white)
|
||||||
|
.cornerRadius(10)
|
||||||
|
.swipeActions(edge: .trailing) {
|
||||||
|
Button(role: .destructive) {
|
||||||
|
UserDefaults.standard.set("", forKey: "group")
|
||||||
|
vm.updateArrayOfGroups()
|
||||||
|
vm.fetchWeekSchedule()
|
||||||
|
} label: {
|
||||||
|
Label("Удалить", systemImage: "trash")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if secondFavGroup != "" {
|
||||||
|
HStack {
|
||||||
|
Text(secondFavGroup)
|
||||||
|
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.background(Color.white)
|
||||||
|
.cornerRadius(10)
|
||||||
|
.swipeActions(edge: .trailing) {
|
||||||
|
Button(role: .destructive) {
|
||||||
|
UserDefaults.standard.set("", forKey: "group2")
|
||||||
|
vm.updateArrayOfGroups()
|
||||||
|
vm.fetchWeekSchedule()
|
||||||
|
} label: {
|
||||||
|
Label("Удалить", systemImage: "trash")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if thirdFavGroup != "" {
|
||||||
|
HStack {
|
||||||
|
Text(thirdFavGroup)
|
||||||
|
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.background(Color.white)
|
||||||
|
.cornerRadius(10)
|
||||||
|
.swipeActions(edge: .trailing) {
|
||||||
|
Button(role: .destructive) {
|
||||||
|
UserDefaults.standard.set("", forKey: "group3")
|
||||||
|
vm.updateArrayOfGroups()
|
||||||
|
vm.fetchWeekSchedule()
|
||||||
|
} label: {
|
||||||
|
Label("Удалить", systemImage: "trash")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if firstFavGroup == "" || secondFavGroup == "" || thirdFavGroup == "" {
|
||||||
|
NavigationLink(destination: SelectingGroupView(vm: vm, firstFavGroup: firstFavGroup, secondFavGroup: secondFavGroup, thirdFavGroup: thirdFavGroup)) {
|
||||||
|
HStack {
|
||||||
|
Image(systemName: "plus")
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.font(.system(size: 22))
|
||||||
|
.padding(EdgeInsets(top: 15, leading: 130, bottom: 15, trailing: 130))
|
||||||
|
}
|
||||||
|
.padding(.horizontal)
|
||||||
|
.background(Color("blueColor"))
|
||||||
|
.cornerRadius(10)
|
||||||
|
.padding(.bottom, 40)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.background(Color("background"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
@Previewable @StateObject var vm = ScheduleViewModel()
|
||||||
|
FavGroupsView(vm: vm)
|
||||||
|
}
|
@ -8,20 +8,15 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct ScheduleGroupSettings: View {
|
struct ScheduleGroupSettings: View {
|
||||||
@AppStorage("group") private var favGroup = ""
|
|
||||||
@AppStorage("vpk") private var favVPK = ""
|
|
||||||
@ObservedObject var vm: ScheduleViewModel
|
@ObservedObject var vm: ScheduleViewModel
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
NavigationLink(destination: SelectingGroupView(vm: vm)) {
|
NavigationLink(destination: FavGroupsView(vm: vm)) {
|
||||||
HStack {
|
HStack {
|
||||||
Text("Избранное расписание")
|
Text("Избранное расписание")
|
||||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||||
.foregroundColor(.black)
|
.foregroundColor(.black)
|
||||||
Spacer()
|
Spacer()
|
||||||
Text(favGroup)
|
|
||||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
|
||||||
.foregroundColor(Color("customGray3"))
|
|
||||||
Image("arrowRight")
|
Image("arrowRight")
|
||||||
}
|
}
|
||||||
.padding(.horizontal)
|
.padding(.horizontal)
|
||||||
@ -38,9 +33,6 @@ struct ScheduleGroupSettings: View {
|
|||||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||||
.foregroundColor(.black)
|
.foregroundColor(.black)
|
||||||
Spacer()
|
Spacer()
|
||||||
Text(favVPK)
|
|
||||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
|
||||||
.foregroundColor(Color("customGray3"))
|
|
||||||
Image("arrowRight")
|
Image("arrowRight")
|
||||||
}
|
}
|
||||||
.padding(.horizontal)
|
.padding(.horizontal)
|
||||||
|
@ -14,142 +14,132 @@ struct SelectingGroupView: View {
|
|||||||
@ObservedObject var vm: ScheduleViewModel
|
@ObservedObject var vm: ScheduleViewModel
|
||||||
@State private var isLoading = false
|
@State private var isLoading = false
|
||||||
@State private var searchTask: DispatchWorkItem?
|
@State private var searchTask: DispatchWorkItem?
|
||||||
@AppStorage("group") private var favGroup = ""
|
@StateObject private var serchGroupsVM = SearchGroupsViewModel()
|
||||||
|
var firstFavGroup: String
|
||||||
|
var secondFavGroup: String
|
||||||
|
var thirdFavGroup: String
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
VStack {
|
||||||
VStack {
|
HStack (spacing: 0) {
|
||||||
HStack (spacing: 0) {
|
Image(systemName: "magnifyingglass")
|
||||||
Image(systemName: "magnifyingglass")
|
.foregroundColor(Color.gray)
|
||||||
.foregroundColor(Color.gray)
|
.padding(.leading, 12)
|
||||||
.padding(.leading, 12)
|
.padding(.trailing, 7)
|
||||||
.padding(.trailing, 7)
|
TextField("Поиск группы", text: $text)
|
||||||
TextField("Поиск группы", text: $text)
|
.disableAutocorrection(true)
|
||||||
.disableAutocorrection(true)
|
.focused($isFocused)
|
||||||
.focused($isFocused)
|
.onChange(of: text) { oldValue, newValue in
|
||||||
.onChange(of: text) { oldValue, newValue in
|
searchTask?.cancel()
|
||||||
searchTask?.cancel()
|
let task = DispatchWorkItem {
|
||||||
let task = DispatchWorkItem {
|
if !text.isEmpty {
|
||||||
if !text.isEmpty {
|
serchGroupsVM.fetchGroups(group: text)
|
||||||
vm.fetchGroups(group: text)
|
}
|
||||||
|
else {
|
||||||
|
serchGroupsVM.fetchGroups(group: "кт")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
searchTask = task
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: task)
|
||||||
|
}
|
||||||
|
.onSubmit {
|
||||||
|
self.isFocused = false
|
||||||
|
if (!text.isEmpty) {
|
||||||
|
vm.fetchWeekSchedule(isOtherWeek: false)
|
||||||
|
self.isLoading = true
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||||
|
self.isLoading = false
|
||||||
|
if vm.errorInNetwork == .noError {
|
||||||
|
vm.errorInNetwork = nil
|
||||||
|
print("Зашел")
|
||||||
|
if firstFavGroup == "" {
|
||||||
|
UserDefaults.standard.set(text, forKey: "group")
|
||||||
|
} else if secondFavGroup == "" {
|
||||||
|
UserDefaults.standard.set(text, forKey: "group2")
|
||||||
|
} else {
|
||||||
|
UserDefaults.standard.set(text, forKey: "group3")
|
||||||
|
}
|
||||||
|
vm.nameGroups.append(text)
|
||||||
|
self.text = ""
|
||||||
|
dismiss()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
vm.fetchGroups(group: "кт")
|
vm.isShowingAlertForIncorrectGroup = true
|
||||||
}
|
vm.errorInNetwork = .invalidResponse
|
||||||
}
|
|
||||||
searchTask = task
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: task)
|
|
||||||
}
|
|
||||||
.onSubmit {
|
|
||||||
self.isFocused = false
|
|
||||||
if (!text.isEmpty) {
|
|
||||||
vm.fetchWeekSchedule(group: text)
|
|
||||||
self.isLoading = true
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
||||||
self.isLoading = false
|
|
||||||
if vm.errorInNetwork == .noError {
|
|
||||||
vm.errorInNetwork = nil
|
|
||||||
print("Зашел")
|
|
||||||
UserDefaults.standard.set(text, forKey: "group")
|
|
||||||
vm.group = text
|
|
||||||
self.text = ""
|
|
||||||
dismiss()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
vm.isShowingAlertForIncorrectGroup = true
|
|
||||||
vm.errorInNetwork = .invalidResponse
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.submitLabel(.done)
|
|
||||||
if isFocused {
|
|
||||||
Button {
|
|
||||||
self.text = ""
|
|
||||||
self.isFocused = false
|
|
||||||
} label: {
|
|
||||||
Image(systemName: "xmark.circle.fill")
|
|
||||||
.padding(.trailing, 20)
|
|
||||||
.offset(x: 10)
|
|
||||||
.foregroundColor(.gray)
|
|
||||||
.background(
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
.submitLabel(.done)
|
||||||
.frame(height: 40)
|
|
||||||
.background(
|
|
||||||
RoundedRectangle(cornerRadius: 15)
|
|
||||||
.fill(.white)
|
|
||||||
)
|
|
||||||
Spacer()
|
|
||||||
if isLoading {
|
|
||||||
LoadingView(isLoading: $isLoading)
|
|
||||||
}
|
|
||||||
if isFocused {
|
if isFocused {
|
||||||
ScrollView(.vertical, showsIndicators: true) {
|
Button {
|
||||||
ForEach(vm.groups) { item in
|
self.text = ""
|
||||||
if item.name.starts(with: "КТ") { //Отображаем только группы(без аудиторий и преподавателей)
|
self.isFocused = false
|
||||||
VStack {
|
} label: {
|
||||||
Rectangle()
|
Image(systemName: "xmark.circle.fill")
|
||||||
.frame(height: 1)
|
.padding(.trailing, 20)
|
||||||
.foregroundColor(Color("customGray1"))
|
.offset(x: 10)
|
||||||
.padding(.horizontal, 10)
|
.foregroundColor(.gray)
|
||||||
HStack {
|
.background(
|
||||||
Text(item.name)
|
)
|
||||||
.foregroundColor(.black)
|
}
|
||||||
.font(.custom("Montserrat-SemiBold", fixedSize: 15))
|
}
|
||||||
Spacer()
|
}
|
||||||
}
|
.frame(height: 40)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: 15)
|
||||||
|
.fill(.white)
|
||||||
|
)
|
||||||
|
Spacer()
|
||||||
|
if isLoading {
|
||||||
|
LoadingView(isLoading: $isLoading)
|
||||||
|
}
|
||||||
|
if isFocused {
|
||||||
|
ScrollView(.vertical, showsIndicators: true) {
|
||||||
|
ForEach(serchGroupsVM.groups) { item in
|
||||||
|
if item.name.starts(with: "КТ") { //Отображаем только группы(без аудиторий и преподавателей)
|
||||||
|
VStack {
|
||||||
|
Rectangle()
|
||||||
|
.frame(height: 1)
|
||||||
|
.foregroundColor(Color("customGray1"))
|
||||||
.padding(.horizontal, 10)
|
.padding(.horizontal, 10)
|
||||||
.padding(.top, 2)
|
HStack {
|
||||||
.padding(.bottom, 2)
|
Text(item.name)
|
||||||
.frame(width: UIScreen.main.bounds.width, height: 30)
|
.foregroundColor(.black)
|
||||||
.background(Color("background"))
|
.font(.custom("Montserrat-SemiBold", fixedSize: 15))
|
||||||
.onTapGesture {
|
Spacer()
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 10)
|
||||||
|
.padding(.top, 2)
|
||||||
|
.padding(.bottom, 2)
|
||||||
|
.frame(width: UIScreen.main.bounds.width, height: 30)
|
||||||
|
.background(Color("background"))
|
||||||
|
.onTapGesture {
|
||||||
|
if firstFavGroup == "" {
|
||||||
UserDefaults.standard.set(item.name, forKey: "group")
|
UserDefaults.standard.set(item.name, forKey: "group")
|
||||||
vm.group = item.name
|
} else if secondFavGroup == "" {
|
||||||
vm.fetchWeekSchedule(group: item.name)
|
UserDefaults.standard.set(item.name, forKey: "group2")
|
||||||
dismiss()
|
} else {
|
||||||
|
UserDefaults.standard.set(item.name, forKey: "group3")
|
||||||
}
|
}
|
||||||
|
vm.updateArrayOfGroups()
|
||||||
|
vm.fetchWeekSchedule()
|
||||||
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if favGroup != "" {
|
|
||||||
Button {
|
|
||||||
UserDefaults.standard.removeObject(forKey: "group")
|
|
||||||
vm.classes.removeAll()
|
|
||||||
vm.group = ""
|
|
||||||
vm.numOfGroup = ""
|
|
||||||
dismiss()
|
|
||||||
} label: {
|
|
||||||
HStack {
|
|
||||||
Spacer()
|
|
||||||
Image(systemName: "trash")
|
|
||||||
Text("Удалить группу")
|
|
||||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
|
||||||
Spacer()
|
|
||||||
}
|
|
||||||
.frame(height: 40)
|
|
||||||
.background(Color.white)
|
|
||||||
.foregroundColor(Color.red)
|
|
||||||
.cornerRadius(10)
|
|
||||||
.padding(.bottom, 50)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(.horizontal, 10)
|
|
||||||
.background(Color("background"))
|
|
||||||
}
|
}
|
||||||
|
.padding(.horizontal, 10)
|
||||||
|
.background(Color("background"))
|
||||||
.onAppear {
|
.onAppear {
|
||||||
vm.fetchGroups(group: "кт")
|
serchGroupsVM.fetchGroups(group: "кт")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
@Previewable @StateObject var vm = ScheduleViewModel()
|
@Previewable @StateObject var vm = ScheduleViewModel()
|
||||||
SelectingGroupView(vm: vm)
|
SelectingGroupView(vm: vm, firstFavGroup: "", secondFavGroup: "", thirdFavGroup: "")
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ struct SelectingVPKView: View {
|
|||||||
@ObservedObject var vm: ScheduleViewModel
|
@ObservedObject var vm: ScheduleViewModel
|
||||||
@State private var isLoading = false
|
@State private var isLoading = false
|
||||||
@State private var searchTask: DispatchWorkItem?
|
@State private var searchTask: DispatchWorkItem?
|
||||||
|
@StateObject private var serchGroupsVM = SearchGroupsViewModel()
|
||||||
@AppStorage("vpk") private var favVPK = ""
|
@AppStorage("vpk") private var favVPK = ""
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
@ -30,10 +31,10 @@ struct SelectingVPKView: View {
|
|||||||
searchTask?.cancel()
|
searchTask?.cancel()
|
||||||
let task = DispatchWorkItem {
|
let task = DispatchWorkItem {
|
||||||
if !text.isEmpty {
|
if !text.isEmpty {
|
||||||
vm.fetchGroups(group: text)
|
serchGroupsVM.fetchGroups(group: text)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
vm.fetchGroups(group: "впк")
|
serchGroupsVM.fetchGroups(group: "впк")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
searchTask = task
|
searchTask = task
|
||||||
@ -50,7 +51,7 @@ struct SelectingVPKView: View {
|
|||||||
vm.errorInNetwork = nil
|
vm.errorInNetwork = nil
|
||||||
print("Зашел")
|
print("Зашел")
|
||||||
UserDefaults.standard.set(text, forKey: "vpk")
|
UserDefaults.standard.set(text, forKey: "vpk")
|
||||||
vm.group = text
|
//vm.group = text
|
||||||
self.text = ""
|
self.text = ""
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
@ -87,7 +88,7 @@ struct SelectingVPKView: View {
|
|||||||
}
|
}
|
||||||
if isFocused {
|
if isFocused {
|
||||||
ScrollView(.vertical, showsIndicators: true) {
|
ScrollView(.vertical, showsIndicators: true) {
|
||||||
ForEach(vm.groups) { item in
|
ForEach(serchGroupsVM.groups) { item in
|
||||||
if item.name.starts(with: "ВП") || item.name.starts(with: "мВ") {
|
if item.name.starts(with: "ВП") || item.name.starts(with: "мВ") {
|
||||||
VStack {
|
VStack {
|
||||||
Rectangle()
|
Rectangle()
|
||||||
@ -145,7 +146,7 @@ struct SelectingVPKView: View {
|
|||||||
.background(Color("background"))
|
.background(Color("background"))
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
vm.fetchGroups(group: "впк")
|
serchGroupsVM.fetchGroups(group: "впк")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
28
Schedule ICTIS/Settings/TestingView.swift
Normal file
28
Schedule ICTIS/Settings/TestingView.swift
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// TestingView.swift
|
||||||
|
// Schedule ICTIS
|
||||||
|
//
|
||||||
|
// Created by G412 on 05.03.2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct TestingView: View {
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
Text("Hello")
|
||||||
|
Text("Hello")
|
||||||
|
Text("Hello")
|
||||||
|
Text("Hello")
|
||||||
|
Text("Hello")
|
||||||
|
Text("Hello")
|
||||||
|
Text("Hello")
|
||||||
|
Text("Hello")
|
||||||
|
Text("Hello")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
TestingView()
|
||||||
|
}
|
@ -187,11 +187,11 @@ extension WeekViewForWeek {
|
|||||||
if let firstDate = weekSlider[currentWeekIndex].first?.date,
|
if let firstDate = weekSlider[currentWeekIndex].first?.date,
|
||||||
currentWeekIndex == 0 {
|
currentWeekIndex == 0 {
|
||||||
vm.week -= 1
|
vm.week -= 1
|
||||||
if vm.group != "" {
|
if !vm.nameGroups.isEmpty {
|
||||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||||
}
|
}
|
||||||
if UserDefaults.standard.string(forKey: "vpk") != nil {
|
if UserDefaults.standard.string(forKey: "vpk") != nil {
|
||||||
vm.fetchWeekVPK(isOtherWeek: true, vpk: UserDefaults.standard.string(forKey: "vpk"))
|
//vm.fetchWeekVPK(isOtherWeek: true, vpk: UserDefaults.standard.string(forKey: "vpk"))
|
||||||
}
|
}
|
||||||
weekSlider.insert(firstDate.createPrevioustWeek(), at: 0)
|
weekSlider.insert(firstDate.createPrevioustWeek(), at: 0)
|
||||||
weekSlider.removeLast()
|
weekSlider.removeLast()
|
||||||
@ -203,7 +203,7 @@ extension WeekViewForWeek {
|
|||||||
if let lastDate = weekSlider[currentWeekIndex].last?.date,
|
if let lastDate = weekSlider[currentWeekIndex].last?.date,
|
||||||
currentWeekIndex == (weekSlider.count - 1) {
|
currentWeekIndex == (weekSlider.count - 1) {
|
||||||
vm.week += 1
|
vm.week += 1
|
||||||
if vm.group != "" {
|
if !vm.nameGroups.isEmpty {
|
||||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||||
}
|
}
|
||||||
if UserDefaults.standard.string(forKey: "vpk") != nil {
|
if UserDefaults.standard.string(forKey: "vpk") != nil {
|
||||||
@ -252,11 +252,11 @@ extension WeekViewForMonth {
|
|||||||
}
|
}
|
||||||
print(difBetweenWeeks)
|
print(difBetweenWeeks)
|
||||||
vm.week += difBetweenWeeks
|
vm.week += difBetweenWeeks
|
||||||
if vm.group != "" {
|
if !vm.nameGroups.isEmpty {
|
||||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||||
}
|
}
|
||||||
if UserDefaults.standard.string(forKey: "vpk") != nil {
|
if UserDefaults.standard.string(forKey: "vpk") != nil {
|
||||||
vm.fetchWeekVPK(isOtherWeek: true, vpk: UserDefaults.standard.string(forKey: "vpk"))
|
//vm.fetchWeekVPK(isOtherWeek: true, vpk: UserDefaults.standard.string(forKey: "vpk"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vm.selectedDay = day.date
|
vm.selectedDay = day.date
|
||||||
@ -293,7 +293,7 @@ extension MonthTabView {
|
|||||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -5, to: vm.selectedDay) ?? Date.init()
|
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -5, to: vm.selectedDay) ?? Date.init()
|
||||||
vm.updateSelectedDayIndex()
|
vm.updateSelectedDayIndex()
|
||||||
vm.week -= 5
|
vm.week -= 5
|
||||||
if vm.group != "" {
|
if !vm.nameGroups.isEmpty {
|
||||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||||
}
|
}
|
||||||
if let vpkStr = UserDefaults.standard.string(forKey: "vpk") {
|
if let vpkStr = UserDefaults.standard.string(forKey: "vpk") {
|
||||||
@ -309,7 +309,7 @@ extension MonthTabView {
|
|||||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 5, to: vm.selectedDay) ?? Date.init()
|
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 5, to: vm.selectedDay) ?? Date.init()
|
||||||
vm.updateSelectedDayIndex()
|
vm.updateSelectedDayIndex()
|
||||||
vm.week += 5
|
vm.week += 5
|
||||||
if vm.group != "" {
|
if !vm.nameGroups.isEmpty {
|
||||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||||
}
|
}
|
||||||
if let vpkStr = UserDefaults.standard.string(forKey: "vpk") {
|
if let vpkStr = UserDefaults.standard.string(forKey: "vpk") {
|
||||||
|
@ -6,10 +6,16 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import SwiftUICore
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
final class ScheduleViewModel: ObservableObject {
|
final class ScheduleViewModel: ObservableObject {
|
||||||
//MARK: Properties
|
//MARK: Properties
|
||||||
|
|
||||||
|
@Published var nameGroups: [String] = []
|
||||||
|
@Published var numbersNTMLGroups: [String] = []
|
||||||
|
@Published var classesGroups: [[ClassInfo]] = []
|
||||||
|
|
||||||
//Schedule
|
//Schedule
|
||||||
@Published var weekScheduleGroup: Table = Table(
|
@Published var weekScheduleGroup: Table = Table(
|
||||||
type: "",
|
type: "",
|
||||||
@ -21,14 +27,12 @@ final class ScheduleViewModel: ObservableObject {
|
|||||||
)
|
)
|
||||||
@Published var selectedDay: Date = .init()
|
@Published var selectedDay: Date = .init()
|
||||||
@Published var selectedIndex: Int = 1
|
@Published var selectedIndex: Int = 1
|
||||||
@Published var classes: [[String]] = []
|
|
||||||
@Published var week: Int = 0
|
@Published var week: Int = 0
|
||||||
@Published var numOfGroup: String = ""
|
|
||||||
@Published var isFirstStartOffApp = true
|
@Published var isFirstStartOffApp = true
|
||||||
@Published var isShowingAlertForIncorrectGroup: Bool = false
|
@Published var isShowingAlertForIncorrectGroup: Bool = false
|
||||||
@Published var errorInNetwork: NetworkError?
|
@Published var errorInNetwork: NetworkError?
|
||||||
@Published var isLoading: Bool = false
|
@Published var isLoading: Bool = false
|
||||||
@Published var group: String = ""
|
|
||||||
@Published var isNewGroup: Bool = false
|
@Published var isNewGroup: Bool = false
|
||||||
|
|
||||||
//Groups
|
//Groups
|
||||||
@ -46,39 +50,64 @@ final class ScheduleViewModel: ObservableObject {
|
|||||||
link: ""
|
link: ""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//MARK: Methods
|
||||||
//MARK: Methods
|
func fetchWeekSchedule(isOtherWeek: Bool = false) {
|
||||||
func fetchWeekSchedule(group: String = "default", isOtherWeek: Bool = false) {
|
|
||||||
isLoading = true
|
isLoading = true
|
||||||
Task {
|
Task {
|
||||||
do {
|
do {
|
||||||
var schedule: Schedule
|
var updatedClassesGroups: [[ClassInfo]] = Array(repeating: [], count: 6) // 6 дней (пн-сб)
|
||||||
// В этот if мы заходим только если пользователь перелистывает недели и нам ИЗВЕСТНЫ номер группы(в html формате) и номер недели, которая показывается пользователю
|
|
||||||
if (isOtherWeek || !isFirstStartOffApp) && (group == "default") {
|
if isOtherWeek {
|
||||||
schedule = try await NetworkManager.shared.getScheduleForOtherWeek(self.week, self.numOfGroup)
|
for groupHTML in numbersNTMLGroups {
|
||||||
|
let schedule = try await NetworkManager.shared.getScheduleForOtherWeek(self.week, groupHTML)
|
||||||
|
let table = schedule.table.table
|
||||||
|
let nameOfGroup = schedule.table.name
|
||||||
|
|
||||||
|
// Преобразуем данные в формат ClassInfo
|
||||||
|
for (dayIndex, day) in table[2...].enumerated() { // Пропускаем первые две строки (заголовки)
|
||||||
|
for (timeIndex, subject) in day.enumerated() {
|
||||||
|
if !subject.isEmpty && timeIndex > 0 { // Пропускаем первый столбец (день и дату)
|
||||||
|
let time = table[1][timeIndex] // Время берем из второй строки
|
||||||
|
let classInfo = ClassInfo(subject: subject, group: nameOfGroup, time: time)
|
||||||
|
updatedClassesGroups[dayIndex].append(classInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for groupName in nameGroups {
|
||||||
|
let schedule = try await NetworkManager.shared.getSchedule(groupName)
|
||||||
|
let numberHTML = schedule.table.group
|
||||||
|
self.numbersNTMLGroups.append(numberHTML)
|
||||||
|
let table = schedule.table.table
|
||||||
|
let nameOfGroup = schedule.table.name
|
||||||
|
self.week = schedule.table.week
|
||||||
|
|
||||||
|
// Преобразуем данные в формат ClassInfo
|
||||||
|
for (dayIndex, day) in table[2...].enumerated() { // Пропускаем первые две строки (заголовки)
|
||||||
|
for (timeIndex, subject) in day.enumerated() {
|
||||||
|
if !subject.isEmpty && timeIndex > 0 { // Пропускаем первый столбец (день и дату)
|
||||||
|
let time = table[1][timeIndex] // Время берем из второй строки
|
||||||
|
let classInfo = ClassInfo(subject: subject, group: groupName, time: time)
|
||||||
|
updatedClassesGroups[dayIndex].append(classInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// В else мы заходим в том случае, если НЕ знаем номер недели, которую нужно отобразить и номер группы(в html формате)
|
|
||||||
else {
|
// Обновляем данные
|
||||||
print("Отладка 1")
|
self.classesGroups = updatedClassesGroups
|
||||||
schedule = try await NetworkManager.shared.getSchedule(group)
|
|
||||||
print("Отладка 2")
|
|
||||||
self.group = group
|
|
||||||
self.isNewGroup = true
|
|
||||||
self.selectedDay = .init()
|
|
||||||
}
|
|
||||||
self.weekScheduleGroup = schedule.table
|
|
||||||
self.week = weekScheduleGroup.week
|
|
||||||
self.numOfGroup = weekScheduleGroup.group
|
|
||||||
self.classes = weekScheduleGroup.table
|
|
||||||
self.isFirstStartOffApp = false
|
self.isFirstStartOffApp = false
|
||||||
self.isShowingAlertForIncorrectGroup = false
|
self.isShowingAlertForIncorrectGroup = false
|
||||||
self.isLoading = false
|
self.isLoading = false
|
||||||
self.errorInNetwork = .noError
|
self.errorInNetwork = .noError
|
||||||
print("Отладка 4")
|
|
||||||
}
|
// Сортируем по времени
|
||||||
catch {
|
self.sortClassesByTime()
|
||||||
|
} catch {
|
||||||
if let error = error as? NetworkError {
|
if let error = error as? NetworkError {
|
||||||
switch (error) {
|
switch error {
|
||||||
case .invalidResponse:
|
case .invalidResponse:
|
||||||
errorInNetwork = .invalidResponse
|
errorInNetwork = .invalidResponse
|
||||||
case .invalidData:
|
case .invalidData:
|
||||||
@ -135,46 +164,68 @@ final class ScheduleViewModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchGroups(group: String) {
|
|
||||||
Task {
|
|
||||||
do {
|
|
||||||
var groups: Welcome
|
|
||||||
groups = try await NetworkManager.shared.getGroups(group: group)
|
|
||||||
self.groups = groups.choices
|
|
||||||
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
if let error = error as? NetworkError {
|
|
||||||
switch (error) {
|
|
||||||
case .invalidData:
|
|
||||||
self.groups.removeAll()
|
|
||||||
default:
|
|
||||||
self.groups.removeAll()
|
|
||||||
print("Неизвестная ошибка: \(error)")
|
|
||||||
}
|
|
||||||
print("Есть ошибка: \(error)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateSelectedDayIndex() {
|
func updateSelectedDayIndex() {
|
||||||
switch selectedDay.format("E") {
|
switch selectedDay.format("E") {
|
||||||
case "Пн":
|
case "Пн":
|
||||||
selectedIndex = 2
|
selectedIndex = 0
|
||||||
case "Вт":
|
case "Вт":
|
||||||
selectedIndex = 3
|
selectedIndex = 1
|
||||||
case "Ср":
|
case "Ср":
|
||||||
selectedIndex = 4
|
selectedIndex = 2
|
||||||
case "Чт":
|
case "Чт":
|
||||||
selectedIndex = 5
|
selectedIndex = 3
|
||||||
case "Пт":
|
case "Пт":
|
||||||
selectedIndex = 6
|
selectedIndex = 4
|
||||||
case "Сб":
|
case "Сб":
|
||||||
selectedIndex = 7
|
selectedIndex = 5
|
||||||
default:
|
default:
|
||||||
selectedIndex = 8
|
selectedIndex = 6
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func parseTime(_ timeString: String) -> Int {
|
||||||
|
// Разделяем строку по дефису и берем первую часть (время начала)
|
||||||
|
let startTimeString = timeString.components(separatedBy: "-").first ?? ""
|
||||||
|
|
||||||
|
// Разделяем время на часы и минуты
|
||||||
|
let components = startTimeString.components(separatedBy: ":")
|
||||||
|
guard components.count == 2,
|
||||||
|
let hours = Int(components[0]),
|
||||||
|
let minutes = Int(components[1]) else {
|
||||||
|
return 0 // В случае ошибки возвращаем 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Преобразуем время в минуты с начала дня
|
||||||
|
return hours * 60 + minutes
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method for sorting classes by time
|
||||||
|
private func sortClassesByTime() {
|
||||||
|
// Проходим по каждому дню (подмассиву) в classesGroups
|
||||||
|
for dayIndex in 0..<classesGroups.count {
|
||||||
|
// Сортируем подмассив по времени начала пары
|
||||||
|
classesGroups[dayIndex].sort { class1, class2 in
|
||||||
|
let time1 = parseTime(class1.time) // Время начала первой пары
|
||||||
|
let time2 = parseTime(class2.time) // Время начала второй пары
|
||||||
|
return time1 < time2 // Сортируем по возрастанию
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateArrayOfGroups() {
|
||||||
|
self.nameGroups.removeAll()
|
||||||
|
self.numbersNTMLGroups.removeAll()
|
||||||
|
let group1 = UserDefaults.standard.string(forKey: "group")
|
||||||
|
let group2 = UserDefaults.standard.string(forKey: "group2")
|
||||||
|
let group3 = UserDefaults.standard.string(forKey: "group3")
|
||||||
|
if let nameGroup1 = group1, nameGroup1 != "" {
|
||||||
|
self.nameGroups.append(nameGroup1)
|
||||||
|
}
|
||||||
|
if let nameGroup2 = group2, nameGroup2 != "" {
|
||||||
|
self.nameGroups.append(nameGroup2)
|
||||||
|
}
|
||||||
|
if let nameGroup3 = group3, nameGroup3 != "" {
|
||||||
|
self.nameGroups.append(nameGroup3)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
36
Schedule ICTIS/ViewModel/SearchGroupsViewModel.swift
Normal file
36
Schedule ICTIS/ViewModel/SearchGroupsViewModel.swift
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
//
|
||||||
|
// SearchGroupsViewModel.swift
|
||||||
|
// Schedule ICTIS
|
||||||
|
//
|
||||||
|
// Created by G412 on 06.03.2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
final class SearchGroupsViewModel: ObservableObject {
|
||||||
|
@Published var groups: [Choice] = []
|
||||||
|
|
||||||
|
func fetchGroups(group: String) {
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
var groups: Welcome
|
||||||
|
groups = try await NetworkManager.shared.getGroups(group: group)
|
||||||
|
self.groups = groups.choices
|
||||||
|
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
if let error = error as? NetworkError {
|
||||||
|
switch (error) {
|
||||||
|
case .invalidData:
|
||||||
|
self.groups.removeAll()
|
||||||
|
default:
|
||||||
|
self.groups.removeAll()
|
||||||
|
print("Неизвестная ошибка: \(error)")
|
||||||
|
}
|
||||||
|
print("Есть ошибка: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user