Files
honeyDueKMP/iosApp/iosApp/Subviews/Task/DynamicTaskCard.swift
Trey t 2baf5484e0 Add task completion history feature and UI improvements
- Add CompletionHistorySheet for viewing task completion history (Android & iOS)
- Update TaskCard and DynamicTaskCard with completion history access
- Add getTaskCompletions API endpoint to TaskApi and APILayer
- Update models (CustomTask, Document, TaskCompletion, User) for Go API alignment
- Improve TaskKanbanView with completion history integration
- Update iOS TaskViewModel with completion history loading

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 12:01:56 -06:00

243 lines
8.4 KiB
Swift

import SwiftUI
import ComposeApp
/// Task card that dynamically renders buttons based on the column's button types
struct DynamicTaskCard: View {
let task: TaskResponse
let buttonTypes: [String]
let onEdit: () -> Void
let onCancel: () -> Void
let onUncancel: () -> Void
let onMarkInProgress: () -> Void
let onComplete: () -> Void
let onArchive: () -> Void
let onUnarchive: () -> Void
@State private var showCompletionHistory = false
var body: some View {
let _ = print("📋 DynamicTaskCard - Task: \(task.title), ButtonTypes: \(buttonTypes)")
VStack(alignment: .leading, spacing: 12) {
HStack {
VStack(alignment: .leading, spacing: 4) {
Text(task.title)
.font(.title3)
.foregroundColor(.primary)
if let status = task.status {
StatusBadge(status: status.name)
}
}
Spacer()
PriorityBadge(priority: task.priority?.name ?? "")
}
if !task.description_.isEmpty {
Text(task.description_)
.font(.subheadline)
.foregroundColor(Color.appTextSecondary)
.lineLimit(2)
}
HStack {
Label(task.frequency?.displayName ?? "", systemImage: "repeat")
.font(.caption)
.foregroundColor(Color.appTextSecondary)
Spacer()
if let due_date = task.dueDate {
Label(formatDate(due_date), systemImage: "calendar")
.font(.caption)
.foregroundColor(Color.appTextSecondary)
}
}
// Actions row with completion count button and actions menu
if !buttonTypes.isEmpty || task.completionCount > 0 {
Divider()
HStack(spacing: 12) {
// Actions menu
if !buttonTypes.isEmpty {
Menu {
menuContent
} label: {
HStack {
Image(systemName: "ellipsis.circle.fill")
.font(.title3)
Text("Actions")
.fontWeight(.medium)
}
.frame(maxWidth: .infinity)
.padding(.vertical, 12)
.background(Color.appPrimary.opacity(0.1))
.foregroundColor(Color.appPrimary)
.cornerRadius(8)
.overlay(
RoundedRectangle(cornerRadius: 8)
.stroke(Color.appPrimary, lineWidth: 2)
)
}
.zIndex(10)
.menuOrder(.fixed)
}
// Completion count button - shows when count > 0
if task.completionCount > 0 {
Button(action: {
showCompletionHistory = true
}) {
HStack(spacing: 6) {
Image(systemName: "checkmark.circle.fill")
.font(.title3)
Text("\(task.completionCount)")
.fontWeight(.bold)
}
.padding(.horizontal, 16)
.padding(.vertical, 12)
.background(Color.appAccent.opacity(0.1))
.foregroundColor(Color.appAccent)
.cornerRadius(8)
.overlay(
RoundedRectangle(cornerRadius: 8)
.stroke(Color.appAccent, lineWidth: 2)
)
}
}
}
}
}
.padding(16)
.background(Color.appBackgroundSecondary)
.cornerRadius(12)
.shadow(color: Color.black.opacity(0.1), radius: 5, x: 0, y: 2)
.simultaneousGesture(TapGesture(), including: .subviews)
.sheet(isPresented: $showCompletionHistory) {
CompletionHistorySheet(
taskTitle: task.title,
taskId: task.id,
isPresented: $showCompletionHistory
)
.presentationDetents([.medium, .large])
.presentationDragIndicator(.visible)
}
}
private func formatDate(_ dateString: String) -> String {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
if let date = formatter.date(from: dateString) {
formatter.dateStyle = .medium
return formatter.string(from: date)
}
return dateString
}
// MARK: - Menu Content
@ViewBuilder
private var menuContent: some View {
// Primary actions
ForEach(Array(buttonTypes.enumerated()), id: \.offset) { index, buttonType in
if isPrimaryAction(buttonType) {
menuButton(for: buttonType)
}
}
// Secondary actions (if any exist)
if buttonTypes.contains(where: { isSecondaryAction($0) }) {
Divider()
ForEach(Array(buttonTypes.enumerated()), id: \.offset) { index, buttonType in
if isSecondaryAction(buttonType) {
menuButton(for: buttonType)
}
}
}
// Destructive actions (if any exist)
if buttonTypes.contains(where: { isDestructiveAction($0) }) {
Divider()
ForEach(Array(buttonTypes.enumerated()), id: \.offset) { index, buttonType in
if isDestructiveAction(buttonType) {
menuButton(for: buttonType)
}
}
}
}
private func isPrimaryAction(_ buttonType: String) -> Bool {
["mark_in_progress", "complete", "edit", "uncancel", "unarchive"].contains(buttonType)
}
private func isSecondaryAction(_ buttonType: String) -> Bool {
["archive"].contains(buttonType)
}
private func isDestructiveAction(_ buttonType: String) -> Bool {
["cancel"].contains(buttonType)
}
@ViewBuilder
private func menuButton(for buttonType: String) -> some View {
switch buttonType {
case "mark_in_progress":
Button {
print("🔵 Mark In Progress tapped for task: \(task.id)")
onMarkInProgress()
} label: {
Label("Mark Task In Progress", systemImage: "play.circle")
}
case "complete":
Button {
print("✅ Complete tapped for task: \(task.id)")
onComplete()
} label: {
Label("Complete Task", systemImage: "checkmark.circle")
}
case "edit":
Button {
print("✏️ Edit tapped for task: \(task.id)")
onEdit()
} label: {
Label("Edit Task", systemImage: "pencil")
}
case "cancel":
Button(role: .destructive) {
print("❌ Cancel tapped for task: \(task.id)")
onCancel()
} label: {
Label("Cancel Task", systemImage: "xmark.circle")
}
case "uncancel":
Button {
print("🔄 Restore tapped for task: \(task.id)")
onUncancel()
} label: {
Label("Restore Task", systemImage: "arrow.uturn.backward.circle")
}
case "archive":
Button {
print("📦 Archive tapped for task: \(task.id)")
onArchive()
} label: {
Label("Archive Task", systemImage: "archivebox")
}
case "unarchive":
Button {
print("📤 Unarchive tapped for task: \(task.id)")
onUnarchive()
} label: {
Label("Unarchive Task", systemImage: "arrow.up.bin")
}
default:
EmptyView()
}
}
}