- Add TaskTemplate model with category grouping support - Add TaskTemplateApi for fetching templates from backend - Add TaskSuggestionDropdown component for Android task form - Add TaskTemplatesBrowserSheet for browsing all templates - Add TaskSuggestionsView and TaskTemplatesBrowserView for iOS - Update DataManager to cache task templates - Update APILayer with template fetch and search methods - Update TaskFormView (iOS) with template suggestions - Update AddTaskDialog (Android) with template suggestions - Update onboarding task view to use templates 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
103 lines
3.8 KiB
Swift
103 lines
3.8 KiB
Swift
import SwiftUI
|
|
import ComposeApp
|
|
|
|
/// Inline dropdown showing filtered task template suggestions
|
|
struct TaskSuggestionsView: View {
|
|
let suggestions: [TaskTemplate]
|
|
let onSelect: (TaskTemplate) -> Void
|
|
let maxSuggestions: Int
|
|
|
|
init(
|
|
suggestions: [TaskTemplate],
|
|
onSelect: @escaping (TaskTemplate) -> Void,
|
|
maxSuggestions: Int = 5
|
|
) {
|
|
self.suggestions = suggestions
|
|
self.onSelect = onSelect
|
|
self.maxSuggestions = maxSuggestions
|
|
}
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
ForEach(Array(suggestions.prefix(maxSuggestions).enumerated()), id: \.element.id) { index, template in
|
|
Button {
|
|
onSelect(template)
|
|
} label: {
|
|
HStack(spacing: 12) {
|
|
// Category-colored icon
|
|
Image(systemName: template.iconIos.isEmpty ? "checklist" : template.iconIos)
|
|
.font(.system(size: 18))
|
|
.foregroundColor(categoryColor(for: template.categoryName))
|
|
.frame(width: 28, height: 28)
|
|
|
|
// Task info
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text(template.title)
|
|
.font(.subheadline)
|
|
.fontWeight(.medium)
|
|
.foregroundColor(Color.appTextPrimary)
|
|
.lineLimit(1)
|
|
|
|
HStack(spacing: 4) {
|
|
Text(template.categoryName)
|
|
.font(.caption)
|
|
.foregroundColor(Color.appTextSecondary)
|
|
|
|
Text("•")
|
|
.font(.caption)
|
|
.foregroundColor(Color.appTextSecondary)
|
|
|
|
Text(template.frequencyDisplay)
|
|
.font(.caption)
|
|
.foregroundColor(Color.appTextSecondary)
|
|
}
|
|
}
|
|
|
|
Spacer()
|
|
|
|
// Chevron
|
|
Image(systemName: "chevron.right")
|
|
.font(.caption)
|
|
.foregroundColor(Color.appTextSecondary)
|
|
}
|
|
.padding(.horizontal, 12)
|
|
.padding(.vertical, 10)
|
|
.contentShape(Rectangle())
|
|
}
|
|
.buttonStyle(.plain)
|
|
|
|
// Divider between items (not after last item)
|
|
if index < min(suggestions.count, maxSuggestions) - 1 {
|
|
Divider()
|
|
.padding(.leading, 52)
|
|
}
|
|
}
|
|
}
|
|
.background(Color.appBackgroundSecondary)
|
|
.clipShape(RoundedRectangle(cornerRadius: 10))
|
|
.shadow(color: Color.black.opacity(0.1), radius: 4, x: 0, y: 2)
|
|
}
|
|
|
|
private func categoryColor(for categoryName: String) -> Color {
|
|
switch categoryName.lowercased() {
|
|
case "plumbing": return Color.appSecondary
|
|
case "safety", "electrical": return Color.appError
|
|
case "hvac": return Color.appPrimary
|
|
case "appliances": return Color.appAccent
|
|
case "exterior", "lawn & garden": return Color(hex: "#34C759") ?? .green
|
|
case "interior": return Color(hex: "#AF52DE") ?? .purple
|
|
case "general", "seasonal": return Color(hex: "#FF9500") ?? .orange
|
|
default: return Color.appPrimary
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
VStack(spacing: 20) {
|
|
Text("Preview requires backend templates to be loaded")
|
|
.foregroundColor(.secondary)
|
|
Spacer()
|
|
}
|
|
.background(Color.appBackgroundPrimary)
|
|
}
|