05/02 Phase B

This commit is contained in:
Nguyen Ngo
2026-05-02 11:46:28 -04:00
parent ef0a6448cf
commit 8bdcbecd73
22 changed files with 3262 additions and 69 deletions
+17 -50
View File
@@ -1,61 +1,28 @@
//
// ContentView.swift
// JanitorialQC
//
// Created by Nguyen Ngo on 5/2/26.
//
// ContentView.swift
// -----------------
// Root view. Shows LoginView or DashboardView based on auth state.
import SwiftUI
import SwiftData
struct ContentView: View {
@Environment(\.modelContext) private var modelContext
@Query private var items: [Item]
@EnvironmentObject private var auth: AuthManager
var body: some View {
NavigationSplitView {
List {
ForEach(items) { item in
NavigationLink {
Text("Item at \(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))")
} label: {
Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))
}
Group {
if auth.isLoading && !auth.isAuthenticated {
// Splash / loading state on app launch
VStack(spacing: 16) {
Image(systemName: "checkmark.seal.fill")
.font(.system(size: 64))
.foregroundStyle(.blue)
ProgressView("Loading…")
}
.onDelete(perform: deleteItems)
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
EditButton()
}
ToolbarItem {
Button(action: addItem) {
Label("Add Item", systemImage: "plus")
}
}
}
} detail: {
Text("Select an item")
}
}
private func addItem() {
withAnimation {
let newItem = Item(timestamp: Date())
modelContext.insert(newItem)
}
}
private func deleteItems(offsets: IndexSet) {
withAnimation {
for index in offsets {
modelContext.delete(items[index])
} else if auth.isAuthenticated {
DashboardView()
} else {
LoginView()
}
}
.animation(.easeInOut(duration: 0.3), value: auth.isAuthenticated)
}
}
#Preview {
ContentView()
.modelContainer(for: Item.self, inMemory: true)
}