06/22 Fix High impact items
This commit is contained in:
@@ -17,6 +17,46 @@ struct InspectionHistoryView: View {
|
||||
@State private var offset = 0
|
||||
private let limit = 30
|
||||
|
||||
@State private var searchText = ""
|
||||
|
||||
/// Date formatter for search matching — formats to e.g. "Jun 19, 2026 4:55 PM"
|
||||
/// so partial strings like "jun", "2026", "19" all match.
|
||||
private static let searchDateFmt: DateFormatter = {
|
||||
let f = DateFormatter()
|
||||
f.dateStyle = .medium
|
||||
f.timeStyle = .short
|
||||
return f
|
||||
}()
|
||||
|
||||
private func dateString(for insp: APIInspectionSummary) -> String {
|
||||
guard let d = insp.inspectionDateParsed else { return insp.inspectionDate ?? "" }
|
||||
return Self.searchDateFmt.string(from: d)
|
||||
}
|
||||
|
||||
/// Client-side filter over the already-fetched page.
|
||||
/// Matches: ID (exact or #-prefixed), date string (partial), facility
|
||||
/// name, area name (together = "location"). Load More still fetches more
|
||||
/// server pages so the inspector isn't limited to the first 30 results
|
||||
/// when searching by date or location.
|
||||
private var filteredInspections: [APIInspectionSummary] {
|
||||
guard !searchText.isEmpty else { return inspections }
|
||||
let q = searchText.lowercased()
|
||||
return inspections.filter {
|
||||
// ID — match "#12" or bare "12"
|
||||
let idStr = String($0.id)
|
||||
let idMatch = idStr == q || idStr == q.replacingOccurrences(of: "#", with: "")
|
||||
|
||||
// Location = facility name + area name
|
||||
let locationMatch = $0.facilityName.lowercased().contains(q)
|
||||
|| ($0.areaName?.lowercased().contains(q) ?? false)
|
||||
|
||||
return idMatch
|
||||
|| locationMatch
|
||||
|| dateString(for: $0).lowercased().contains(q)
|
||||
|| $0.templateName.lowercased().contains(q)
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
if !sync.isOnline && inspections.isEmpty {
|
||||
@@ -40,15 +80,18 @@ struct InspectionHistoryView: View {
|
||||
systemImage: "clock.arrow.circlepath",
|
||||
description: Text("Completed inspections will appear here after syncing.")
|
||||
)
|
||||
} else if filteredInspections.isEmpty {
|
||||
ContentUnavailableView.search(text: searchText)
|
||||
} else {
|
||||
List {
|
||||
ForEach(inspections) { inspection in
|
||||
ForEach(filteredInspections) { inspection in
|
||||
NavigationLink(value: inspection) {
|
||||
HistoryRowView(inspection: inspection)
|
||||
}
|
||||
}
|
||||
|
||||
// Load more
|
||||
// Load More — still available while searching so the
|
||||
// inspector can expand beyond the current page.
|
||||
if inspections.count < total {
|
||||
HStack {
|
||||
Spacer()
|
||||
@@ -76,6 +119,8 @@ struct InspectionHistoryView: View {
|
||||
}
|
||||
}
|
||||
.navigationTitle("Inspection History")
|
||||
.searchable(text: $searchText,
|
||||
prompt: "Search ID, date, facility, area…")
|
||||
.task {
|
||||
if sync.isOnline {
|
||||
await load(reset: true)
|
||||
|
||||
Reference in New Issue
Block a user