feat: savings tab, fix pull-to-refresh, beautiful modals, fix signing
This commit is contained in:
@@ -4,54 +4,107 @@ 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: Int = 2
|
||||
@State private var isLoading = false
|
||||
|
||||
private let priorities = [(1, "Низкий"), (2, "Средний"), (3, "Высокий"), (4, "Срочный")]
|
||||
|
||||
|
||||
let priorities: [(Int, String, String)] = [
|
||||
(1, "Низкий", "8888aa"),
|
||||
(2, "Средний", "ffa502"),
|
||||
(3, "Высокий", "ff4757"),
|
||||
(4, "Срочный", "ff0000")
|
||||
]
|
||||
|
||||
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(priorities, id: \.0) { p in Text(p.1).tag(p.0) }
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
Spacer()
|
||||
}.padding()
|
||||
}
|
||||
.navigationTitle("Новая задача")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
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
|
||||
HStack {
|
||||
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 }
|
||||
}
|
||||
.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(title.isEmpty ? Color(hex: "8888aa") : Color(hex: "00d4aa")).fontWeight(.semibold) }
|
||||
}
|
||||
.disabled(title.isEmpty || isLoading)
|
||||
}
|
||||
.padding(.horizontal, 20)
|
||||
.padding(.vertical, 16)
|
||||
|
||||
Divider().background(Color.white.opacity(0.1))
|
||||
|
||||
ScrollView {
|
||||
VStack(spacing: 16) {
|
||||
// Title field
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Label("Название", systemImage: "pencil").font(.caption).foregroundColor(Color(hex: "8888aa"))
|
||||
TextField("Что нужно сделать?", text: $title, axis: .vertical)
|
||||
.lineLimit(1...3)
|
||||
.foregroundColor(.white)
|
||||
.padding(14)
|
||||
.background(RoundedRectangle(cornerRadius: 12).fill(Color.white.opacity(0.07)))
|
||||
}
|
||||
|
||||
// Description field
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Label("Описание", systemImage: "text.alignleft").font(.caption).foregroundColor(Color(hex: "8888aa"))
|
||||
TextField("Дополнительные детали...", text: $description, axis: .vertical)
|
||||
.lineLimit(2...5)
|
||||
.foregroundColor(.white)
|
||||
.padding(14)
|
||||
.background(RoundedRectangle(cornerRadius: 12).fill(Color.white.opacity(0.07)))
|
||||
}
|
||||
|
||||
// Priority selector
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Label("Приоритет", systemImage: "flag.fill").font(.caption).foregroundColor(Color(hex: "8888aa"))
|
||||
HStack(spacing: 8) {
|
||||
ForEach(priorities, id: \.0) { p in
|
||||
Button(action: { priority = p.0 }) {
|
||||
Text(p.1)
|
||||
.font(.caption.bold())
|
||||
.foregroundColor(priority == p.0 ? .black : Color(hex: p.2))
|
||||
.padding(.horizontal, 12)
|
||||
.padding(.vertical, 8)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 20)
|
||||
.fill(priority == p.0 ? Color(hex: p.2) : Color(hex: p.2).opacity(0.15))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(20)
|
||||
}
|
||||
}
|
||||
.preferredColorScheme(.dark)
|
||||
}
|
||||
}
|
||||
|
||||
func save() {
|
||||
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 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,13 +76,16 @@ struct TasksView: View {
|
||||
}
|
||||
.sheet(isPresented: $showAddTask) {
|
||||
AddTaskView(isPresented: $showAddTask) { await loadTasks() }
|
||||
.presentationDetents([.medium, .large])
|
||||
.presentationDragIndicator(.visible)
|
||||
.presentationBackground(Color(hex: "0a0a1a"))
|
||||
}
|
||||
.task { await loadTasks() }
|
||||
.refreshable { await loadTasks() }
|
||||
.refreshable { await loadTasks(refresh: true) }
|
||||
}
|
||||
|
||||
func loadTasks() async {
|
||||
isLoading = true
|
||||
func loadTasks(refresh: Bool = false) async {
|
||||
if !refresh { isLoading = true }
|
||||
tasks = (try? await APIService.shared.getTasks(token: authManager.token)) ?? []
|
||||
isLoading = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user