View Models
All view models are @MainActor classes with @Published properties for SwiftUI reactivity.
AuthViewModel
File: ViewModels/AuthViewModel.swift
Published Properties
| Property | Type | Description |
|---|---|---|
user | User? | Current Supabase user |
profile | Profile? | User profile |
loyaltyAccount | LoyaltyAccount? | Loyalty data |
isLoading | Bool | Loading state |
isAuthenticated | Bool | Auth state |
error | String? | Error message |
Computed Properties
| Property | Type | Description |
|---|---|---|
isStaff | Bool | Employee or admin |
isAdmin | Bool | Admin only |
tierProgress | TierProgress? | Tier progress calculation |
Methods
checkSession(), signInWithEmail(), signUpWithEmail(), signInWithGoogle(), signInWithApple(), signInWithAppleToken(), signOut(), updateProfile(), refreshLoyaltyData()
Injected as @EnvironmentObject from StaccatoCoffeeApp.
CartViewModel
File: ViewModels/CartViewModel.swift
Published Properties
| Property | Type | Description |
|---|---|---|
items | [CartItem] | Cart items |
showCart | Bool | Cart visibility |
Computed Properties
| Property | Type | Description |
|---|---|---|
itemCount | Int | Total items |
subtotal | Int | Sum of item totals (cents) |
tax | Int | Tax at 8.5% |
totalStars | Int | Stars to be earned |
isEmpty | Bool | No items |
Methods
addItem(from: MenuItem, ...), addItem(from: MenuItemWithModifiers, ...), removeItem(id:), updateQuantity(id:quantity:), incrementQuantity(id:), decrementQuantity(id:), clearCart(), toOrderItems()
Persists to UserDefaults via CartStorageService. Injected as @EnvironmentObject.
MenuViewModel
File: ViewModels/MenuViewModel.swift
Manages menu browsing with categories, items, and search. Caches data locally.
Key Published Properties
categories, menuItems, featuredItems, selectedCategory, searchText, isLoading, error
CheckoutViewModel
File: ViewModels/CheckoutViewModel.swift
Orchestrates the checkout flow: payment processing, order creation, and cart clearing.
Key Published Properties
isProcessing, orderResult, error, selectedPaymentMethod
RewardsViewModel
File: ViewModels/RewardsViewModel.swift
Manages the rewards tab: available rewards, redemption, and transaction history.
Key Published Properties
rewards, transactions, loyaltyAccount, isLoading, isRedeeming
OrderQueueViewModel
File: ViewModels/OrderQueueViewModel.swift
Manages the staff order queue with real-time updates and order actions.
Key Published Properties
orders, selectedFilter, isLoading, error
AnalyticsViewModel
File: ViewModels/AnalyticsViewModel.swift
Manages the admin dashboard data for all analytics sections.
Key Published Properties
salesSummary, dailySales, hourlyDistribution, topItems, popularModifiers, employeePerformance, tierStats, starSummary, selectedTimeRange, isLoading