Add unified DataManager as single source of truth for all app data

- Create DataManager.kt with StateFlows for all cached data:
  - Authentication (token, user)
  - Residences, tasks, documents, contractors
  - Subscription status and upgrade triggers
  - All lookup data (residence types, task categories, etc.)
  - Theme preferences and state metadata

- Add PersistenceManager with platform-specific implementations:
  - Android: SharedPreferences
  - iOS: NSUserDefaults
  - JVM: Properties file
  - WasmJS: localStorage

- Migrate APILayer to update DataManager on every API response
- Update Kotlin ViewModels to use DataManager for token access
- Deprecate LookupsRepository (delegates to DataManager)
- Create iOS DataManagerObservable Swift wrapper for SwiftUI
- Update iOS auth flow to use DataManager.isAuthenticated()

Data flow: User Action → API Call → DataManager Updated → All Screens React

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-12-03 00:21:24 -06:00
parent b79fda8aee
commit cf0cd1cda2
17 changed files with 1721 additions and 489 deletions

View File

@@ -0,0 +1,38 @@
package com.example.casera.data
import kotlinx.browser.localStorage
/**
* WasmJS implementation of PersistenceManager using browser localStorage.
*/
actual class PersistenceManager {
actual fun save(key: String, value: String) {
localStorage.setItem(key, value)
}
actual fun load(key: String): String? {
return localStorage.getItem(key)
}
actual fun remove(key: String) {
localStorage.removeItem(key)
}
actual fun clear() {
// Remove all items with our prefix
val keysToRemove = mutableListOf<String>()
for (i in 0 until localStorage.length) {
val key = localStorage.key(i) ?: continue
if (key.startsWith("dm_")) {
keysToRemove.add(key)
}
}
keysToRemove.forEach { localStorage.removeItem(it) }
}
companion object {
private val instance by lazy { PersistenceManager() }
fun getInstance(): PersistenceManager = instance
}
}