|
| 1 | +// |
| 2 | +// EmptyClassAPIService.swift |
| 3 | +// VITTY |
| 4 | +// |
| 5 | +// Created by Rujin Devkota on 2/27/25. |
| 6 | +// |
| 7 | + |
1 | 8 | import SwiftUI |
2 | 9 |
|
3 | 10 | struct EmptyClassRoom: View { |
@@ -88,83 +95,172 @@ struct EmptyClassRoom: View { |
88 | 95 | private var contentView: some View { |
89 | 96 | Group { |
90 | 97 | if viewModel.isLoading { |
91 | | - VStack(spacing: 16) { |
92 | | - ProgressView() |
93 | | - .scaleEffect(1.2) |
94 | | - .tint(.white) |
95 | | - Text("Loading classrooms...") |
96 | | - .foregroundColor(.white.opacity(0.8)) |
97 | | - .font(.subheadline) |
98 | | - } |
99 | | - .frame(maxWidth: .infinity, maxHeight: .infinity) |
100 | | - .padding() |
| 98 | + loadingView |
| 99 | + } else if viewModel.isGenerating { |
| 100 | + generatingView |
101 | 101 | } else if let errorMessage = viewModel.errorMessage { |
102 | | - VStack(spacing: 16) { |
103 | | - Image(systemName: "exclamationmark.triangle") |
104 | | - .font(.system(size: 40)) |
105 | | - .foregroundColor(.red.opacity(0.8)) |
106 | | - Text("Error") |
107 | | - .font(.headline) |
108 | | - .foregroundColor(.white) |
109 | | - Text(errorMessage) |
110 | | - .foregroundColor(.red.opacity(0.8)) |
111 | | - .multilineTextAlignment(.center) |
112 | | - .font(.subheadline) |
113 | | - Button("Retry") { |
114 | | - Task { |
115 | | - await viewModel.fetchEmptyClassrooms(slot: selectedSlot, authToken: authViewModel.loggedInBackendUser?.token ?? "") |
116 | | - } |
117 | | - } |
| 102 | + errorView(errorMessage) |
| 103 | + } else if viewModel.emptyClassrooms.isEmpty { |
| 104 | + emptyStateView |
| 105 | + } else if filteredClassrooms.isEmpty && !searchText.isEmpty { |
| 106 | + noResultsView |
| 107 | + } else { |
| 108 | + classroomsGrid |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + private var loadingView: some View { |
| 114 | + VStack(spacing: 16) { |
| 115 | + ProgressView() |
| 116 | + .scaleEffect(1.2) |
| 117 | + .tint(.white) |
| 118 | + Text("Loading classrooms...") |
| 119 | + .foregroundColor(.white.opacity(0.8)) |
| 120 | + .font(.subheadline) |
| 121 | + } |
| 122 | + .frame(maxWidth: .infinity, maxHeight: .infinity) |
| 123 | + .padding() |
| 124 | + } |
| 125 | + |
| 126 | + private var generatingView: some View { |
| 127 | + VStack(spacing: 24) { |
| 128 | + // Animated hourglass icon |
| 129 | + Image(systemName: "hourglass") |
| 130 | + .font(.system(size: 50)) |
| 131 | + .foregroundColor(.blue.opacity(0.7)) |
| 132 | + .rotationEffect(.degrees(viewModel.isGenerating ? 180 : 0)) |
| 133 | + .animation(.easeInOut(duration: 1.5).repeatForever(autoreverses: true), value: viewModel.isGenerating) |
| 134 | + |
| 135 | + VStack(spacing: 16) { |
| 136 | + Text("Preparing Your Data") |
| 137 | + .font(.title2) |
| 138 | + .fontWeight(.semibold) |
118 | 139 | .foregroundColor(.white) |
| 140 | + |
| 141 | + Text("Our system is currently generating the latest classroom information for slot \(selectedSlot).") |
| 142 | + .foregroundColor(.white.opacity(0.8)) |
| 143 | + .multilineTextAlignment(.center) |
| 144 | + .font(.body) |
119 | 145 | .padding(.horizontal, 20) |
120 | | - .padding(.vertical, 8) |
121 | | - .background(Color.blue.opacity(0.7)) |
122 | | - .cornerRadius(8) |
123 | | - } |
124 | | - .frame(maxWidth: .infinity, maxHeight: .infinity) |
125 | | - .padding() |
126 | | - } else if viewModel.emptyClassrooms.isEmpty { |
127 | | - VStack(spacing: 16) { |
128 | | - Image(systemName: "building.2") |
129 | | - .font(.system(size: 40)) |
| 146 | + |
| 147 | + VStack(spacing: 8) { |
| 148 | + Text("This process may take a few moments") |
| 149 | + .foregroundColor(.blue.opacity(0.8)) |
| 150 | + .font(.subheadline) |
| 151 | + |
| 152 | + Text("Please try reloading in a moment") |
130 | 153 | .foregroundColor(.white.opacity(0.6)) |
131 | | - Text("No Classrooms Available") |
132 | | - .font(.headline) |
133 | | - .foregroundColor(.white) |
134 | | - Text("There are no empty classrooms for slot \(selectedSlot) at this time.") |
135 | | - .foregroundColor(.white.opacity(0.8)) |
136 | | - .multilineTextAlignment(.center) |
| 154 | + .font(.caption) |
| 155 | + } |
| 156 | + .padding(.top, 8) |
| 157 | + } |
| 158 | + |
| 159 | + Button(action: { |
| 160 | + viewModel.reload(slot: selectedSlot, authToken: authViewModel.loggedInBackendUser?.token ?? "") |
| 161 | + }) { |
| 162 | + HStack(spacing: 8) { |
| 163 | + Image(systemName: "arrow.clockwise") |
| 164 | + .font(.system(size: 14, weight: .medium)) |
| 165 | + Text("Reload") |
137 | 166 | .font(.subheadline) |
| 167 | + .fontWeight(.medium) |
138 | 168 | } |
139 | | - .frame(maxWidth: .infinity, maxHeight: .infinity) |
140 | | - .padding() |
141 | | - } else if filteredClassrooms.isEmpty && !searchText.isEmpty { |
142 | | - VStack(spacing: 16) { |
143 | | - Image(systemName: "magnifyingglass") |
144 | | - .font(.system(size: 40)) |
145 | | - .foregroundColor(.white.opacity(0.6)) |
146 | | - Text("No Results Found") |
147 | | - .font(.headline) |
148 | | - .foregroundColor(.white) |
149 | | - Text("No classrooms match '\(searchText)'") |
150 | | - .foregroundColor(.white.opacity(0.8)) |
151 | | - .multilineTextAlignment(.center) |
| 169 | + .foregroundColor(.white) |
| 170 | + .padding(.horizontal, 24) |
| 171 | + .padding(.vertical, 12) |
| 172 | + .background( |
| 173 | + RoundedRectangle(cornerRadius: 10) |
| 174 | + .fill(Color.blue.opacity(0.7)) |
| 175 | + .shadow(color: .black.opacity(0.2), radius: 4, x: 0, y: 2) |
| 176 | + ) |
| 177 | + } |
| 178 | + .padding(.top, 8) |
| 179 | + } |
| 180 | + .frame(maxWidth: .infinity, maxHeight: .infinity) |
| 181 | + .padding() |
| 182 | + } |
| 183 | + |
| 184 | + private func errorView(_ errorMessage: String) -> some View { |
| 185 | + VStack(spacing: 16) { |
| 186 | + Image(systemName: "exclamationmark.triangle") |
| 187 | + .font(.system(size: 40)) |
| 188 | + .foregroundColor(.orange.opacity(0.8)) |
| 189 | + |
| 190 | + Text("Oops!") |
| 191 | + .font(.headline) |
| 192 | + .foregroundColor(.white) |
| 193 | + |
| 194 | + Text(errorMessage) |
| 195 | + .foregroundColor(.white.opacity(0.8)) |
| 196 | + .multilineTextAlignment(.center) |
| 197 | + .font(.subheadline) |
| 198 | + .padding(.horizontal) |
| 199 | + |
| 200 | + Button(action: { |
| 201 | + viewModel.reload(slot: selectedSlot, authToken: authViewModel.loggedInBackendUser?.token ?? "") |
| 202 | + }) { |
| 203 | + HStack(spacing: 8) { |
| 204 | + Image(systemName: "arrow.clockwise") |
| 205 | + .font(.system(size: 14, weight: .medium)) |
| 206 | + Text("Reload") |
152 | 207 | .font(.subheadline) |
153 | | - Button("Clear Search") { |
154 | | - searchText = "" |
155 | | - } |
156 | | - .foregroundColor(.white) |
157 | | - .padding(.horizontal, 20) |
158 | | - .padding(.vertical, 8) |
159 | | - .background(Color.blue.opacity(0.7)) |
160 | | - .cornerRadius(8) |
| 208 | + .fontWeight(.medium) |
161 | 209 | } |
162 | | - .frame(maxWidth: .infinity, maxHeight: .infinity) |
163 | | - .padding() |
164 | | - } else { |
165 | | - classroomsGrid |
| 210 | + .foregroundColor(.white) |
| 211 | + .padding(.horizontal, 24) |
| 212 | + .padding(.vertical, 12) |
| 213 | + .background( |
| 214 | + RoundedRectangle(cornerRadius: 10) |
| 215 | + .fill(Color.orange.opacity(0.7)) |
| 216 | + .shadow(color: .black.opacity(0.2), radius: 4, x: 0, y: 2) |
| 217 | + ) |
| 218 | + } |
| 219 | + } |
| 220 | + .frame(maxWidth: .infinity, maxHeight: .infinity) |
| 221 | + .padding() |
| 222 | + } |
| 223 | + |
| 224 | + private var emptyStateView: some View { |
| 225 | + VStack(spacing: 16) { |
| 226 | + Image(systemName: "building.2") |
| 227 | + .font(.system(size: 40)) |
| 228 | + .foregroundColor(.white.opacity(0.6)) |
| 229 | + Text("No Classrooms Available") |
| 230 | + .font(.headline) |
| 231 | + .foregroundColor(.white) |
| 232 | + Text("There are no empty classrooms for slot \(selectedSlot) at this time.") |
| 233 | + .foregroundColor(.white.opacity(0.8)) |
| 234 | + .multilineTextAlignment(.center) |
| 235 | + .font(.subheadline) |
| 236 | + } |
| 237 | + .frame(maxWidth: .infinity, maxHeight: .infinity) |
| 238 | + .padding() |
| 239 | + } |
| 240 | + |
| 241 | + private var noResultsView: some View { |
| 242 | + VStack(spacing: 16) { |
| 243 | + Image(systemName: "magnifyingglass") |
| 244 | + .font(.system(size: 40)) |
| 245 | + .foregroundColor(.white.opacity(0.6)) |
| 246 | + Text("No Results Found") |
| 247 | + .font(.headline) |
| 248 | + .foregroundColor(.white) |
| 249 | + Text("No classrooms match '\(searchText)'") |
| 250 | + .foregroundColor(.white.opacity(0.8)) |
| 251 | + .multilineTextAlignment(.center) |
| 252 | + .font(.subheadline) |
| 253 | + Button("Clear Search") { |
| 254 | + searchText = "" |
166 | 255 | } |
| 256 | + .foregroundColor(.white) |
| 257 | + .padding(.horizontal, 20) |
| 258 | + .padding(.vertical, 8) |
| 259 | + .background(Color.blue.opacity(0.7)) |
| 260 | + .cornerRadius(8) |
167 | 261 | } |
| 262 | + .frame(maxWidth: .infinity, maxHeight: .infinity) |
| 263 | + .padding() |
168 | 264 | } |
169 | 265 |
|
170 | 266 | private var classroomsGrid: some View { |
|
0 commit comments