ios ui refactor

This commit is contained in:
Trey t
2025-11-05 17:15:17 -06:00
parent 1d48a9bff1
commit 86c89121e1
24 changed files with 1086 additions and 634 deletions

View File

@@ -147,377 +147,6 @@ struct ResidenceDetailView: View {
}
}
struct PropertyHeaderCard: View {
let residence: Residence
var body: some View {
VStack(alignment: .leading, spacing: 16) {
HStack {
Image(systemName: "house.fill")
.font(.title2)
.foregroundColor(.blue)
VStack(alignment: .leading, spacing: 4) {
Text(residence.name)
.font(.title2)
.fontWeight(.bold)
Text(residence.propertyType)
.font(.caption)
.foregroundColor(.secondary)
}
Spacer()
}
Divider()
// Address
VStack(alignment: .leading, spacing: 4) {
Label(residence.streetAddress, systemImage: "mappin.circle.fill")
.font(.subheadline)
Text("\(residence.city), \(residence.stateProvince) \(residence.postalCode)")
.font(.subheadline)
.foregroundColor(.secondary)
if !residence.country.isEmpty {
Text(residence.country)
.font(.caption)
.foregroundColor(.secondary)
}
}
// Property Details
if let bedrooms = residence.bedrooms,
let bathrooms = residence.bathrooms {
Divider()
HStack(spacing: 24) {
PropertyDetailItem(icon: "bed.double.fill", value: "\(bedrooms)", label: "Beds")
PropertyDetailItem(icon: "shower.fill", value: String(format: "%.1f", bathrooms), label: "Baths")
if let sqft = residence.squareFootage {
PropertyDetailItem(icon: "square.fill", value: "\(sqft)", label: "Sq Ft")
}
}
}
}
.padding(20)
.background(Color.blue.opacity(0.1))
.cornerRadius(16)
}
}
struct PropertyDetailItem: View {
let icon: String
let value: String
let label: String
var body: some View {
VStack(spacing: 4) {
Image(systemName: icon)
.font(.caption)
.foregroundColor(.blue)
Text(value)
.font(.subheadline)
.fontWeight(.semibold)
Text(label)
.font(.caption2)
.foregroundColor(.secondary)
}
}
}
struct TasksSection: View {
let tasksResponse: TasksByResidenceResponse
@Binding var showCancelledTasks: Bool
let onEditTask: (TaskDetail) -> Void
let onCancelTask: (TaskDetail) -> Void
let onUncancelTask: (TaskDetail) -> Void
var body: some View {
VStack(alignment: .leading, spacing: 12) {
HStack {
Text("Tasks")
.font(.title2)
.fontWeight(.bold)
Spacer()
// Task Summary Pills
HStack(spacing: 8) {
TaskPill(count: tasksResponse.summary.total, label: "Total", color: .blue)
TaskPill(count: tasksResponse.summary.pending, label: "Pending", color: .orange)
TaskPill(count: tasksResponse.summary.completed, label: "Done", color: .green)
}
}
// Active Tasks
if tasksResponse.tasks.isEmpty && tasksResponse.cancelledTasks.isEmpty {
EmptyTasksView()
} else {
ForEach(tasksResponse.tasks, id: \.id) { task in
TaskCard(
task: task,
onEdit: { onEditTask(task) },
onCancel: { onCancelTask(task) },
onUncancel: nil
)
}
// Cancelled Tasks Section
if !tasksResponse.cancelledTasks.isEmpty {
VStack(alignment: .leading, spacing: 12) {
HStack {
Label("Cancelled Tasks (\(tasksResponse.cancelledTasks.count))", systemImage: "xmark.circle")
.font(.headline)
.foregroundColor(.red)
Spacer()
Button(showCancelledTasks ? "Hide" : "Show") {
showCancelledTasks.toggle()
}
.font(.subheadline)
}
.padding(.top, 8)
if showCancelledTasks {
ForEach(tasksResponse.cancelledTasks, id: \.id) { task in
TaskCard(
task: task,
onEdit: { onEditTask(task) },
onCancel: nil,
onUncancel: { onUncancelTask(task) }
)
}
}
}
}
}
}
}
}
struct TaskPill: View {
let count: Int32
let label: String
let color: Color
var body: some View {
HStack(spacing: 4) {
Text("\(count)")
.font(.caption)
.fontWeight(.bold)
Text(label)
.font(.caption2)
}
.padding(.horizontal, 8)
.padding(.vertical, 4)
.background(color.opacity(0.2))
.foregroundColor(color)
.cornerRadius(8)
}
}
struct TaskCard: View {
let task: TaskDetail
let onEdit: () -> Void
let onCancel: (() -> Void)?
let onUncancel: (() -> Void)?
var body: some View {
VStack(alignment: .leading, spacing: 12) {
HStack {
VStack(alignment: .leading, spacing: 4) {
Text(task.title)
.font(.headline)
.foregroundColor(.primary)
if let status = task.status {
StatusBadge(status: status.name)
}
}
Spacer()
PriorityBadge(priority: task.priority.name)
}
if let description = task.description_, !description.isEmpty {
Text(description)
.font(.subheadline)
.foregroundColor(.secondary)
.lineLimit(2)
}
HStack {
Label(task.frequency.displayName, systemImage: "repeat")
.font(.caption)
.foregroundColor(.secondary)
Spacer()
Label(formatDate(task.dueDate), systemImage: "calendar")
.font(.caption)
.foregroundColor(.secondary)
}
// Completion count
if task.completions.count > 0 {
Divider()
HStack {
Image(systemName: "checkmark.circle")
.foregroundColor(.green)
Text("Completed \(task.completions.count) time\(task.completions.count == 1 ? "" : "s")")
.font(.caption)
.foregroundColor(.secondary)
}
}
if task.showCompletedButton {
Button(action: {}) {
HStack {
Image(systemName: "checkmark.circle.fill")
.resizable()
.frame(width: 20, height: 20)
Text("Complete Task")
.font(.title3.weight(.semibold))
}
.frame(maxWidth: .infinity)
}
.buttonStyle(.borderedProminent)
.cornerRadius(12)
}
// Action Buttons
HStack(spacing: 8) {
Button(action: onEdit) {
Label("Edit", systemImage: "pencil")
.font(.subheadline)
.frame(maxWidth: .infinity)
}
.buttonStyle(.bordered)
if let onCancel = onCancel {
Button(action: onCancel) {
Label("Cancel", systemImage: "xmark.circle")
.font(.subheadline)
.frame(maxWidth: .infinity)
}
.buttonStyle(.bordered)
.tint(.red)
} else if let onUncancel = onUncancel {
Button(action: onUncancel) {
Label("Restore", systemImage: "arrow.uturn.backward")
.font(.subheadline)
.frame(maxWidth: .infinity)
}
.buttonStyle(.borderedProminent)
.tint(.blue)
}
}
}
.padding(16)
.background(Color(.systemBackground))
.cornerRadius(12)
.shadow(color: Color.black.opacity(0.05), radius: 3, x: 0, y: 2)
}
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
}
}
struct StatusBadge: View {
let status: String
var body: some View {
Text(formatStatus(status))
.font(.caption)
.padding(.horizontal, 8)
.padding(.vertical, 4)
.background(statusColor.opacity(0.2))
.foregroundColor(statusColor)
.cornerRadius(6)
}
private func formatStatus(_ status: String) -> String {
switch status {
case "in_progress": return "In Progress"
default: return status.capitalized
}
}
private var statusColor: Color {
switch status {
case "completed": return .green
case "in_progress": return .blue
case "pending": return .orange
case "cancelled": return .red
default: return .gray
}
}
}
struct PriorityBadge: View {
let priority: String
var body: some View {
HStack(spacing: 4) {
Image(systemName: "exclamationmark.circle.fill")
.font(.caption2)
Text(priority.capitalized)
.font(.caption)
.fontWeight(.medium)
}
.padding(.horizontal, 8)
.padding(.vertical, 4)
.background(priorityColor.opacity(0.2))
.foregroundColor(priorityColor)
.cornerRadius(6)
}
private var priorityColor: Color {
switch priority.lowercased() {
case "high": return .red
case "medium": return .orange
case "low": return .green
default: return .gray
}
}
}
struct EmptyTasksView: View {
var body: some View {
VStack(spacing: 12) {
Image(systemName: "checkmark.circle")
.font(.system(size: 48))
.foregroundColor(.gray.opacity(0.5))
Text("No tasks yet")
.font(.subheadline)
.foregroundColor(.secondary)
}
.frame(maxWidth: .infinity)
.padding(32)
.background(Color(.systemBackground))
.cornerRadius(12)
}
}
#Preview {
NavigationView {
ResidenceDetailView(residenceId: 1)