Commit
This commit is contained in:
parent
1de531abc8
commit
92b125927d
@ -11,6 +11,7 @@ struct MonthTabView: View {
|
|||||||
@State private var currentMonthIndex: Int = 1
|
@State private var currentMonthIndex: Int = 1
|
||||||
@State private var monthSlider: [[Date.MonthWeek]] = []
|
@State private var monthSlider: [[Date.MonthWeek]] = []
|
||||||
@State private var createMonth: Bool = false
|
@State private var createMonth: Bool = false
|
||||||
|
@State private var currentWeekIndex: Int = 0
|
||||||
@ObservedObject var vm: ViewModel
|
@ObservedObject var vm: ViewModel
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
@ -139,7 +140,7 @@ struct MonthTabView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func paginateMonth() {
|
func paginateMonth(_ indexOfWeek: Int = 0) {
|
||||||
let calendar = Calendar.current
|
let calendar = Calendar.current
|
||||||
if monthSlider.indices.contains(currentMonthIndex) {
|
if monthSlider.indices.contains(currentMonthIndex) {
|
||||||
if let firstDate = monthSlider[currentMonthIndex].first?.week[0].date,
|
if let firstDate = monthSlider[currentMonthIndex].first?.week[0].date,
|
||||||
|
@ -15,7 +15,7 @@ struct LoadingView: View {
|
|||||||
.ignoresSafeArea()
|
.ignoresSafeArea()
|
||||||
ProgressView()
|
ProgressView()
|
||||||
.progressViewStyle(CircularProgressViewStyle(tint: .secondary))
|
.progressViewStyle(CircularProgressViewStyle(tint: .secondary))
|
||||||
.scaleEffect(1.5)
|
.scaleEffect(1.2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,6 +16,7 @@ struct MainView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
SearchBarView(text: $searchText, vm: vm)
|
SearchBarView(text: $searchText, vm: vm)
|
||||||
|
|
||||||
if (vm.isFirstStartOffApp && vm.isLoading) {
|
if (vm.isFirstStartOffApp && vm.isLoading) {
|
||||||
LoadingView(isLoading: $vm.isLoading)
|
LoadingView(isLoading: $vm.isLoading)
|
||||||
}
|
}
|
23
Schedule ICTIS/Main/Views/NoScheduleView.swift
Normal file
23
Schedule ICTIS/Main/Views/NoScheduleView.swift
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
//
|
||||||
|
// NoScheduleView.swift
|
||||||
|
// Schedule ICTIS
|
||||||
|
//
|
||||||
|
// Created by G412 on 12.12.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct NoScheduleView: View {
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
ScrollView (showsIndicators: false) {
|
||||||
|
Text("Пока расписания нет")
|
||||||
|
.padding(.top, 20)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
NoScheduleView()
|
||||||
|
}
|
@ -14,6 +14,7 @@ struct ScheduleView: View {
|
|||||||
LoadingView(isLoading: $vm.isLoading)
|
LoadingView(isLoading: $vm.isLoading)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if vm.errorInNetwork != .invalidResponse {
|
||||||
ZStack (alignment: .top) {
|
ZStack (alignment: .top) {
|
||||||
ScrollView(.vertical, showsIndicators: false) {
|
ScrollView(.vertical, showsIndicators: false) {
|
||||||
VStack (spacing: 20) {
|
VStack (spacing: 20) {
|
||||||
@ -57,11 +58,15 @@ struct ScheduleView: View {
|
|||||||
.frame(width: UIScreen.main.bounds.width)
|
.frame(width: UIScreen.main.bounds.width)
|
||||||
.padding(.bottom, 100)
|
.padding(.bottom, 100)
|
||||||
.padding(.top, 30)
|
.padding(.top, 30)
|
||||||
}
|
}
|
||||||
VStack {
|
VStack {
|
||||||
LinearGradient(gradient: Gradient(colors: [Color("background").opacity(0.9), Color("background").opacity(0.89)]), startPoint: .top, endPoint: .bottom)
|
LinearGradient(gradient: Gradient(colors: [Color("background").opacity(0.95), Color.white.opacity(0.1)]), startPoint: .top, endPoint: .bottom)
|
||||||
}
|
}
|
||||||
.frame(width: UIScreen.main.bounds.width, height: 15)
|
.frame(width: UIScreen.main.bounds.width, height: 15)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
NoScheduleView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -28,6 +28,7 @@ struct SearchBarView: View {
|
|||||||
self.isEditing = false
|
self.isEditing = false
|
||||||
if (!text.isEmpty) {
|
if (!text.isEmpty) {
|
||||||
vm.fetchWeekSchedule(text)
|
vm.fetchWeekSchedule(text)
|
||||||
|
vm.group = text
|
||||||
}
|
}
|
||||||
self.text = ""
|
self.text = ""
|
||||||
}
|
}
|
@ -12,6 +12,7 @@ enum NetworkError: String, Error, LocalizedError {
|
|||||||
case invalidResponse
|
case invalidResponse
|
||||||
case invalidData
|
case invalidData
|
||||||
case noNetwork
|
case noNetwork
|
||||||
|
case noError
|
||||||
|
|
||||||
var errorDescription: String? {
|
var errorDescription: String? {
|
||||||
switch self {
|
switch self {
|
||||||
@ -23,6 +24,8 @@ enum NetworkError: String, Error, LocalizedError {
|
|||||||
"Проверьте номер группы"
|
"Проверьте номер группы"
|
||||||
case .noNetwork:
|
case .noNetwork:
|
||||||
"No network connection"
|
"No network connection"
|
||||||
|
case .noError:
|
||||||
|
"Нет ошибки"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,6 +39,8 @@ enum NetworkError: String, Error, LocalizedError {
|
|||||||
"Похоже такой группы не существует"
|
"Похоже такой группы не существует"
|
||||||
case .noNetwork:
|
case .noNetwork:
|
||||||
"Проверьте подключение к интернету и попробуйте заново"
|
"Проверьте подключение к интернету и попробуйте заново"
|
||||||
|
case .noError:
|
||||||
|
"Ошибки нет"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,6 +27,7 @@ final class ViewModel: ObservableObject {
|
|||||||
@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 = ""
|
||||||
|
|
||||||
//MARK: Methods
|
//MARK: Methods
|
||||||
func fetchWeekSchedule(_ group: String, _ num: Int = 0) {
|
func fetchWeekSchedule(_ group: String, _ num: Int = 0) {
|
||||||
@ -38,7 +39,7 @@ final class ViewModel: ObservableObject {
|
|||||||
week += num
|
week += num
|
||||||
schedule = try await NetworkManager.shared.getScheduleForOtherWeek(week, numOfGroup)
|
schedule = try await NetworkManager.shared.getScheduleForOtherWeek(week, numOfGroup)
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
schedule = try await NetworkManager.shared.getSchedule(group)
|
schedule = try await NetworkManager.shared.getSchedule(group)
|
||||||
}
|
}
|
||||||
weekSchedule = schedule.table
|
weekSchedule = schedule.table
|
||||||
@ -48,12 +49,14 @@ final class ViewModel: ObservableObject {
|
|||||||
self.isFirstStartOffApp = false
|
self.isFirstStartOffApp = false
|
||||||
self.isShowingAlertForIncorrectGroup = false
|
self.isShowingAlertForIncorrectGroup = false
|
||||||
isLoading = false
|
isLoading = false
|
||||||
|
self.errorInNetwork = .noError
|
||||||
|
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
if let error = error as? NetworkError {
|
if let error = error as? NetworkError {
|
||||||
switch (error) {
|
switch (error) {
|
||||||
case .invalidResponse:
|
case .invalidResponse:
|
||||||
print(4)
|
errorInNetwork = .invalidResponse
|
||||||
case .invalidData:
|
case .invalidData:
|
||||||
errorInNetwork = .invalidData
|
errorInNetwork = .invalidData
|
||||||
self.isShowingAlertForIncorrectGroup = true
|
self.isShowingAlertForIncorrectGroup = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user