Commit
This commit is contained in:
parent
15fbe5895c
commit
9bfd85ec3d
@ -50,9 +50,6 @@ struct ContentView: View {
|
||||
}
|
||||
print("\(group1) - \(group2) - \(group3)")
|
||||
vm.fetchWeekSchedule()
|
||||
if let vpkStr = UserDefaults.standard.string(forKey: "vpk") {
|
||||
vm.fetchWeekVPK(vpk: vpkStr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ struct FavGroupsView: View {
|
||||
var secondFavGroup = (UserDefaults.standard.string(forKey: "group2") ?? "")
|
||||
var thirdFavGroup = (UserDefaults.standard.string(forKey: "group3") ?? "")
|
||||
var body: some View {
|
||||
VStack {
|
||||
VStack (spacing: 0) {
|
||||
List {
|
||||
if firstFavGroup != "" {
|
||||
HStack {
|
||||
@ -70,20 +70,27 @@ struct FavGroupsView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
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)
|
||||
.frame(maxHeight: 400)
|
||||
|
||||
Spacer()
|
||||
|
||||
HStack {
|
||||
Spacer()
|
||||
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: 12, leading: 12, bottom: 12, trailing: 12))
|
||||
}
|
||||
.background(Color("blueColor"))
|
||||
.cornerRadius(10)
|
||||
.padding(.trailing, 20)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.bottom, 50)
|
||||
}
|
||||
.background(Color("background"))
|
||||
}
|
||||
|
102
Schedule ICTIS/Settings/FavVPKView.swift
Normal file
102
Schedule ICTIS/Settings/FavVPKView.swift
Normal file
@ -0,0 +1,102 @@
|
||||
//
|
||||
// FavGroupsView.swift
|
||||
// Schedule ICTIS
|
||||
//
|
||||
// Created by G412 on 05.03.2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct FavVPKView: View {
|
||||
@ObservedObject var vm: ScheduleViewModel
|
||||
var firstFavVPK = (UserDefaults.standard.string(forKey: "vpk1") ?? "")
|
||||
var secondFavVPK = (UserDefaults.standard.string(forKey: "vpk2") ?? "")
|
||||
var thirdFavVPK = (UserDefaults.standard.string(forKey: "vpk3") ?? "")
|
||||
var body: some View {
|
||||
VStack (spacing: 0) {
|
||||
List {
|
||||
if firstFavVPK != "" {
|
||||
HStack {
|
||||
Text(firstFavVPK)
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||
Spacer()
|
||||
}
|
||||
.background(Color.white)
|
||||
.cornerRadius(10)
|
||||
.swipeActions(edge: .trailing) {
|
||||
Button(role: .destructive) {
|
||||
UserDefaults.standard.set("", forKey: "vpk1")
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
} label: {
|
||||
Label("Удалить", systemImage: "trash")
|
||||
}
|
||||
}
|
||||
}
|
||||
if secondFavVPK != "" {
|
||||
HStack {
|
||||
Text(secondFavVPK)
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||
Spacer()
|
||||
}
|
||||
.background(Color.white)
|
||||
.cornerRadius(10)
|
||||
.swipeActions(edge: .trailing) {
|
||||
Button(role: .destructive) {
|
||||
UserDefaults.standard.set("", forKey: "vpk2")
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
} label: {
|
||||
Label("Удалить", systemImage: "trash")
|
||||
}
|
||||
}
|
||||
}
|
||||
if thirdFavVPK != "" {
|
||||
HStack {
|
||||
Text(thirdFavVPK)
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||
Spacer()
|
||||
}
|
||||
.background(Color.white)
|
||||
.cornerRadius(10)
|
||||
.swipeActions(edge: .trailing) {
|
||||
Button(role: .destructive) {
|
||||
UserDefaults.standard.set("", forKey: "vpk3")
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
} label: {
|
||||
Label("Удалить", systemImage: "trash")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(maxHeight: 400)
|
||||
|
||||
Spacer()
|
||||
|
||||
HStack {
|
||||
Spacer()
|
||||
if firstFavVPK == "" || secondFavVPK == "" || thirdFavVPK == "" {
|
||||
NavigationLink(destination: SelectingVPKView(vm: vm, firstFavVPK: firstFavVPK, secondFavVPK: secondFavVPK, thirdFavVPK: thirdFavVPK)) {
|
||||
HStack {
|
||||
Image(systemName: "plus")
|
||||
.foregroundColor(.white)
|
||||
.font(.system(size: 22))
|
||||
.padding(EdgeInsets(top: 12, leading: 12, bottom: 12, trailing: 12))
|
||||
}
|
||||
.background(Color("blueColor"))
|
||||
.cornerRadius(10)
|
||||
.padding(.trailing, 20)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.bottom, 50)
|
||||
}
|
||||
.background(Color("background"))
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
@Previewable @StateObject var vm = ScheduleViewModel()
|
||||
FavVPKView(vm: vm)
|
||||
}
|
@ -27,7 +27,7 @@ struct ScheduleGroupSettings: View {
|
||||
.foregroundColor(Color("customGray1"))
|
||||
.frame(height: 1)
|
||||
.padding(.horizontal)
|
||||
NavigationLink(destination: SelectingVPKView(vm: vm)) {
|
||||
NavigationLink(destination: FavVPKView(vm: vm)) {
|
||||
HStack {
|
||||
Text("ВПК")
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||
|
@ -47,10 +47,8 @@ struct SelectingGroupView: View {
|
||||
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 == "" {
|
||||
@ -58,7 +56,9 @@ struct SelectingGroupView: View {
|
||||
} else {
|
||||
UserDefaults.standard.set(text, forKey: "group3")
|
||||
}
|
||||
vm.nameGroups.append(text)
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
self.isLoading = false
|
||||
self.text = ""
|
||||
dismiss()
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// SelectedVPKView.swift
|
||||
// SelectedGroupView.swift
|
||||
// Schedule ICTIS
|
||||
//
|
||||
// Created by Mironov Egor on 30.01.2025.
|
||||
@ -15,143 +15,132 @@ struct SelectingVPKView: View {
|
||||
@State private var isLoading = false
|
||||
@State private var searchTask: DispatchWorkItem?
|
||||
@StateObject private var serchGroupsVM = SearchGroupsViewModel()
|
||||
@AppStorage("vpk") private var favVPK = ""
|
||||
var firstFavVPK: String
|
||||
var secondFavVPK: String
|
||||
var thirdFavVPK: String
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
VStack {
|
||||
HStack (spacing: 0) {
|
||||
Image(systemName: "magnifyingglass")
|
||||
.foregroundColor(Color.gray)
|
||||
.padding(.leading, 12)
|
||||
.padding(.trailing, 7)
|
||||
TextField("Поиск ВПК", text: $text)
|
||||
.disableAutocorrection(true)
|
||||
.focused($isFocused)
|
||||
.onChange(of: text) { oldValue, newValue in
|
||||
searchTask?.cancel()
|
||||
let task = DispatchWorkItem {
|
||||
if !text.isEmpty {
|
||||
serchGroupsVM.fetchGroups(group: text)
|
||||
VStack {
|
||||
HStack (spacing: 0) {
|
||||
Image(systemName: "magnifyingglass")
|
||||
.foregroundColor(Color.gray)
|
||||
.padding(.leading, 12)
|
||||
.padding(.trailing, 7)
|
||||
TextField("Поиск ВПК", text: $text)
|
||||
.disableAutocorrection(true)
|
||||
.focused($isFocused)
|
||||
.onChange(of: text) { oldValue, newValue in
|
||||
searchTask?.cancel()
|
||||
let task = DispatchWorkItem {
|
||||
if !text.isEmpty {
|
||||
serchGroupsVM.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) {
|
||||
if vm.errorInNetwork == .noError {
|
||||
vm.errorInNetwork = nil
|
||||
if firstFavVPK == "" {
|
||||
UserDefaults.standard.set(text, forKey: "vpk1")
|
||||
} else if secondFavVPK == "" {
|
||||
UserDefaults.standard.set(text, forKey: "vpk2")
|
||||
} else {
|
||||
UserDefaults.standard.set(text, forKey: "vpk3")
|
||||
}
|
||||
vm.updateArrayOfGroups()
|
||||
vm.fetchWeekSchedule()
|
||||
self.isLoading = false
|
||||
self.text = ""
|
||||
print("✅ - Избранный ВПК был установлен")
|
||||
dismiss()
|
||||
}
|
||||
else {
|
||||
serchGroupsVM.fetchGroups(group: "впк")
|
||||
}
|
||||
}
|
||||
searchTask = task
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: task)
|
||||
}
|
||||
.onSubmit {
|
||||
self.isFocused = false
|
||||
if (!text.isEmpty) {
|
||||
vm.fetchWeekVPK(vpk: UserDefaults.standard.string(forKey: "vpk"))
|
||||
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: "vpk")
|
||||
//vm.group = text
|
||||
self.text = ""
|
||||
dismiss()
|
||||
}
|
||||
else {
|
||||
vm.isShowingAlertForIncorrectGroup = true
|
||||
vm.errorInNetwork = .invalidResponse
|
||||
}
|
||||
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(
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(height: 40)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 15)
|
||||
.fill(.white)
|
||||
)
|
||||
Spacer()
|
||||
if isLoading {
|
||||
LoadingView(isLoading: $isLoading)
|
||||
}
|
||||
.submitLabel(.done)
|
||||
if isFocused {
|
||||
ScrollView(.vertical, showsIndicators: true) {
|
||||
ForEach(serchGroupsVM.groups) { item in
|
||||
if item.name.starts(with: "ВП") || 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()
|
||||
}
|
||||
Button {
|
||||
self.text = ""
|
||||
self.isFocused = false
|
||||
} label: {
|
||||
Image(systemName: "xmark.circle.fill")
|
||||
.padding(.trailing, 20)
|
||||
.offset(x: 10)
|
||||
.foregroundColor(.gray)
|
||||
.background(
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
.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(.top, 2)
|
||||
.padding(.bottom, 2)
|
||||
.frame(width: UIScreen.main.bounds.width, height: 30)
|
||||
.background(Color("background"))
|
||||
.onTapGesture {
|
||||
UserDefaults.standard.set(item.name, forKey: "vpk")
|
||||
vm.vpk = item.name
|
||||
vm.fetchWeekVPK(vpk: item.name)
|
||||
dismiss()
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !isFocused {
|
||||
if favVPK != "" {
|
||||
Button {
|
||||
UserDefaults.standard.removeObject(forKey: "vpk")
|
||||
vm.vpks.removeAll()
|
||||
vm.vpk = ""
|
||||
vm.vpkHTML = ""
|
||||
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 {
|
||||
serchGroupsVM.fetchGroups(group: "впк")
|
||||
serchGroupsVM.fetchGroups(group: "ВПК")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#Preview {
|
||||
@Previewable @StateObject var vm = ScheduleViewModel()
|
||||
SelectingVPKView(vm: vm)
|
||||
SelectingVPKView(vm: vm, firstFavVPK: "", secondFavVPK: "", thirdFavVPK: "")
|
||||
}
|
||||
|
@ -206,9 +206,6 @@ extension WeekViewForWeek {
|
||||
if !vm.nameGroups.isEmpty {
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
if UserDefaults.standard.string(forKey: "vpk") != nil {
|
||||
vm.fetchWeekVPK(isOtherWeek: true, vpk: UserDefaults.standard.string(forKey: "vpk"))
|
||||
}
|
||||
weekSlider.append(lastDate.createNextWeek())
|
||||
weekSlider.removeFirst()
|
||||
currentWeekIndex = weekSlider.count - 2
|
||||
@ -296,9 +293,6 @@ extension MonthTabView {
|
||||
if !vm.nameGroups.isEmpty {
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
if let vpkStr = UserDefaults.standard.string(forKey: "vpk") {
|
||||
vm.fetchWeekVPK(vpk: vpkStr)
|
||||
}
|
||||
}
|
||||
|
||||
if let lastDate = monthSlider[currentMonthIndex].last?.week[6].date,
|
||||
@ -312,9 +306,6 @@ extension MonthTabView {
|
||||
if !vm.nameGroups.isEmpty {
|
||||
vm.fetchWeekSchedule(isOtherWeek: true)
|
||||
}
|
||||
if let vpkStr = UserDefaults.standard.string(forKey: "vpk") {
|
||||
vm.fetchWeekVPK(vpk: vpkStr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,6 @@ final class ScheduleViewModel: ObservableObject {
|
||||
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
|
||||
@ -123,47 +122,6 @@ final class ScheduleViewModel: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
func fetchWeekVPK(isOtherWeek: Bool = false, vpk: String? = "default") {
|
||||
isLoading = true
|
||||
Task {
|
||||
do {
|
||||
var tempVPKS: Schedule
|
||||
// В этот if мы заходим только если пользователь перелистывает недели и нам известы номер ВПК(в html формате) и номер недели, которая показывается пользователю
|
||||
if isOtherWeek && vpk != nil {
|
||||
tempVPKS = try await NetworkManager.shared.getScheduleForOtherWeek(self.week, self.vpkHTML)
|
||||
}
|
||||
// В else мы заходим в том случае, если не знаем номер недели, которую нужно отобразить и номер группы(в html формате)
|
||||
else {
|
||||
tempVPKS = try await NetworkManager.shared.getSchedule(vpk!)
|
||||
self.vpk = vpk!
|
||||
self.selectedDay = .init()
|
||||
}
|
||||
self.weekScheduleVPK = tempVPKS.table
|
||||
self.vpkHTML = weekScheduleVPK.group
|
||||
self.vpks = weekScheduleVPK.table
|
||||
print(self.vpk)
|
||||
self.isShowingAlertForIncorrectGroup = false
|
||||
self.isLoading = false
|
||||
self.errorInNetwork = .noError
|
||||
}
|
||||
catch {
|
||||
if let error = error as? NetworkError {
|
||||
switch (error) {
|
||||
case .invalidResponse:
|
||||
errorInNetwork = .invalidResponse
|
||||
case .invalidData:
|
||||
errorInNetwork = .invalidData
|
||||
self.isShowingAlertForIncorrectGroup = true
|
||||
default:
|
||||
print("Неизвестная ошибка: \(error)")
|
||||
}
|
||||
isLoading = false
|
||||
print("Есть ошибка: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func updateSelectedDayIndex() {
|
||||
switch selectedDay.format("E") {
|
||||
case "Пн":
|
||||
@ -218,6 +176,9 @@ final class ScheduleViewModel: ObservableObject {
|
||||
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)
|
||||
}
|
||||
@ -227,5 +188,14 @@ final class ScheduleViewModel: ObservableObject {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user