fix: layout, 409 handling, edit habits/tasks/savings

This commit is contained in:
Cosmo
2026-03-25 18:03:36 +00:00
parent 0d5eef1b87
commit c9bd63d5e7
6 changed files with 563 additions and 0 deletions

View File

@@ -48,6 +48,7 @@ struct HabitListView: View {
@State private var showArchived = false
@State private var errorMsg: String?
@State private var showError = false
@State private var editingHabit: Habit? = nil
var activeHabits: [Habit] { habits.filter { $0.isArchived != true } }
var archivedHabits: [Habit] { habits.filter { $0.isArchived == true } }
@@ -67,6 +68,7 @@ struct HabitListView: View {
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
.listRowInsets(EdgeInsets(top: 3, leading: 16, bottom: 3, trailing: 16))
.onTapGesture { editingHabit = habit }
}
.onDelete { idx in
let toDelete = idx.map { activeHabits[$0] }
@@ -113,6 +115,12 @@ struct HabitListView: View {
.presentationDragIndicator(.visible)
.presentationBackground(Color(hex: "0a0a1a"))
}
.sheet(item: ) { habit in
EditHabitView(isPresented: .constant(true), habit: habit) { await loadHabits(refresh: true) }
.presentationDetents([.large])
.presentationDragIndicator(.visible)
.presentationBackground(Color(hex: 0a0a1a))
}
.alert("Ошибка", isPresented: $showError) { Button("OK", role: .cancel) {} }
message: { Text(errorMsg ?? "") }
}
@@ -136,6 +144,12 @@ struct HabitListView: View {
try await APIService.shared.logHabit(token: authManager.token, id: habit.id)
}
await loadHabits(refresh: true)
} catch APIError.serverError(let code, _) where code == 409 {
await MainActor.run {
if let idx = habits.firstIndex(where: { /bin/bash.id == habit.id }) {
habits[idx].completedToday = true
}
}
} catch { errorMsg = error.localizedDescription; showError = true }
}
@@ -213,6 +227,7 @@ struct TaskListView: View {
@State private var showAddTask = false
@State private var errorMsg: String?
@State private var showError = false
@State private var editingTask: PulseTask? = nil
enum TaskFilter: String, CaseIterable {
case active = "Активные"
@@ -248,6 +263,7 @@ struct TaskListView: View {
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
.listRowInsets(EdgeInsets(top: 2, leading: 16, bottom: 2, trailing: 16))
.onTapGesture { editingTask = task }
}
.onDelete { idx in
let toDelete = idx.map { filtered[$0] }
@@ -282,6 +298,12 @@ struct TaskListView: View {
.presentationDragIndicator(.visible)
.presentationBackground(Color(hex: "0a0a1a"))
}
.sheet(item: ) { task in
EditTaskView(isPresented: .constant(true), task: task) { await loadTasks(refresh: true) }
.presentationDetents([.medium, .large])
.presentationDragIndicator(.visible)
.presentationBackground(Color(hex: 0a0a1a))
}
.alert("Ошибка", isPresented: $showError) { Button("OK", role: .cancel) {} }
message: { Text(errorMsg ?? "") }
}