Commit
This commit is contained in:
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
|
||||
|
||||
struct ScheduleGroupSettings: View {
|
||||
@AppStorage("group") private var favGroup = ""
|
||||
@AppStorage("vpk") private var favVPK = ""
|
||||
@ObservedObject var vm: ScheduleViewModel
|
||||
var body: some View {
|
||||
VStack {
|
||||
NavigationLink(destination: SelectingGroupView(vm: vm)) {
|
||||
NavigationLink(destination: FavGroupsView(vm: vm)) {
|
||||
HStack {
|
||||
Text("Избранное расписание")
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||
.foregroundColor(.black)
|
||||
Spacer()
|
||||
Text(favGroup)
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||
.foregroundColor(Color("customGray3"))
|
||||
Image("arrowRight")
|
||||
}
|
||||
.padding(.horizontal)
|
||||
@ -38,9 +33,6 @@ struct ScheduleGroupSettings: View {
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||
.foregroundColor(.black)
|
||||
Spacer()
|
||||
Text(favVPK)
|
||||
.font(.custom("Montserrat-Medium", fixedSize: 17))
|
||||
.foregroundColor(Color("customGray3"))
|
||||
Image("arrowRight")
|
||||
}
|
||||
.padding(.horizontal)
|
||||
|
@ -14,142 +14,132 @@ struct SelectingGroupView: View {
|
||||
@ObservedObject var vm: ScheduleViewModel
|
||||
@State private var isLoading = false
|
||||
@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 {
|
||||
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 {
|
||||
vm.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) {
|
||||
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 {
|
||||
vm.fetchGroups(group: "кт")
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
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(vm.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()
|
||||
}
|
||||
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 {
|
||||
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 firstFavGroup == "" {
|
||||
UserDefaults.standard.set(item.name, forKey: "group")
|
||||
vm.group = item.name
|
||||
vm.fetchWeekSchedule(group: item.name)
|
||||
dismiss()
|
||||
} else if secondFavGroup == "" {
|
||||
UserDefaults.standard.set(item.name, forKey: "group2")
|
||||
} 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 {
|
||||
vm.fetchGroups(group: "кт")
|
||||
serchGroupsVM.fetchGroups(group: "кт")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#Preview {
|
||||
@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
|
||||
@State private var isLoading = false
|
||||
@State private var searchTask: DispatchWorkItem?
|
||||
@StateObject private var serchGroupsVM = SearchGroupsViewModel()
|
||||
@AppStorage("vpk") private var favVPK = ""
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
@ -30,10 +31,10 @@ struct SelectingVPKView: View {
|
||||
searchTask?.cancel()
|
||||
let task = DispatchWorkItem {
|
||||
if !text.isEmpty {
|
||||
vm.fetchGroups(group: text)
|
||||
serchGroupsVM.fetchGroups(group: text)
|
||||
}
|
||||
else {
|
||||
vm.fetchGroups(group: "впк")
|
||||
serchGroupsVM.fetchGroups(group: "впк")
|
||||
}
|
||||
}
|
||||
searchTask = task
|
||||
@ -50,7 +51,7 @@ struct SelectingVPKView: View {
|
||||
vm.errorInNetwork = nil
|
||||
print("Зашел")
|
||||
UserDefaults.standard.set(text, forKey: "vpk")
|
||||
vm.group = text
|
||||
//vm.group = text
|
||||
self.text = ""
|
||||
dismiss()
|
||||
}
|
||||
@ -87,7 +88,7 @@ struct SelectingVPKView: View {
|
||||
}
|
||||
if isFocused {
|
||||
ScrollView(.vertical, showsIndicators: true) {
|
||||
ForEach(vm.groups) { item in
|
||||
ForEach(serchGroupsVM.groups) { item in
|
||||
if item.name.starts(with: "ВП") || item.name.starts(with: "мВ") {
|
||||
VStack {
|
||||
Rectangle()
|
||||
@ -145,7 +146,7 @@ struct SelectingVPKView: View {
|
||||
.background(Color("background"))
|
||||
}
|
||||
.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()
|
||||
}
|
Reference in New Issue
Block a user