API ReferenceView Models

View Models

All view models are @MainActor classes with @Published properties for SwiftUI reactivity.

AuthViewModel

File: ViewModels/AuthViewModel.swift

Published Properties

PropertyTypeDescription
userUser?Current Supabase user
profileProfile?User profile
loyaltyAccountLoyaltyAccount?Loyalty data
isLoadingBoolLoading state
isAuthenticatedBoolAuth state
errorString?Error message

Computed Properties

PropertyTypeDescription
isStaffBoolEmployee or admin
isAdminBoolAdmin only
tierProgressTierProgress?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

PropertyTypeDescription
items[CartItem]Cart items
showCartBoolCart visibility

Computed Properties

PropertyTypeDescription
itemCountIntTotal items
subtotalIntSum of item totals (cents)
taxIntTax at 8.5%
totalStarsIntStars to be earned
isEmptyBoolNo 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.


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