This commit is contained in:
Vladimir Dubovik
2025-02-19 12:43:52 +03:00
parent 9f717d83df
commit bb268cc6ad
31 changed files with 335 additions and 95 deletions

View File

@ -2,7 +2,7 @@
// SelectedGroupView.swift
// Schedule ICTIS
//
// Created by G412 on 30.01.2025.
// Created by Mironov Egor on 30.01.2025.
//
import SwiftUI
@ -11,7 +11,9 @@ struct SelectingGroupView: View {
@Environment(\.dismiss) private var dismiss
@FocusState private var isFocused: Bool
@State private var text: String = ""
@Binding var group: String
@ObservedObject var vm: ScheduleViewModel
@State private var isLoading = false
@State private var searchTask: DispatchWorkItem?
var body: some View {
NavigationView {
VStack {
@ -23,14 +25,37 @@ struct SelectingGroupView: View {
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)
}
}
searchTask = task
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: task)
}
.onSubmit {
self.isFocused = false
if (!text.isEmpty) {
UserDefaults.standard.set(text, forKey: "group")
group = text
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
}
}
}
self.text = ""
dismiss()
}
.submitLabel(.done)
if isFocused {
@ -52,17 +77,45 @@ struct SelectingGroupView: View {
RoundedRectangle(cornerRadius: 15)
.fill(.white)
)
.padding(.horizontal, 10)
Spacer()
if isLoading {
LoadingView(isLoading: $isLoading)
}
if isFocused {
ScrollView(.vertical, showsIndicators: true) {
ForEach(vm.groups) { item in
VStack {
Rectangle()
.frame(height: 1)
.foregroundColor(Color("customGray1"))
.padding(.horizontal, 10)
HStack {
Text(item.name)
.foregroundColor(.black)
.font(.custom("Montserrat-SemiBold", size: 15))
Spacer()
}
.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: "group")
vm.group = item.name
vm.fetchWeekSchedule(group: item.name)
dismiss()
}
}
}
}
}
}
.padding(.horizontal, 10)
.background(Color("background"))
.onTapGesture {
self.isFocused = false
}
}
.onAppear {
vm.fetchGroups(group: "кт")
}
}
}
#Preview {
SelectingGroupView(group: .constant("КТбо2-6"))
}

View File

@ -2,14 +2,18 @@
// SelectedVPKView.swift
// Schedule ICTIS
//
// Created by G412 on 30.01.2025.
// Created by Mironov Egor on 30.01.2025.
//
import SwiftUI
struct SelectingVPKView: View {
@Environment(\.dismiss) private var dismiss
@FocusState private var isFocused: Bool
@State private var text: String = ""
@ObservedObject var vm: ScheduleViewModel
@State private var isLoading = false
@State private var searchTask: DispatchWorkItem?
var body: some View {
NavigationView {
VStack {
@ -21,12 +25,37 @@ struct SelectingVPKView: View {
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)
}
}
searchTask = task
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: task)
}
.onSubmit {
self.isFocused = false
if (!text.isEmpty) {
UserDefaults.standard.set(text, forKey: "group")
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: "vpk")
vm.group = text
self.text = ""
dismiss()
}
else {
vm.isShowingAlertForIncorrectGroup = true
vm.errorInNetwork = .invalidResponse
}
}
}
self.text = ""
}
.submitLabel(.done)
if isFocused {
@ -48,17 +77,45 @@ struct SelectingVPKView: View {
RoundedRectangle(cornerRadius: 15)
.fill(.white)
)
.padding(.horizontal, 10)
Spacer()
if isLoading {
LoadingView(isLoading: $isLoading)
}
if isFocused {
ScrollView(.vertical, showsIndicators: true) {
ForEach(vm.groups) { item in
VStack {
Rectangle()
.frame(height: 1)
.foregroundColor(Color("customGray1"))
.padding(.horizontal, 10)
HStack {
Text(item.name)
.foregroundColor(.black)
.font(.custom("Montserrat-SemiBold", size: 15))
Spacer()
}
.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.group = item.name
vm.fetchWeekSchedule(group: item.name)
dismiss()
}
}
}
}
}
}
.padding(.horizontal, 10)
.background(Color("background"))
.onTapGesture {
self.isFocused = false
}
}
.onAppear {
vm.fetchGroups(group: "впк")
}
}
}
#Preview {
SelectingVPKView()
}

View File

@ -2,7 +2,7 @@
// SettingsView.swift
// Schedule ICTIS
//
// Created by G412 on 30.01.2025.
// Created by Mironov Egor on 30.01.2025.
//
import SwiftUI
@ -11,6 +11,8 @@ struct SettingsView: View {
@ObservedObject var vm: ScheduleViewModel
@State private var selectedTheme = "Светлая"
@State private var selectedLanguage = "Русский"
@AppStorage("group") private var favGroup = ""
@AppStorage("vpk") private var favVPK = ""
var body: some View {
NavigationView {
VStack {
@ -28,17 +30,18 @@ struct SettingsView: View {
})
}
Section("Расписание") {
NavigationLink(destination: SelectingGroupView(group: $vm.group)) {
NavigationLink(destination: SelectingGroupView(vm: vm)) {
LabeledContent {
Text(vm.group)
Text(favGroup)
} label: {
Text("Избранное расписание")
}
}
NavigationLink(destination: SelectingVPKView()) {
NavigationLink(destination: SelectingVPKView(vm: vm)) {
LabeledContent {
Text(favVPK)
} label: {
Text("ВПК")
Text("Избранное ВПК")
}
}
}