Commit
This commit is contained in:
parent
5946cd3ec0
commit
8bc7425e2a
@ -36,20 +36,35 @@ struct ContentView: View {
|
||||
}
|
||||
.accentColor(Color("blueColor"))
|
||||
.onAppear {
|
||||
fillDictForVm()
|
||||
vm.fetchWeekSchedule()
|
||||
}
|
||||
}
|
||||
|
||||
func fillDictForVm() {
|
||||
let group1 = UserDefaults.standard.string(forKey: "group")
|
||||
let group2 = UserDefaults.standard.string(forKey: "group2")
|
||||
let group3 = UserDefaults.standard.string(forKey: "group3")
|
||||
let vpk1 = UserDefaults.standard.string(forKey: "vpk1")
|
||||
let vpk2 = UserDefaults.standard.string(forKey: "vpk2")
|
||||
let vpk3 = UserDefaults.standard.string(forKey: "vpk3")
|
||||
if let nameGroup1 = group1, nameGroup1 != "" {
|
||||
vm.nameGroups.append(nameGroup1)
|
||||
vm.nameToHtml[nameGroup1] = ""
|
||||
}
|
||||
if let nameGroup2 = group2, nameGroup2 != "" {
|
||||
vm.nameGroups.append(nameGroup2)
|
||||
vm.nameToHtml[nameGroup2] = ""
|
||||
}
|
||||
if let nameGroup3 = group3, nameGroup3 != "" {
|
||||
vm.nameGroups.append(nameGroup3)
|
||||
vm.nameToHtml[nameGroup3] = ""
|
||||
}
|
||||
print("\(group1) - \(group2) - \(group3)")
|
||||
vm.fetchWeekSchedule()
|
||||
if let nameVpk1 = vpk1, nameVpk1 != "" {
|
||||
vm.nameToHtml[nameVpk1] = ""
|
||||
}
|
||||
if let nameVpk2 = vpk2, nameVpk2 != "" {
|
||||
vm.nameToHtml[nameVpk2] = ""
|
||||
}
|
||||
if let nameVpk3 = vpk3, nameVpk3 != "" {
|
||||
vm.nameToHtml[nameVpk3] = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,6 @@ struct ScheduleView: View {
|
||||
@State private var isShowingMyPairs = false
|
||||
@Binding var isScrolling: Bool
|
||||
var provider = ClassProvider.shared
|
||||
var hasVPK: Bool {
|
||||
return vm.vpks.indices.contains(vm.selectedIndex) && vm.vpks[vm.selectedIndex].dropFirst().contains { !$0.isEmpty }
|
||||
}
|
||||
var body: some View {
|
||||
if vm.isLoading {
|
||||
LoadingScheduleView()
|
||||
|
@ -29,8 +29,10 @@ struct SearchBarView: View {
|
||||
.onSubmit {
|
||||
self.isFocused = false
|
||||
if (!text.isEmpty) {
|
||||
vm.nameToHtml[vm.searchingGroup] = nil
|
||||
vm.removeFromSchedule(group: vm.searchingGroup)
|
||||
vm.searchingGroup = text
|
||||
vm.updateArrayOfGroups()
|
||||
vm.nameToHtml[text] = ""
|
||||
vm.fetchWeekSchedule()
|
||||
}
|
||||
self.text = ""
|
||||
|
@ -25,9 +25,8 @@ struct FavGroupsView: View {
|
||||
.cornerRadius(10)
|
||||
.swipeActions(edge: .trailing) {
|
||||
Button(role: .destructive) {
|
||||
vm.removeFromSchedule(group: firstFavGroup)
|
||||
UserDefaults.standard.set("", forKey: "group")
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
} label: {
|
||||
Label("Удалить", systemImage: "trash")
|
||||
}
|
||||
@ -43,9 +42,8 @@ struct FavGroupsView: View {
|
||||
.cornerRadius(10)
|
||||
.swipeActions(edge: .trailing) {
|
||||
Button(role: .destructive) {
|
||||
vm.removeFromSchedule(group: secondFavGroup)
|
||||
UserDefaults.standard.set("", forKey: "group2")
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
} label: {
|
||||
Label("Удалить", systemImage: "trash")
|
||||
}
|
||||
@ -61,9 +59,8 @@ struct FavGroupsView: View {
|
||||
.cornerRadius(10)
|
||||
.swipeActions(edge: .trailing) {
|
||||
Button(role: .destructive) {
|
||||
vm.removeFromSchedule(group: thirdFavGroup)
|
||||
UserDefaults.standard.set("", forKey: "group3")
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
} label: {
|
||||
Label("Удалить", systemImage: "trash")
|
||||
}
|
||||
|
@ -25,9 +25,8 @@ struct FavVPKView: View {
|
||||
.cornerRadius(10)
|
||||
.swipeActions(edge: .trailing) {
|
||||
Button(role: .destructive) {
|
||||
vm.removeFromSchedule(group: firstFavVPK)
|
||||
UserDefaults.standard.set("", forKey: "vpk1")
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
} label: {
|
||||
Label("Удалить", systemImage: "trash")
|
||||
}
|
||||
@ -43,9 +42,8 @@ struct FavVPKView: View {
|
||||
.cornerRadius(10)
|
||||
.swipeActions(edge: .trailing) {
|
||||
Button(role: .destructive) {
|
||||
vm.removeFromSchedule(group: secondFavVPK)
|
||||
UserDefaults.standard.set("", forKey: "vpk2")
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
} label: {
|
||||
Label("Удалить", systemImage: "trash")
|
||||
}
|
||||
@ -61,9 +59,8 @@ struct FavVPKView: View {
|
||||
.cornerRadius(10)
|
||||
.swipeActions(edge: .trailing) {
|
||||
Button(role: .destructive) {
|
||||
vm.removeFromSchedule(group: thirdFavVPK)
|
||||
UserDefaults.standard.set("", forKey: "vpk3")
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
} label: {
|
||||
Label("Удалить", systemImage: "trash")
|
||||
}
|
||||
|
54
Schedule ICTIS/Settings/ListOfGroupsView.swift
Normal file
54
Schedule ICTIS/Settings/ListOfGroupsView.swift
Normal file
@ -0,0 +1,54 @@
|
||||
//
|
||||
// ListOfGroupsView.swift
|
||||
// Schedule ICTIS
|
||||
//
|
||||
// Created by G412 on 13.03.2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ListOfGroupsView: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@ObservedObject var vm: ScheduleViewModel
|
||||
@ObservedObject var serchGroupsVM: SearchGroupsViewModel
|
||||
var firstFavVPK: String
|
||||
var secondFavVPK: String
|
||||
var thirdFavVPK: String
|
||||
var body: some View {
|
||||
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)
|
||||
HStack {
|
||||
Text(item.name)
|
||||
.foregroundColor(.black)
|
||||
.font(.custom("Montserrat-SemiBold", fixedSize: 15))
|
||||
Spacer()
|
||||
}
|
||||
.padding(.horizontal, 10)
|
||||
.padding(.top, 2)
|
||||
.padding(.bottom, 2)
|
||||
.frame(width: UIScreen.main.bounds.width, height: 30)
|
||||
.background(Color("background"))
|
||||
.onTapGesture {
|
||||
if firstFavVPK == "" {
|
||||
UserDefaults.standard.set(item.name, forKey: "vpk1")
|
||||
} else if secondFavVPK == "" {
|
||||
UserDefaults.standard.set(item.name, forKey: "vpk2")
|
||||
} else {
|
||||
UserDefaults.standard.set(item.name, forKey: "vpk3")
|
||||
}
|
||||
vm.nameToHtml[item.name] = ""
|
||||
vm.fetchWeekSchedule()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -51,12 +51,14 @@ struct SelectingGroupView: View {
|
||||
vm.errorInNetwork = nil
|
||||
if firstFavGroup == "" {
|
||||
UserDefaults.standard.set(text, forKey: "group")
|
||||
vm.nameToHtml[text] = ""
|
||||
} else if secondFavGroup == "" {
|
||||
UserDefaults.standard.set(text, forKey: "group2")
|
||||
vm.nameToHtml[text] = ""
|
||||
} else {
|
||||
UserDefaults.standard.set(text, forKey: "group3")
|
||||
vm.nameToHtml[text] = ""
|
||||
}
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
self.isLoading = false
|
||||
self.text = ""
|
||||
@ -116,12 +118,14 @@ struct SelectingGroupView: View {
|
||||
.onTapGesture {
|
||||
if firstFavGroup == "" {
|
||||
UserDefaults.standard.set(item.name, forKey: "group")
|
||||
vm.nameToHtml[item.name] = ""
|
||||
} else if secondFavGroup == "" {
|
||||
UserDefaults.standard.set(item.name, forKey: "group2")
|
||||
vm.nameToHtml[item.name] = ""
|
||||
} else {
|
||||
UserDefaults.standard.set(item.name, forKey: "group3")
|
||||
vm.nameToHtml[item.name] = ""
|
||||
}
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
dismiss()
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ struct SelectingVPKView: View {
|
||||
} else {
|
||||
UserDefaults.standard.set(text, forKey: "vpk3")
|
||||
}
|
||||
vm.updateArrayOfGroups()
|
||||
vm.nameToHtml[text] = ""
|
||||
vm.fetchWeekSchedule()
|
||||
self.isLoading = false
|
||||
self.text = ""
|
||||
@ -95,41 +95,7 @@ struct SelectingVPKView: View {
|
||||
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)
|
||||
HStack {
|
||||
Text(item.name)
|
||||
.foregroundColor(.black)
|
||||
.font(.custom("Montserrat-SemiBold", fixedSize: 15))
|
||||
Spacer()
|
||||
}
|
||||
.padding(.horizontal, 10)
|
||||
.padding(.top, 2)
|
||||
.padding(.bottom, 2)
|
||||
.frame(width: UIScreen.main.bounds.width, height: 30)
|
||||
.background(Color("background"))
|
||||
.onTapGesture {
|
||||
if firstFavVPK == "" {
|
||||
UserDefaults.standard.set(item.name, forKey: "vpk1")
|
||||
} else if secondFavVPK == "" {
|
||||
UserDefaults.standard.set(item.name, forKey: "vpk2")
|
||||
} else {
|
||||
UserDefaults.standard.set(item.name, forKey: "vpk3")
|
||||
}
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ListOfGroupsView(vm: vm, serchGroupsVM: serchGroupsVM, firstFavVPK: firstFavVPK, secondFavVPK: secondFavVPK, thirdFavVPK: thirdFavVPK)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 10)
|
||||
|
@ -183,11 +183,12 @@ extension WeekTabView {
|
||||
extension WeekViewForWeek {
|
||||
func paginateWeek() {
|
||||
let calendar = Calendar.current
|
||||
let groupsKeys = Array (vm.nameToHtml.keys)
|
||||
if weekSlider.indices.contains(currentWeekIndex) {
|
||||
if let firstDate = weekSlider[currentWeekIndex].first?.date,
|
||||
currentWeekIndex == 0 {
|
||||
vm.week -= 1
|
||||
if !vm.nameGroups.isEmpty {
|
||||
if !groupsKeys.isEmpty {
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
if UserDefaults.standard.string(forKey: "vpk") != nil {
|
||||
@ -203,7 +204,7 @@ extension WeekViewForWeek {
|
||||
if let lastDate = weekSlider[currentWeekIndex].last?.date,
|
||||
currentWeekIndex == (weekSlider.count - 1) {
|
||||
vm.week += 1
|
||||
if !vm.nameGroups.isEmpty {
|
||||
if !groupsKeys.isEmpty {
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
weekSlider.append(lastDate.createNextWeek())
|
||||
@ -243,13 +244,14 @@ extension WeekViewForMonth {
|
||||
print("На одной неделе")
|
||||
}
|
||||
else {
|
||||
let groupsKeys = Array(vm.nameToHtml.keys)
|
||||
var difBetweenWeeks = weeksBetween(startDate: vm.selectedDay, endDate: day.date)
|
||||
if day.date < vm.selectedDay {
|
||||
difBetweenWeeks = difBetweenWeeks * -1
|
||||
}
|
||||
print(difBetweenWeeks)
|
||||
vm.week += difBetweenWeeks
|
||||
if !vm.nameGroups.isEmpty {
|
||||
if !groupsKeys.isEmpty {
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
if UserDefaults.standard.string(forKey: "vpk") != nil {
|
||||
@ -281,6 +283,7 @@ extension MonthTabView {
|
||||
|
||||
func paginateMonth(_ indexOfWeek: Int = 0) {
|
||||
let calendar = Calendar.current
|
||||
let groupsKeys = Array (vm.nameToHtml.keys)
|
||||
if monthSlider.indices.contains(currentMonthIndex) {
|
||||
if let firstDate = monthSlider[currentMonthIndex].first?.week[0].date,
|
||||
currentMonthIndex == 0 {
|
||||
@ -290,7 +293,7 @@ extension MonthTabView {
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -5, to: vm.selectedDay) ?? Date.init()
|
||||
vm.updateSelectedDayIndex()
|
||||
vm.week -= 5
|
||||
if !vm.nameGroups.isEmpty {
|
||||
if !groupsKeys.isEmpty {
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
}
|
||||
@ -303,7 +306,7 @@ extension MonthTabView {
|
||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 5, to: vm.selectedDay) ?? Date.init()
|
||||
vm.updateSelectedDayIndex()
|
||||
vm.week += 5
|
||||
if !vm.nameGroups.isEmpty {
|
||||
if !groupsKeys.isEmpty {
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,7 @@ import SwiftUICore
|
||||
@MainActor
|
||||
final class ScheduleViewModel: ObservableObject {
|
||||
//MARK: Properties
|
||||
@Published var nameGroups: [String] = []
|
||||
@Published var numbersNTMLGroups: [String] = []
|
||||
@Published var nameToHtml: [String : String] = [:]
|
||||
@Published var classesGroups: [[ClassInfo]] = []
|
||||
@Published var searchingGroup = ""
|
||||
|
||||
@ -44,7 +43,8 @@ final class ScheduleViewModel: ObservableObject {
|
||||
|
||||
// Если другая неделя, запрашиваем расписание по неделе и номеру группу(в HTML формате)
|
||||
if isOtherWeek {
|
||||
for groupHTML in numbersNTMLGroups {
|
||||
let groupHTMLs = Array(self.nameToHtml.values)
|
||||
for groupHTML in groupHTMLs {
|
||||
let schedule = try await NetworkManager.shared.getScheduleForOtherWeek(self.week, groupHTML)
|
||||
let table = schedule.table.table
|
||||
let nameOfGroup = schedule.table.name
|
||||
@ -61,10 +61,11 @@ final class ScheduleViewModel: ObservableObject {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for groupName in nameGroups {
|
||||
let groupNames = Array(self.nameToHtml.keys)
|
||||
for groupName in groupNames {
|
||||
let schedule = try await NetworkManager.shared.getSchedule(groupName)
|
||||
let numberHTML = schedule.table.group
|
||||
self.numbersNTMLGroups.append(numberHTML)
|
||||
self.nameToHtml[groupName] = numberHTML
|
||||
let table = schedule.table.table
|
||||
self.week = schedule.table.week
|
||||
|
||||
@ -156,33 +157,19 @@ final class ScheduleViewModel: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
let vpk1 = UserDefaults.standard.string(forKey: "vpk1")
|
||||
let vpk2 = UserDefaults.standard.string(forKey: "vpk2")
|
||||
let vpk3 = UserDefaults.standard.string(forKey: "vpk3")
|
||||
if let nameGroup1 = group1, nameGroup1 != "" {
|
||||
self.nameGroups.append(nameGroup1)
|
||||
func removeFromSchedule(group: String) {
|
||||
self.nameToHtml[group] = nil
|
||||
|
||||
for i in classesGroups.indices {
|
||||
// Сначала находим индексы элементов для удаления
|
||||
let indicesToRemove = classesGroups[i].indices.filter { j in
|
||||
classesGroups[i][j].group.lowercased() == group.lowercased()
|
||||
}
|
||||
if let nameGroup2 = group2, nameGroup2 != "" {
|
||||
self.nameGroups.append(nameGroup2)
|
||||
|
||||
// Удаляем элементы в обратном порядке, чтобы индексы оставались корректными
|
||||
for j in indicesToRemove.reversed() {
|
||||
classesGroups[i].remove(at: j)
|
||||
}
|
||||
if let nameGroup3 = group3, nameGroup3 != "" {
|
||||
self.nameGroups.append(nameGroup3)
|
||||
}
|
||||
if let nameVPK1 = vpk1, nameVPK1 != "" {
|
||||
self.nameGroups.append(nameVPK1)
|
||||
}
|
||||
if let nameVPK2 = vpk2, nameVPK2 != "" {
|
||||
self.nameGroups.append(nameVPK2)
|
||||
}
|
||||
if let nameVPK3 = vpk3, nameVPK3 != "" {
|
||||
self.nameGroups.append(nameVPK3)
|
||||
}
|
||||
self.nameGroups.append(self.searchingGroup)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user