API Integration: - Fix logHabit: send "date" instead of "completed_at" - Fix FinanceCategory: "icon" → "emoji" to match API - Fix task priorities: remove level 4, keep 1-3 matching API - Fix habit frequencies: map monthly/interval → "custom" for API - Add token refresh (401 → auto retry with new token) - Add proper error handling (remove try? in save functions, show errors in UI) - Add date field to savings transactions - Add MonthlyPaymentDetail and OverduePayment models - Fix habit completedToday: compute on client from logs (API doesn't return it) - Filter habits by day of week on client (daily/weekly/monthly/interval) Design System (glassmorphism): - New DesignSystem.swift: Theme colors, GlassCard modifier, GlowIcon, GlowStatCard - Custom tab bar with per-tab glow colors (VStack layout, not ZStack overlay) - Deep dark background #06060f across all views - Glass cards with gradient fill + stroke throughout app - App icon: glassmorphism style with teal glow Health Dashboard: - Compact ReadinessBanner with recommendation text - 8 metric tiles: sleep, HR, HRV, steps, SpO2, respiratory rate, energy, distance - Each tile with status indicator (good/ok/bad) and hint text - Heart rate card (min/avg/max) - Weekly trends card (averages) - Recovery score (weighted: 40% sleep, 35% HRV, 25% RHR) - Tips card with actionable recommendations - Sleep detail view with hypnogram (step chart of phases) - Sleep segments timeline from HealthKit (deep/rem/core/awake with exact times) - Line chart replacing bar chart for weekly data - Collect respiratory_rate and sleep phases with timestamps from HealthKit - Background sync every ~30min via BGProcessingTask Notifications: - NotificationService for local push notifications - Morning/evening reminders with native DatePicker (wheel) - Payment reminders: 5 days, 1 day, and day-of for recurring savings - Notification settings in Settings tab UI Fixes: - Fix color picker overflow: HStack → LazyVGrid 5 columns - Fix sheet headers: shorter text, proper padding - Fix task/habit toggle: separate tap zones (checkbox vs edit) - Fix deprecated onChange syntax for iOS 17+ - Savings overview: real monthly payments and detailed overdues from API - Settings: timezone as Menu picker, removed Telegram/server notifications sections - All sheets use .presentationDetents([.large]) Config: - project.yml: real DEVELOPMENT_TEAM, HealthKit + BackgroundModes capabilities - Info.plist: BGTaskScheduler + UIBackgroundModes - Assets.xcassets with AppIcon - CLAUDE.md project documentation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
149 lines
3.1 KiB
Swift
149 lines
3.1 KiB
Swift
import Foundation
|
|
|
|
struct ReadinessResponse: Codable {
|
|
let score: Int
|
|
let status: String
|
|
let recommendation: String
|
|
let date: String?
|
|
let factors: ReadinessFactors?
|
|
}
|
|
|
|
struct ReadinessFactors: Codable {
|
|
let sleep: FactorScore
|
|
let hrv: FactorScore
|
|
let rhr: FactorScore
|
|
let activity: FactorScore
|
|
}
|
|
|
|
struct FactorScore: Codable {
|
|
let score: Int
|
|
let value: String
|
|
let baseline: String?
|
|
}
|
|
|
|
struct LatestHealthResponse: Codable {
|
|
let sleep: SleepData?
|
|
let heartRate: HeartRateData?
|
|
let restingHeartRate: RestingHRData?
|
|
let hrv: HRVData?
|
|
let steps: StepsData?
|
|
let activeEnergy: EnergyData?
|
|
let bloodOxygen: BloodOxygenData?
|
|
let respiratoryRate: RespiratoryRateData?
|
|
let distance: DistanceData?
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case sleep, steps, hrv, distance
|
|
case heartRate = "heartRate"
|
|
case restingHeartRate = "restingHeartRate"
|
|
case activeEnergy = "activeEnergy"
|
|
case bloodOxygen = "spo2"
|
|
case respiratoryRate = "respiratoryRate"
|
|
}
|
|
}
|
|
|
|
struct BloodOxygenData: Codable {
|
|
let avg: Double?
|
|
let min: Double?
|
|
let max: Double?
|
|
}
|
|
|
|
struct RespiratoryRateData: Codable {
|
|
let avg: Double?
|
|
}
|
|
|
|
struct DistanceData: Codable {
|
|
let total: Double?
|
|
let units: String?
|
|
}
|
|
|
|
struct SleepData: Codable {
|
|
let totalSleep: Double?
|
|
let deep: Double?
|
|
let rem: Double?
|
|
let core: Double?
|
|
}
|
|
|
|
// Local-only model for sleep timeline (not from API)
|
|
struct SleepSegment: Identifiable {
|
|
let id = UUID()
|
|
let phase: SleepPhaseType
|
|
let start: Date
|
|
let end: Date
|
|
var duration: TimeInterval { end.timeIntervalSince(start) }
|
|
}
|
|
|
|
enum SleepPhaseType: String {
|
|
case deep = "Глубокий"
|
|
case rem = "REM"
|
|
case core = "Базовый"
|
|
case awake = "Пробуждение"
|
|
|
|
var color: Color {
|
|
switch self {
|
|
case .deep: return Color(hex: "7c3aed")
|
|
case .rem: return Color(hex: "a78bfa")
|
|
case .core: return Color(hex: "c4b5fd")
|
|
case .awake: return Color(hex: "ff4757")
|
|
}
|
|
}
|
|
|
|
var icon: String {
|
|
switch self {
|
|
case .deep: return "moon.zzz.fill"
|
|
case .rem: return "brain.head.profile"
|
|
case .core: return "moon.fill"
|
|
case .awake: return "eye.fill"
|
|
}
|
|
}
|
|
}
|
|
|
|
import SwiftUI
|
|
|
|
struct HeartRateData: Codable {
|
|
let avg: Int?
|
|
let min: Int?
|
|
let max: Int?
|
|
}
|
|
|
|
struct RestingHRData: Codable {
|
|
let value: Double?
|
|
}
|
|
|
|
struct HRVData: Codable {
|
|
let avg: Double?
|
|
let latest: Double?
|
|
}
|
|
|
|
struct StepsData: Codable {
|
|
let total: Int?
|
|
}
|
|
|
|
struct EnergyData: Codable {
|
|
let total: Int?
|
|
let units: String?
|
|
}
|
|
|
|
// MARK: - Heatmap / Weekly Data
|
|
|
|
struct HeatmapEntry: Codable, Identifiable {
|
|
let date: String
|
|
let score: Int?
|
|
let steps: Int?
|
|
let sleep: Double?
|
|
let hrv: Double?
|
|
let rhr: Double?
|
|
|
|
var id: String { date }
|
|
|
|
var displayDate: String {
|
|
let parts = date.split(separator: "-")
|
|
guard parts.count == 3 else { return date }
|
|
return "\(parts[2]).\(parts[1])"
|
|
}
|
|
}
|
|
|
|
struct HeatmapResponse: Codable {
|
|
let data: [HeatmapEntry]
|
|
}
|