feat: полноценное Pulse приложение с TabBar

- Auth: переключено на Pulse API (api.digital-home.site) вместо health
- TabBar: Главная, Задачи, Привычки, Здоровье, Финансы
- Models: TaskModels, HabitModels, FinanceModels, обновлённые AuthModels
- Services: APIService (Pulse API), HealthAPIService (health отдельно)
- Dashboard: обзор дня с задачами, привычками, readiness, балансом
- Tasks: список, фильтр, создание, выполнение, удаление
- Habits: список с прогресс-баром, отметка выполнения, стрики
- Health: бывший DashboardView, HealthKit sync через health API key
- Finance: баланс, список транзакций, добавление расхода/дохода
- Health данные через x-api-key вместо JWT токена health сервиса
This commit is contained in:
Cosmo
2026-03-25 11:49:52 +00:00
parent cf0e535639
commit c015824b36
23 changed files with 1090 additions and 202 deletions

View File

@@ -0,0 +1,55 @@
import SwiftUI
struct AddTaskView: View {
@Binding var isPresented: Bool
@EnvironmentObject var authManager: AuthManager
let onAdded: () async -> Void
@State private var title = ""
@State private var description = ""
@State private var priority: TaskPriority = .medium
@State private var isLoading = false
var body: some View {
NavigationView {
ZStack {
Color(hex: "0a0a1a").ignoresSafeArea()
VStack(spacing: 20) {
TextField("Название задачи", text: $title)
.padding().background(Color.white.opacity(0.08)).cornerRadius(12).foregroundColor(.white)
TextField("Описание (необязательно)", text: $description)
.padding().background(Color.white.opacity(0.08)).cornerRadius(12).foregroundColor(.white)
Picker("Приоритет", selection: $priority) {
ForEach(TaskPriority.allCases, id: \.self) { p in Text(p.displayName).tag(p) }
}
.pickerStyle(.segmented)
Spacer()
}.padding()
}
.navigationTitle("Новая задача")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Отмена") { isPresented = false }
}
ToolbarItem(placement: .confirmationAction) {
Button("Добавить") {
isLoading = true
Task {
let req = CreateTaskRequest(
title: title,
description: description.isEmpty ? nil : description,
priority: priority
)
try? await APIService.shared.createTask(token: authManager.token, request: req)
await onAdded()
await MainActor.run { isPresented = false }
}
}
.disabled(title.isEmpty || isLoading)
}
}
.preferredColorScheme(.dark)
}
}
}

View File

@@ -0,0 +1,45 @@
import SwiftUI
struct TaskRowView: View {
let task: PulseTask
let onComplete: () async -> Void
var priorityColor: Color {
switch task.priority {
case .urgent: return Color(hex: "ff0000")
case .high: return Color(hex: "ff4757")
case .medium: return Color(hex: "ffa502")
default: return Color(hex: "8888aa")
}
}
var body: some View {
HStack(spacing: 12) {
Button(action: { Task { await onComplete() } }) {
Image(systemName: task.done ? "checkmark.circle.fill" : "circle")
.font(.title3)
.foregroundColor(task.done ? Color(hex: "00d4aa") : Color(hex: "8888aa"))
}
VStack(alignment: .leading, spacing: 4) {
Text(task.title)
.foregroundColor(task.done ? Color(hex: "8888aa") : .white)
.strikethrough(task.done)
.font(.callout)
if let desc = task.description, !desc.isEmpty {
Text(desc).font(.caption).foregroundColor(Color(hex: "8888aa")).lineLimit(1)
}
if let due = task.dueDate {
Text(due).font(.caption2).foregroundColor(Color(hex: "ffa502"))
}
}
Spacer()
if let priority = task.priority, priority != .low {
Circle().fill(priorityColor).frame(width: 8, height: 8)
}
}
.padding(12)
.background(RoundedRectangle(cornerRadius: 12).fill(Color.white.opacity(0.05)))
.padding(.horizontal)
.padding(.vertical, 2)
}
}

View File

@@ -0,0 +1,95 @@
import SwiftUI
struct TasksView: View {
@EnvironmentObject var authManager: AuthManager
@State private var tasks: [PulseTask] = []
@State private var isLoading = true
@State private var showAddTask = false
@State private var filter: TaskFilter = .pending
enum TaskFilter: String, CaseIterable {
case pending = "Активные"
case completed = "Выполненные"
case all = "Все"
}
var filteredTasks: [PulseTask] {
switch filter {
case .pending: return tasks.filter { !$0.done }
case .completed: return tasks.filter { $0.done }
case .all: return tasks
}
}
var body: some View {
ZStack {
Color(hex: "0a0a1a").ignoresSafeArea()
VStack(spacing: 0) {
// Header
HStack {
Text("Задачи").font(.title.bold()).foregroundColor(.white)
Spacer()
Button(action: { showAddTask = true }) {
Image(systemName: "plus.circle.fill").font(.title2).foregroundColor(Color(hex: "00d4aa"))
}
}.padding()
// Filter
Picker("", selection: $filter) {
ForEach(TaskFilter.allCases, id: \.self) { f in Text(f.rawValue).tag(f) }
}
.pickerStyle(.segmented)
.padding(.horizontal)
.padding(.bottom, 8)
if isLoading {
ProgressView().tint(Color(hex: "00d4aa")).padding(.top, 40)
Spacer()
} else if filteredTasks.isEmpty {
VStack(spacing: 12) {
Text("").font(.system(size: 50))
Text(filter == .pending ? "Нет активных задач" : "Нет задач")
.foregroundColor(Color(hex: "8888aa"))
}.padding(.top, 60)
Spacer()
} else {
List {
ForEach(filteredTasks) { task in
TaskRowView(task: task) { await completeTask(task) }
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
}
.onDelete { indices in
let tasksToDelete = indices.map { filteredTasks[$0] }
Task {
for task in tasksToDelete {
try? await APIService.shared.deleteTask(token: authManager.token, id: task.id)
}
await loadTasks()
}
}
}
.listStyle(.plain)
.scrollContentBackground(.hidden)
}
}
}
.sheet(isPresented: $showAddTask) {
AddTaskView(isPresented: $showAddTask) { await loadTasks() }
}
.task { await loadTasks() }
.refreshable { await loadTasks() }
}
func loadTasks() async {
isLoading = true
tasks = (try? await APIService.shared.getTasks(token: authManager.token)) ?? []
isLoading = false
}
func completeTask(_ task: PulseTask) async {
try? await APIService.shared.completeTask(token: authManager.token, id: task.id)
await loadTasks()
UIImpactFeedbackGenerator(style: .light).impactOccurred()
}
}