AppState
Central state management for the app. Passed as @EnvironmentObject to all views.
Definition
@MainActor
class AppState: ObservableObject {
@Published var tags: [Tag] = []
@Published var tagsByID: [UUID: Tag] = [:]
@Published var runningRecords: [TimeRecord] = []
@Published var todayRecords: [TimeRecord] = []
@Published var isLoading = false
@Published var errorMessage: String?
@Published var pendingDeletion: (record: TimeRecord, timer: Timer)?
}
Key Methods
Data Loading
| Method | Description |
|---|
loadData() | Reload all data from 301-file-storage |
reinitializeStorage() | Reset storage location and reload |
Timer Operations
| Method | Description |
|---|
startTimer(tagId:comment:) | Start new timer via 303-time-tracking |
stopTimer(_:) | Stop a running timer |
Record Operations
| Method | Description |
|---|
updateRecord(_:) | Save changes to a 202-time-record |
deleteRecord(_:) | Permanently delete a record |
softDeleteRecord(_:) | Mark for deletion with 60s undo window |
undoDelete() | Restore pending deletion |
Tag Operations
| Method | Description |
|---|
createTag(name:color:) | Create new 201-tag |
deleteTag(_:) | Remove tag |
toggleArchiveTag(_:) | Archive/unarchive tag |
renameTag(_:to:) | Rename with merge if duplicate |
resolveTagId(from:) | Find or create tag by name |
Auto-Refresh
Data reloads every 60 seconds via timer:
- Keeps UI in sync with filesystem changes
- Handles external edits (e.g., iCloud sync)
Environment Usage
Must be passed explicitly to sheets:
.sheet(isPresented: $showSettings) {
SettingsSheet()
.environmentObject(appState)
}
Related