feat: major app overhaul — API fixes, glassmorphism UI, health dashboard, notifications

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>
This commit is contained in:
2026-04-05 23:15:36 +03:00
parent 1146965bcb
commit 28fca1de89
38 changed files with 3608 additions and 1031 deletions

View File

@@ -41,8 +41,8 @@ struct DashboardView: View {
var body: some View {
ZStack(alignment: .bottomTrailing) {
Color(hex: "0a0a1a").ignoresSafeArea()
ScrollView {
Theme.bg.ignoresSafeArea()
ScrollView(showsIndicators: false) {
VStack(spacing: 20) {
// MARK: Header
HStack {
@@ -50,7 +50,7 @@ struct DashboardView: View {
Text("\(greeting), \(authManager.userName)!")
.font(.title2.bold()).foregroundColor(.white)
Text(Date(), style: .date)
.font(.subheadline).foregroundColor(Color(hex: "8888aa"))
.font(.subheadline).foregroundColor(Theme.textSecondary)
}
Spacer()
}
@@ -58,51 +58,47 @@ struct DashboardView: View {
.padding(.top)
if isLoading {
ProgressView().tint(Color(hex: "0D9488")).padding(.top, 40)
ProgressView().tint(Theme.teal).padding(.top, 40)
} else {
// MARK: Day Progress
VStack(alignment: .leading, spacing: 8) {
VStack(alignment: .leading, spacing: 10) {
HStack {
Text("Прогресс дня")
.font(.subheadline).foregroundColor(Color(hex: "8888aa"))
.font(.subheadline.weight(.medium)).foregroundColor(Theme.textSecondary)
Spacer()
Text("\(completedHabitsToday)/\(totalHabitsToday) привычек")
.font(.caption).foregroundColor(Color(hex: "0D9488"))
Text("\(completedHabitsToday)/\(totalHabitsToday)")
.font(.caption.bold()).foregroundColor(Theme.teal)
}
GeometryReader { geo in
ZStack(alignment: .leading) {
RoundedRectangle(cornerRadius: 4)
.fill(Color.white.opacity(0.1))
RoundedRectangle(cornerRadius: 4)
.fill(LinearGradient(colors: [Color(hex: "0D9488"), Color(hex: "14b8a6")], startPoint: .leading, endPoint: .trailing))
RoundedRectangle(cornerRadius: 6)
.fill(Color.white.opacity(0.08))
RoundedRectangle(cornerRadius: 6)
.fill(LinearGradient(colors: [Theme.teal, Theme.tealLight], startPoint: .leading, endPoint: .trailing))
.frame(width: geo.size.width * dayProgress)
.shadow(color: Theme.teal.opacity(0.5), radius: 8, y: 0)
.animation(.easeInOut(duration: 0.5), value: dayProgress)
}
}
.frame(height: 8)
}
.padding(16)
.glassCard(cornerRadius: 16)
.padding(.horizontal)
// MARK: Stat Cards
LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())], spacing: 12) {
DashStatCard(icon: "checkmark.circle.fill", value: "\(completedHabitsToday)", label: "Выполнено сегодня", color: "0D9488")
DashStatCard(icon: "flame.fill", value: "\(habitsStats?.activeHabits ?? totalHabitsToday)", label: "Активных привычек", color: "ffa502")
DashStatCard(icon: "calendar", value: "\(todayTasks.count)", label: "Задач на сегодня", color: "6366f1")
DashStatCard(icon: "checkmark.seal.fill", value: "\(completedTodayTasksCount)", label: "Задач выполнено", color: "10b981")
LazyVGrid(columns: [GridItem(.flexible(), spacing: 12), GridItem(.flexible(), spacing: 12)], spacing: 12) {
GlowStatCard(icon: "checkmark.circle.fill", value: "\(completedHabitsToday)", label: "Выполнено", color: Theme.teal)
GlowStatCard(icon: "flame.fill", value: "\(habitsStats?.activeHabits ?? totalHabitsToday)", label: "Активных", color: Theme.orange)
GlowStatCard(icon: "calendar", value: "\(todayTasks.count)", label: "Задач", color: Theme.indigo)
GlowStatCard(icon: "checkmark.seal.fill", value: "\(completedTodayTasksCount)", label: "Готово", color: Theme.green)
}
.padding(.horizontal)
// MARK: Today's Habits
if !todayHabits.isEmpty {
VStack(alignment: .leading, spacing: 10) {
HStack {
Text("Привычки сегодня")
.font(.headline).foregroundColor(.white)
Spacer()
Text("\(completedHabitsToday)/\(totalHabitsToday)")
.font(.caption).foregroundColor(Color(hex: "8888aa"))
}
.padding(.horizontal)
SectionHeader(title: "Привычки", trailing: "\(completedHabitsToday)/\(totalHabitsToday)")
ForEach(todayHabits) { habit in
DashHabitRow(
@@ -120,12 +116,12 @@ struct DashboardView: View {
// MARK: Today's Tasks
VStack(alignment: .leading, spacing: 10) {
HStack {
Text("Задачи на сегодня")
Text("Задачи")
.font(.headline).foregroundColor(.white)
Spacer()
Button(action: { addMode = .task; showAddSheet = true }) {
Image(systemName: "plus.circle.fill")
.foregroundColor(Color(hex: "0D9488"))
.foregroundColor(Theme.teal).font(.title3)
}
}
.padding(.horizontal)
@@ -144,7 +140,7 @@ struct DashboardView: View {
}
}
}
Spacer(minLength: 80)
Spacer(minLength: 100)
}
}
.refreshable { await loadData(refresh: true) }
@@ -153,27 +149,31 @@ struct DashboardView: View {
Button(action: { addMode = .task; showAddSheet = true }) {
ZStack {
Circle()
.fill(LinearGradient(colors: [Color(hex: "0D9488"), Color(hex: "14b8a6")], startPoint: .topLeading, endPoint: .bottomTrailing))
.fill(Theme.teal.opacity(0.3))
.frame(width: 64, height: 64)
.blur(radius: 10)
Circle()
.fill(LinearGradient(colors: [Theme.teal, Theme.tealLight], startPoint: .topLeading, endPoint: .bottomTrailing))
.frame(width: 56, height: 56)
.shadow(color: Color(hex: "0D9488").opacity(0.4), radius: 8, y: 4)
.shadow(color: Theme.teal.opacity(0.5), radius: 12, y: 4)
Image(systemName: "plus").font(.title2.bold()).foregroundColor(.white)
}
}
.padding(.bottom, 90)
.padding(.bottom, 100)
.padding(.trailing, 20)
}
.task { await loadData() }
.sheet(isPresented: $showAddSheet) {
if addMode == .task {
AddTaskView(isPresented: $showAddSheet) { await loadData(refresh: true) }
.presentationDetents([.medium, .large])
.presentationDetents([.large])
.presentationDragIndicator(.visible)
.presentationBackground(Color(hex: "0a0a1a"))
.presentationBackground(Theme.bg)
} else {
AddHabitView(isPresented: $showAddSheet) { await loadData(refresh: true) }
.presentationDetents([.large])
.presentationDragIndicator(.visible)
.presentationBackground(Color(hex: "0a0a1a"))
.presentationBackground(Theme.bg)
}
}
.alert("Ошибка", isPresented: $showError) {
@@ -186,24 +186,63 @@ struct DashboardView: View {
func loadData(refresh: Bool = false) async {
if !refresh { isLoading = true }
async let tasks = APIService.shared.getTodayTasks(token: authManager.token)
async let habits = APIService.shared.getHabits(token: authManager.token)
async let allHabits = APIService.shared.getHabits(token: authManager.token)
async let stats = APIService.shared.getHabitsStats(token: authManager.token)
todayTasks = (try? await tasks) ?? []
todayHabits = (try? await habits) ?? []
habitsStats = try? await stats
// Filter habits for today + check completion
var habits = ((try? await allHabits) ?? []).filter { !($0.isArchived ?? false) }
habits = filterHabitsForToday(habits)
// Check which habits are completed today
let today = todayDateString()
for i in habits.indices {
let logs = (try? await APIService.shared.getHabitLogs(token: authManager.token, habitId: habits[i].id, days: 1)) ?? []
habits[i].completedToday = logs.contains { $0.dateOnly == today }
}
todayHabits = habits
isLoading = false
}
func filterHabitsForToday(_ habits: [Habit]) -> [Habit] {
let weekday = Calendar.current.component(.weekday, from: Date()) - 1 // 0=Sun, 1=Mon...6=Sat
return habits.filter { habit in
switch habit.frequency {
case .daily: return true
case .weekly:
guard let days = habit.targetDays, !days.isEmpty else { return true }
return days.contains(weekday)
case .monthly:
let day = Calendar.current.component(.day, from: Date())
return habit.targetCount == day || habit.targetDays?.contains(day) == true
case .interval:
// Show interval habits every N days from start
guard let startStr = habit.startDate ?? habit.createdAt,
let startDate = parseDate(startStr) else { return true }
let daysSince = Calendar.current.dateComponents([.day], from: startDate, to: Date()).day ?? 0
let interval = max(habit.targetCount ?? 1, 1)
return daysSince % interval == 0
case .custom:
// Custom habits: check target_days if set, otherwise show daily
guard let days = habit.targetDays, !days.isEmpty else { return true }
return days.contains(weekday)
}
}
}
func parseDate(_ str: String) -> Date? {
let df = DateFormatter(); df.dateFormat = "yyyy-MM-dd"
return df.date(from: String(str.prefix(10)))
}
// MARK: - Actions
func toggleHabit(_ habit: Habit) async {
if habit.completedToday == true {
// Already done undo will handle it
return
}
if habit.completedToday == true { return }
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
let today = todayDateString()
do {
let today = todayDateString()
try await APIService.shared.logHabit(token: authManager.token, id: habit.id, date: today)
recentlyLoggedHabitId = habit.id
recentlyLoggedHabitLogDate = today
@@ -225,7 +264,6 @@ struct DashboardView: View {
func undoHabitLog(_ habit: Habit) async {
UIImpactFeedbackGenerator(style: .light).impactOccurred()
// Get logs and find today's log to delete
do {
let logs = try await APIService.shared.getHabitLogs(token: authManager.token, habitId: habit.id, days: 1)
let today = todayDateString()
@@ -255,9 +293,7 @@ struct DashboardView: View {
func undoTask(_ task: PulseTask) async {
UIImpactFeedbackGenerator(style: .light).impactOccurred()
do {
try await APIService.shared.uncompleteTask(token: authManager.token, id: task.id)
} catch {}
do { try await APIService.shared.uncompleteTask(token: authManager.token, id: task.id) } catch {}
recentlyCompletedTaskId = nil
await loadData(refresh: true)
}
@@ -277,31 +313,6 @@ struct DashboardView: View {
}
}
// MARK: - DashStatCard
struct DashStatCard: View {
let icon: String
let value: String
let label: String
let color: String
var body: some View {
VStack(spacing: 8) {
Image(systemName: icon)
.foregroundColor(Color(hex: color))
.font(.title2)
Text(value)
.font(.title3.bold()).foregroundColor(.white)
Text(label)
.font(.caption).foregroundColor(Color(hex: "8888aa"))
.multilineTextAlignment(.center)
}
.frame(maxWidth: .infinity)
.padding(16)
.background(RoundedRectangle(cornerRadius: 16).fill(Color.white.opacity(0.05)))
}
}
// MARK: - DashHabitRow
struct DashHabitRow: View {
@@ -316,16 +327,23 @@ struct DashHabitRow: View {
var body: some View {
HStack(spacing: 14) {
ZStack {
Circle().fill(accentColor.opacity(isDone ? 0.3 : 0.1)).frame(width: 44, height: 44)
if isDone {
Circle().fill(accentColor.opacity(0.2)).frame(width: 44, height: 44).blur(radius: 6)
}
Circle().fill(accentColor.opacity(isDone ? 0.2 : 0.08)).frame(width: 44, height: 44)
Text(habit.displayIcon).font(.title3)
}
VStack(alignment: .leading, spacing: 3) {
Text(habit.name)
.font(.callout.weight(.medium)).foregroundColor(.white)
HStack(spacing: 6) {
Text(habit.frequencyLabel).font(.caption).foregroundColor(Color(hex: "8888aa"))
Text(habit.frequencyLabel).font(.caption).foregroundColor(Theme.textSecondary)
if let streak = habit.currentStreak, streak > 0 {
Text("🔥 \(streak)").font(.caption).foregroundColor(Color(hex: "ffa502"))
HStack(spacing: 2) {
Image(systemName: "flame.fill").font(.caption2)
Text("\(streak)")
}
.font(.caption).foregroundColor(Theme.orange)
}
}
}
@@ -333,22 +351,23 @@ struct DashHabitRow: View {
if isUndoVisible {
Button(action: { Task { await onUndo() } }) {
Text("Отмена").font(.caption.bold())
.foregroundColor(Color(hex: "ffa502"))
.foregroundColor(Theme.orange)
.padding(.horizontal, 10).padding(.vertical, 6)
.background(RoundedRectangle(cornerRadius: 8).fill(Color(hex: "ffa502").opacity(0.15)))
.background(RoundedRectangle(cornerRadius: 8).fill(Theme.orange.opacity(0.15)))
}
}
Button(action: { guard !isDone else { return }; Task { await onToggle() } }) {
Image(systemName: isDone ? "checkmark.circle.fill" : "circle")
.font(.title2)
.foregroundColor(isDone ? accentColor : Color(hex: "8888aa"))
.foregroundColor(isDone ? accentColor : Color(hex: "555566"))
}
.buttonStyle(.plain)
}
.padding(14)
.background(
.glassCard(cornerRadius: 16)
.overlay(
RoundedRectangle(cornerRadius: 16)
.fill(isDone ? accentColor.opacity(0.08) : Color.white.opacity(0.04))
.overlay(RoundedRectangle(cornerRadius: 16).stroke(isDone ? accentColor.opacity(0.3) : Color.clear, lineWidth: 1))
.stroke(isDone ? accentColor.opacity(0.3) : Color.clear, lineWidth: 1)
)
.padding(.horizontal)
.padding(.vertical, 2)
@@ -368,25 +387,25 @@ struct DashTaskRow: View {
Button(action: { Task { await onToggle() } }) {
Image(systemName: task.completed ? "checkmark.circle.fill" : "circle")
.font(.title3)
.foregroundColor(task.completed ? Color(hex: "0D9488") : Color(hex: "8888aa"))
.foregroundColor(task.completed ? Theme.teal : Color(hex: "555566"))
}
VStack(alignment: .leading, spacing: 3) {
Text(task.title)
.foregroundColor(task.completed ? Color(hex: "8888aa") : .white)
.foregroundColor(task.completed ? Theme.textSecondary : .white)
.strikethrough(task.completed)
.font(.callout)
HStack(spacing: 6) {
if let due = task.dueDateFormatted {
Text(due)
.font(.caption2)
.foregroundColor(task.isOverdue ? Color(hex: "ff4757") : Color(hex: "ffa502"))
.foregroundColor(task.isOverdue ? Theme.red : Theme.orange)
}
if let p = task.priority, p > 1 {
Circle().fill(Color(hex: task.priorityColor)).frame(width: 6, height: 6)
}
if task.isRecurring == true {
Image(systemName: "arrow.clockwise")
.font(.caption2).foregroundColor(Color(hex: "8888aa"))
.font(.caption2).foregroundColor(Theme.textSecondary)
}
}
}
@@ -394,14 +413,14 @@ struct DashTaskRow: View {
if isUndoVisible {
Button(action: { Task { await onUndo() } }) {
Text("Отмена").font(.caption.bold())
.foregroundColor(Color(hex: "ffa502"))
.foregroundColor(Theme.orange)
.padding(.horizontal, 10).padding(.vertical, 6)
.background(RoundedRectangle(cornerRadius: 8).fill(Color(hex: "ffa502").opacity(0.15)))
.background(RoundedRectangle(cornerRadius: 8).fill(Theme.orange.opacity(0.15)))
}
}
}
.padding(12)
.background(RoundedRectangle(cornerRadius: 12).fill(Color.white.opacity(0.05)))
.glassCard(cornerRadius: 14)
.padding(.horizontal)
.padding(.vertical, 2)
}
@@ -415,7 +434,7 @@ struct EmptyState: View {
var body: some View {
VStack(spacing: 8) {
Image(systemName: icon).font(.system(size: 32)).foregroundColor(Color(hex: "334155"))
Text(text).font(.subheadline).foregroundColor(Color(hex: "8888aa"))
Text(text).font(.subheadline).foregroundColor(Theme.textSecondary)
}
.frame(maxWidth: .infinity)
.padding(.vertical, 24)