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

@@ -32,21 +32,22 @@ struct AddHabitView: View {
var body: some View {
ZStack {
Color(hex: "0a0a1a").ignoresSafeArea()
Color(hex: "06060f").ignoresSafeArea()
VStack(spacing: 0) {
RoundedRectangle(cornerRadius: 3)
.fill(Color.white.opacity(0.2)).frame(width: 40, height: 4).padding(.top, 12)
HStack {
Button("Отмена") { isPresented = false }.foregroundColor(Color(hex: "8888aa"))
Button("Отмена") { isPresented = false }
.font(.callout).foregroundColor(Color(hex: "8888aa"))
Spacer()
Text("Новая привычка").font(.headline).foregroundColor(.white)
Spacer()
Button(action: save) {
if isLoading { ProgressView().tint(Color(hex: "0D9488")).scaleEffect(0.8) }
else { Text("Добавить").foregroundColor(name.isEmpty ? Color(hex: "8888aa") : Color(hex: "0D9488")).fontWeight(.semibold) }
if isLoading { ProgressView().tint(Theme.teal).scaleEffect(0.8) }
else { Text("Готово").font(.callout.bold()).foregroundColor(name.isEmpty ? Color(hex: "8888aa") : Theme.teal) }
}.disabled(name.isEmpty || isLoading)
}
.padding(.horizontal, 20).padding(.vertical, 16)
.padding(.horizontal, 16).padding(.vertical, 14)
Divider().background(Color.white.opacity(0.1))
ScrollView {
VStack(spacing: 20) {
@@ -144,7 +145,7 @@ struct AddHabitView: View {
// Color picker
VStack(alignment: .leading, spacing: 8) {
Label("Цвет", systemImage: "paintpalette").font(.caption).foregroundColor(Color(hex: "8888aa"))
HStack(spacing: 10) {
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 5), spacing: 10) {
ForEach(colors, id: \.self) { color in
Button(action: { selectedColor = color }) {
Circle()
@@ -166,10 +167,11 @@ struct AddHabitView: View {
func save() {
isLoading = true
Task {
let apiFrequency = (frequency == "interval" || frequency == "monthly") ? "custom" : frequency
var body: [String: Any] = [
"name": name,
"description": description,
"frequency": frequency,
"frequency": apiFrequency,
"icon": selectedIcon,
"color": selectedColor,
"target_count": 1

View File

@@ -14,6 +14,11 @@ struct EditHabitView: View {
@State private var intervalDays: String
@State private var isLoading = false
@State private var showArchiveConfirm = false
@State private var freezes: [HabitFreeze] = []
@State private var showAddFreeze = false
@State private var freezeStartDate = Date()
@State private var freezeEndDate = Date().addingTimeInterval(86400 * 7)
@State private var freezeReason = ""
let weekdayNames = ["Вс","Пн","Вт","Ср","Чт","Пт","Сб"]
let icons = ["🔥", "💪", "🏃", "📚", "💧", "🧘", "🎯", "⭐️", "🌟", "",
@@ -42,21 +47,22 @@ struct EditHabitView: View {
var body: some View {
ZStack {
Color(hex: "0a0a1a").ignoresSafeArea()
Color(hex: "06060f").ignoresSafeArea()
VStack(spacing: 0) {
RoundedRectangle(cornerRadius: 3)
.fill(Color.white.opacity(0.2)).frame(width: 40, height: 4).padding(.top, 12)
HStack {
Button("Отмена") { isPresented = false }.foregroundColor(Color(hex: "8888aa"))
Button("Отмена") { isPresented = false }
.font(.callout).foregroundColor(Color(hex: "8888aa"))
Spacer()
Text("Редактировать привычку").font(.headline).foregroundColor(.white)
Text("Редактировать").font(.headline).foregroundColor(.white)
Spacer()
Button(action: save) {
if isLoading { ProgressView().tint(Color(hex: "0D9488")).scaleEffect(0.8) }
else { Text("Сохранить").foregroundColor(name.isEmpty ? Color(hex: "8888aa") : Color(hex: "0D9488")).fontWeight(.semibold) }
if isLoading { ProgressView().tint(Theme.teal).scaleEffect(0.8) }
else { Text("Готово").font(.callout.bold()).foregroundColor(name.isEmpty ? Color(hex: "8888aa") : Theme.teal) }
}.disabled(name.isEmpty || isLoading)
}
.padding(.horizontal, 20).padding(.vertical, 16)
.padding(.horizontal, 16).padding(.vertical, 14)
Divider().background(Color.white.opacity(0.1))
ScrollView {
VStack(spacing: 20) {
@@ -152,7 +158,7 @@ struct EditHabitView: View {
// Color picker
VStack(alignment: .leading, spacing: 8) {
Label("Цвет", systemImage: "paintpalette").font(.caption).foregroundColor(Color(hex: "8888aa"))
HStack(spacing: 10) {
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 5), spacing: 10) {
ForEach(colors, id: \.self) { color in
Button(action: { selectedColor = color }) {
Circle()
@@ -166,6 +172,73 @@ struct EditHabitView: View {
}
}
// Freezes
VStack(alignment: .leading, spacing: 10) {
HStack {
Label("Заморозки", systemImage: "snowflake").font(.caption).foregroundColor(Color(hex: "8888aa"))
Spacer()
Button(action: { showAddFreeze = true }) {
Image(systemName: "plus.circle.fill")
.foregroundColor(Color(hex: "0D9488"))
}
}
if freezes.isEmpty {
Text("Нет активных заморозок").font(.caption).foregroundColor(Color(hex: "8888aa"))
.padding(10)
.frame(maxWidth: .infinity)
.background(RoundedRectangle(cornerRadius: 10).fill(Color.white.opacity(0.04)))
} else {
ForEach(freezes) { freeze in
HStack {
VStack(alignment: .leading, spacing: 2) {
Text("\(formatFreezeDate(freeze.startDate))\(formatFreezeDate(freeze.endDate))")
.font(.callout).foregroundColor(.white)
}
Spacer()
Button(action: { Task { await deleteFreeze(freeze) } }) {
Image(systemName: "xmark.circle.fill")
.foregroundColor(Color(hex: "ff4757").opacity(0.8))
}
}
.padding(10)
.background(RoundedRectangle(cornerRadius: 10).fill(Color.white.opacity(0.05)))
}
}
if showAddFreeze {
VStack(spacing: 10) {
HStack {
VStack(alignment: .leading, spacing: 4) {
Text("Начало").font(.caption2).foregroundColor(Color(hex: "8888aa"))
DatePicker("", selection: $freezeStartDate, displayedComponents: .date)
.labelsHidden()
.colorInvert()
.colorMultiply(Color(hex: "0D9488"))
}
Spacer()
VStack(alignment: .leading, spacing: 4) {
Text("Конец").font(.caption2).foregroundColor(Color(hex: "8888aa"))
DatePicker("", selection: $freezeEndDate, in: freezeStartDate..., displayedComponents: .date)
.labelsHidden()
.colorInvert()
.colorMultiply(Color(hex: "0D9488"))
}
}
TextField("Причина (необязательно)", text: $freezeReason)
.foregroundColor(.white).padding(10)
.background(RoundedRectangle(cornerRadius: 8).fill(Color.white.opacity(0.07)))
HStack {
Button("Отмена") { showAddFreeze = false; freezeReason = "" }
.foregroundColor(Color(hex: "8888aa"))
Spacer()
Button("Добавить") { Task { await addFreeze() } }
.foregroundColor(Color(hex: "0D9488")).fontWeight(.semibold)
}
}
.padding(12)
.background(RoundedRectangle(cornerRadius: 12).fill(Color.white.opacity(0.06)))
}
}
// Archive / Restore button
Button(action: { showArchiveConfirm = true }) {
HStack {
@@ -181,6 +254,7 @@ struct EditHabitView: View {
}
}
}
.task { freezes = (try? await APIService.shared.getHabitFreezes(token: authManager.token, habitId: habit.id)) ?? [] }
.confirmationDialog(
habit.isArchived == true ? "Восстановить привычку?" : "Архивировать привычку?",
isPresented: $showArchiveConfirm,
@@ -197,9 +271,10 @@ struct EditHabitView: View {
func save() {
isLoading = true
Task {
let apiFrequency = (frequency == .interval || frequency == .monthly) ? "custom" : frequency.rawValue
var body: [String: Any] = [
"name": name,
"frequency": frequency.rawValue,
"frequency": apiFrequency,
"icon": selectedIcon,
"color": selectedColor,
"target_count": 1
@@ -218,6 +293,34 @@ struct EditHabitView: View {
}
}
func addFreeze() async {
let df = DateFormatter(); df.dateFormat = "yyyy-MM-dd"
let start = df.string(from: freezeStartDate)
let end = df.string(from: freezeEndDate)
if let freeze = try? await APIService.shared.createHabitFreeze(
token: authManager.token, habitId: habit.id,
startDate: start, endDate: end,
reason: freezeReason.isEmpty ? nil : freezeReason
) {
await MainActor.run {
freezes.append(freeze)
showAddFreeze = false
freezeReason = ""
}
}
}
func deleteFreeze(_ freeze: HabitFreeze) async {
try? await APIService.shared.deleteHabitFreeze(token: authManager.token, habitId: habit.id, freezeId: freeze.id)
await MainActor.run { freezes.removeAll { $0.id == freeze.id } }
}
func formatFreezeDate(_ s: String) -> String {
let parts = s.prefix(10).split(separator: "-")
guard parts.count == 3 else { return String(s.prefix(10)) }
return "\(parts[2]).\(parts[1]).\(parts[0])"
}
func toggleArchive() async {
let params: [String: Any] = ["is_archived": !(habit.isArchived == true)]
if let body = try? JSONSerialization.data(withJSONObject: params) {

View File

@@ -12,7 +12,7 @@ struct HabitsView: View {
var body: some View {
ZStack {
Color(hex: "0a0a1a").ignoresSafeArea()
Color(hex: "06060f").ignoresSafeArea()
VStack(spacing: 0) {
HStack {
VStack(alignment: .leading) {
@@ -59,7 +59,7 @@ struct HabitsView: View {
.sheet(isPresented: $showAddHabit) {
AddHabitView(isPresented: $showAddHabit) { await loadHabits(refresh: true) }
.presentationDetents([.large]).presentationDragIndicator(.visible)
.presentationBackground(Color(hex: "0a0a1a"))
.presentationBackground(Color(hex: "06060f"))
}
}