feat: full Pulse Mobile implementation - all modules
- Phase 0: project.yml fixes (CODE_SIGN_ENTITLEMENTS confirmed) - Phase 1: Enhanced models (HabitModels, TaskModels, FinanceModels, SavingsModels, UserModels) - Phase 1: Enhanced APIService with all endpoints (habits/log/stats, tasks/uncomplete, finance/analytics, savings/*) - Phase 2: DashboardView rewrite - day progress bar, 4 stat cards, habit/task lists with Undo (3 sec) - Phase 3: TrackerView - HabitListView (streak badge, swipe delete, archive), TaskListView (priority, overdue), StatisticsView (heatmap 84 days, line chart, bar chart via Swift Charts) - Phase 4: FinanceView rewrite - month picker, summary card, top expenses progress bars, pie chart, line chart, transactions by day, analytics tab with bar chart + month comparison - Phase 5: SavingsView rewrite - overview with overdue block, categories tab with type icons, operations tab with category filter + add sheet - Phase 6: SettingsView - dark/light theme, profile edit, telegram chat id, notifications toggle + time, timezone picker, logout - Added: AddHabitView with weekly day selector + interval days - Added: AddTaskView with icon/color/due date picker - Haptic feedback on all toggle actions
This commit is contained in:
@@ -4,52 +4,50 @@ struct AddHabitView: View {
|
||||
@Binding var isPresented: Bool
|
||||
@EnvironmentObject var authManager: AuthManager
|
||||
let onAdded: () async -> Void
|
||||
|
||||
|
||||
@State private var name = ""
|
||||
@State private var description = ""
|
||||
@State private var frequency = "daily"
|
||||
@State private var selectedIcon = "🔥"
|
||||
@State private var selectedColor = "#00d4aa"
|
||||
@State private var selectedColor = "#0D9488"
|
||||
@State private var isLoading = false
|
||||
|
||||
@State private var intervalDays = "2"
|
||||
@State private var selectedWeekdays: Set<Int> = [1,2,3,4,5] // Mon-Fri
|
||||
|
||||
let frequencies: [(String, String, String)] = [
|
||||
("daily", "Каждый день", "calendar"),
|
||||
("weekly", "Каждую неделю", "calendar.badge.clock"),
|
||||
("weekly", "По дням недели", "calendar.badge.clock"),
|
||||
("interval", "Каждые N дней", "repeat"),
|
||||
("monthly", "Каждый месяц", "calendar.badge.plus")
|
||||
]
|
||||
|
||||
let icons = ["🔥", "💪", "🏃", "📚", "💧", "🧘", "🎯", "⭐️", "🌟", "✅", "🏋️", "🚴", "🍎", "😴", "🧠", "🎨", "🎵", "💊", "🌿", "💰"]
|
||||
|
||||
let colors = ["#00d4aa", "#7c3aed", "#ff4757", "#ffa502", "#6366f1", "#ec4899", "#14b8a6", "#f59e0b", "#10b981", "#3b82f6"]
|
||||
|
||||
|
||||
let weekdayNames = ["Вс","Пн","Вт","Ср","Чт","Пт","Сб"]
|
||||
|
||||
let icons = ["🔥", "💪", "🏃", "📚", "💧", "🧘", "🎯", "⭐️", "🌟", "✅",
|
||||
"🏋️", "🚴", "🍎", "😴", "🧠", "🎨", "🎵", "💊", "🌿", "💰",
|
||||
"✍️", "🧹", "🏊", "🚶", "🎮", "📝", "🌅", "🥗", "🧃", "🫁"]
|
||||
|
||||
let colors = ["#0D9488", "#7c3aed", "#ff4757", "#ffa502", "#6366f1",
|
||||
"#ec4899", "#14b8a6", "#f59e0b", "#10b981", "#3b82f6"]
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
Color(hex: "0a0a1a").ignoresSafeArea()
|
||||
|
||||
VStack(spacing: 0) {
|
||||
// Handle
|
||||
RoundedRectangle(cornerRadius: 3)
|
||||
.fill(Color.white.opacity(0.2))
|
||||
.frame(width: 40, height: 4)
|
||||
.padding(.top, 12)
|
||||
|
||||
// Header
|
||||
.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 }.foregroundColor(Color(hex: "8888aa"))
|
||||
Spacer()
|
||||
Text("Новая привычка").font(.headline).foregroundColor(.white)
|
||||
Spacer()
|
||||
Button(action: save) {
|
||||
if isLoading { ProgressView().tint(Color(hex: "00d4aa")).scaleEffect(0.8) }
|
||||
else { Text("Добавить").foregroundColor(name.isEmpty ? Color(hex: "8888aa") : Color(hex: "00d4aa")).fontWeight(.semibold) }
|
||||
}
|
||||
.disabled(name.isEmpty || isLoading)
|
||||
if isLoading { ProgressView().tint(Color(hex: "0D9488")).scaleEffect(0.8) }
|
||||
else { Text("Добавить").foregroundColor(name.isEmpty ? Color(hex: "8888aa") : Color(hex: "0D9488")).fontWeight(.semibold) }
|
||||
}.disabled(name.isEmpty || isLoading)
|
||||
}
|
||||
.padding(.horizontal, 20).padding(.vertical, 16)
|
||||
|
||||
Divider().background(Color.white.opacity(0.1))
|
||||
|
||||
ScrollView {
|
||||
VStack(spacing: 20) {
|
||||
// Preview
|
||||
@@ -64,13 +62,14 @@ struct AddHabitView: View {
|
||||
Text(name.isEmpty ? "Название привычки" : name)
|
||||
.font(.callout.bold())
|
||||
.foregroundColor(name.isEmpty ? Color(hex: "8888aa") : .white)
|
||||
Text(frequencies.first { $0.0 == frequency }?.1 ?? "").font(.caption).foregroundColor(Color(hex: "8888aa"))
|
||||
Text(frequencies.first { $0.0 == frequency }?.1 ?? "")
|
||||
.font(.caption).foregroundColor(Color(hex: "8888aa"))
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
.padding(16)
|
||||
.background(RoundedRectangle(cornerRadius: 16).fill(Color.white.opacity(0.05)))
|
||||
|
||||
|
||||
// Name
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Label("Название", systemImage: "pencil").font(.caption).foregroundColor(Color(hex: "8888aa"))
|
||||
@@ -78,7 +77,7 @@ struct AddHabitView: View {
|
||||
.foregroundColor(.white).padding(14)
|
||||
.background(RoundedRectangle(cornerRadius: 12).fill(Color.white.opacity(0.07)))
|
||||
}
|
||||
|
||||
|
||||
// Frequency
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Label("Периодичность", systemImage: "calendar").font(.caption).foregroundColor(Color(hex: "8888aa"))
|
||||
@@ -86,35 +85,62 @@ struct AddHabitView: View {
|
||||
ForEach(frequencies, id: \.0) { f in
|
||||
Button(action: { frequency = f.0 }) {
|
||||
HStack {
|
||||
Image(systemName: f.2).foregroundColor(frequency == f.0 ? Color(hex: "00d4aa") : Color(hex: "8888aa"))
|
||||
Image(systemName: f.2).foregroundColor(frequency == f.0 ? Color(hex: "0D9488") : Color(hex: "8888aa"))
|
||||
Text(f.1).foregroundColor(frequency == f.0 ? .white : Color(hex: "8888aa"))
|
||||
Spacer()
|
||||
if frequency == f.0 {
|
||||
Image(systemName: "checkmark").foregroundColor(Color(hex: "00d4aa"))
|
||||
}
|
||||
if frequency == f.0 { Image(systemName: "checkmark").foregroundColor(Color(hex: "0D9488")) }
|
||||
}
|
||||
.padding(14)
|
||||
.background(RoundedRectangle(cornerRadius: 12).fill(frequency == f.0 ? Color(hex: "00d4aa").opacity(0.15) : Color.white.opacity(0.05)))
|
||||
.background(RoundedRectangle(cornerRadius: 12).fill(frequency == f.0 ? Color(hex: "0D9488").opacity(0.15) : Color.white.opacity(0.05)))
|
||||
}
|
||||
}
|
||||
}
|
||||
// Weekly day selector
|
||||
if frequency == "weekly" {
|
||||
HStack(spacing: 8) {
|
||||
ForEach(0..<7) { i in
|
||||
Button(action: {
|
||||
if selectedWeekdays.contains(i) { if selectedWeekdays.count > 1 { selectedWeekdays.remove(i) } }
|
||||
else { selectedWeekdays.insert(i) }
|
||||
}) {
|
||||
Text(weekdayNames[i])
|
||||
.font(.caption.bold())
|
||||
.foregroundColor(selectedWeekdays.contains(i) ? .black : .white)
|
||||
.frame(width: 32, height: 32)
|
||||
.background(Circle().fill(selectedWeekdays.contains(i) ? Color(hex: "0D9488") : Color.white.opacity(0.08)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Interval days
|
||||
if frequency == "interval" {
|
||||
HStack {
|
||||
Text("Каждые").foregroundColor(Color(hex: "8888aa")).font(.callout)
|
||||
TextField("2", text: $intervalDays).keyboardType(.numberPad)
|
||||
.foregroundColor(.white)
|
||||
.frame(width: 50)
|
||||
.padding(10)
|
||||
.background(RoundedRectangle(cornerRadius: 8).fill(Color.white.opacity(0.07)))
|
||||
Text("дней").foregroundColor(Color(hex: "8888aa")).font(.callout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Icon picker
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Label("Иконка", systemImage: "face.smiling").font(.caption).foregroundColor(Color(hex: "8888aa"))
|
||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 5), spacing: 8) {
|
||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 6), spacing: 8) {
|
||||
ForEach(icons, id: \.self) { icon in
|
||||
Button(action: { selectedIcon = icon }) {
|
||||
Text(icon).font(.title2)
|
||||
.frame(width: 44, height: 44)
|
||||
.background(Circle().fill(selectedIcon == icon ? Color(hex: "00d4aa").opacity(0.25) : Color.white.opacity(0.05)))
|
||||
.overlay(Circle().stroke(selectedIcon == icon ? Color(hex: "00d4aa") : Color.clear, lineWidth: 2))
|
||||
Text(icon).font(.title3)
|
||||
.frame(width: 40, height: 40)
|
||||
.background(Circle().fill(selectedIcon == icon ? Color(hex: "0D9488").opacity(0.25) : Color.white.opacity(0.05)))
|
||||
.overlay(Circle().stroke(selectedIcon == icon ? Color(hex: "0D9488") : Color.clear, lineWidth: 2))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Color picker
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Label("Цвет", systemImage: "paintpalette").font(.caption).foregroundColor(Color(hex: "8888aa"))
|
||||
@@ -131,21 +157,16 @@ struct AddHabitView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(20)
|
||||
}.padding(20)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func save() {
|
||||
isLoading = true
|
||||
Task {
|
||||
var req = URLRequest(url: URL(string: "https://api.digital-home.site/habits")!)
|
||||
req.httpMethod = "POST"
|
||||
req.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
||||
req.setValue("Bearer \(authManager.token)", forHTTPHeaderField: "Authorization")
|
||||
let body: [String: Any] = [
|
||||
var body: [String: Any] = [
|
||||
"name": name,
|
||||
"description": description,
|
||||
"frequency": frequency,
|
||||
@@ -153,8 +174,14 @@ struct AddHabitView: View {
|
||||
"color": selectedColor,
|
||||
"target_count": 1
|
||||
]
|
||||
req.httpBody = try? JSONSerialization.data(withJSONObject: body)
|
||||
_ = try? await URLSession.shared.data(for: req)
|
||||
if frequency == "weekly" {
|
||||
body["target_days"] = Array(selectedWeekdays).sorted()
|
||||
}
|
||||
if frequency == "interval" {
|
||||
body["target_count"] = Int(intervalDays) ?? 2
|
||||
}
|
||||
let reqBody = try? JSONSerialization.data(withJSONObject: body)
|
||||
try? await APIService.shared.createHabit(token: authManager.token, body: reqBody ?? Data())
|
||||
await onAdded()
|
||||
await MainActor.run { isPresented = false }
|
||||
}
|
||||
|
||||
@@ -4,29 +4,25 @@ struct HabitRowView: View {
|
||||
let habit: Habit
|
||||
let onLog: () async -> Void
|
||||
|
||||
var accentColor: Color { Color(hex: habit.color ?? "00d4aa") }
|
||||
var accentColor: Color { Color(hex: habit.accentColorHex.replacingOccurrences(of: "#", with: "")) }
|
||||
var isDone: Bool { habit.completedToday == true }
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 14) {
|
||||
// Icon
|
||||
ZStack {
|
||||
Circle().fill(accentColor.opacity(isDone ? 0.3 : 0.1)).frame(width: 44, height: 44)
|
||||
Text(habit.icon ?? "🔥").font(.title3)
|
||||
Text(habit.displayIcon).font(.title3)
|
||||
}
|
||||
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(habit.name).font(.callout.weight(.medium)).foregroundColor(.white)
|
||||
HStack(spacing: 8) {
|
||||
Text(habit.frequency.displayName).font(.caption).foregroundColor(Color(hex: "8888aa"))
|
||||
Text(habit.frequencyLabel).font(.caption).foregroundColor(Color(hex: "8888aa"))
|
||||
if let streak = habit.currentStreak, streak > 0 {
|
||||
Text("🔥 \(streak)").font(.caption).foregroundColor(Color(hex: "ffa502"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Button(action: { guard !isDone else { return }; Task { await onLog() } }) {
|
||||
Image(systemName: isDone ? "checkmark.circle.fill" : "circle")
|
||||
.font(.title2)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import SwiftUI
|
||||
|
||||
// HabitsView is now used by TrackerView (HabitListView).
|
||||
// This file kept for backward compat but MainTabView uses TrackerView.
|
||||
struct HabitsView: View {
|
||||
@EnvironmentObject var authManager: AuthManager
|
||||
@State private var habits: [Habit] = []
|
||||
@@ -19,43 +21,36 @@ struct HabitsView: View {
|
||||
}
|
||||
Spacer()
|
||||
Button(action: { showAddHabit = true }) {
|
||||
Image(systemName: "plus.circle.fill").font(.title2).foregroundColor(Color(hex: "00d4aa"))
|
||||
Image(systemName: "plus.circle.fill").font(.title2).foregroundColor(Color(hex: "0D9488"))
|
||||
}
|
||||
}.padding()
|
||||
|
||||
// Progress bar
|
||||
if !habits.isEmpty {
|
||||
GeometryReader { geo in
|
||||
ZStack(alignment: .leading) {
|
||||
RoundedRectangle(cornerRadius: 4).fill(Color.white.opacity(0.1))
|
||||
RoundedRectangle(cornerRadius: 4).fill(Color(hex: "00d4aa"))
|
||||
RoundedRectangle(cornerRadius: 4).fill(Color(hex: "0D9488"))
|
||||
.frame(width: geo.size.width * CGFloat(completedCount) / CGFloat(max(habits.count, 1)))
|
||||
}
|
||||
}
|
||||
.frame(height: 6)
|
||||
.padding(.horizontal)
|
||||
.padding(.bottom, 16)
|
||||
.frame(height: 6).padding(.horizontal).padding(.bottom, 16)
|
||||
}
|
||||
|
||||
if isLoading {
|
||||
ProgressView().tint(Color(hex: "00d4aa")).padding(.top, 40)
|
||||
Spacer()
|
||||
ProgressView().tint(Color(hex: "0D9488")).padding(.top, 40); Spacer()
|
||||
} else if habits.isEmpty {
|
||||
VStack(spacing: 12) {
|
||||
Text("🔥").font(.system(size: 50))
|
||||
Text("Нет привычек").foregroundColor(Color(hex: "8888aa"))
|
||||
}.padding(.top, 60)
|
||||
Spacer()
|
||||
}.padding(.top, 60); Spacer()
|
||||
} else {
|
||||
List {
|
||||
ForEach(habits) { habit in
|
||||
HabitRowView(habit: habit) { await logHabit(habit) }
|
||||
.listRowBackground(Color.clear)
|
||||
.listRowSeparator(.hidden)
|
||||
.listRowBackground(Color.clear).listRowSeparator(.hidden)
|
||||
}
|
||||
}
|
||||
.listStyle(.plain)
|
||||
.scrollContentBackground(.hidden)
|
||||
.listStyle(.plain).scrollContentBackground(.hidden)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,8 +58,7 @@ struct HabitsView: View {
|
||||
.refreshable { await loadHabits(refresh: true) }
|
||||
.sheet(isPresented: $showAddHabit) {
|
||||
AddHabitView(isPresented: $showAddHabit) { await loadHabits(refresh: true) }
|
||||
.presentationDetents([.large])
|
||||
.presentationDragIndicator(.visible)
|
||||
.presentationDetents([.large]).presentationDragIndicator(.visible)
|
||||
.presentationBackground(Color(hex: "0a0a1a"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user