06/08 Fixed issue that inspection doesn't show photo after flagging the issue
This commit is contained in:
@@ -321,8 +321,20 @@ struct ExecuteInspectionView: View {
|
|||||||
guard inspection.status == "draft" else { return }
|
guard inspection.status == "draft" else { return }
|
||||||
if force { isSaving = true }
|
if force { isSaving = true }
|
||||||
|
|
||||||
|
// Preserve server paths already written by processPhotoQueue — same
|
||||||
|
// logic as submitInspection(). Auto-save fires every 30 s and would
|
||||||
|
// overwrite uploads/... with local://... if it runs after a sync that
|
||||||
|
// was triggered by FlagIssueView uploading the inspection's photos.
|
||||||
|
let existingFormData = inspection.formData
|
||||||
var data: [String: Any] = [:]
|
var data: [String: Any] = [:]
|
||||||
for (k, v) in formValues { data[k] = v }
|
for (k, v) in formValues {
|
||||||
|
if let s = v as? String, s.hasPrefix("local://"),
|
||||||
|
let saved = existingFormData[k] as? String, saved.hasPrefix("uploads/") {
|
||||||
|
data[k] = saved
|
||||||
|
} else {
|
||||||
|
data[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
inspection.formData = data
|
inspection.formData = data
|
||||||
inspection.lastModifiedAt = Date()
|
inspection.lastModifiedAt = Date()
|
||||||
try? context.save()
|
try? context.save()
|
||||||
@@ -339,9 +351,27 @@ struct ExecuteInspectionView: View {
|
|||||||
private func submitInspection() async {
|
private func submitInspection() async {
|
||||||
isSubmitting = true
|
isSubmitting = true
|
||||||
|
|
||||||
// Persist final form data
|
// Persist final form data.
|
||||||
|
// IMPORTANT: formValues is an in-memory SwiftUI state dict that is NOT
|
||||||
|
// updated when processPhotoQueue writes server paths back into
|
||||||
|
// inspection.formData (e.g. during the sync triggered by FlagIssueView).
|
||||||
|
// For any field whose formValues entry is still "local://..." (the photo
|
||||||
|
// hasn't been uploaded yet by THIS submit's sync pass), check whether
|
||||||
|
// processPhotoQueue already wrote a real server path into inspection.formData
|
||||||
|
// for that field. If so, preserve it — otherwise the server path gets
|
||||||
|
// overwritten with "local://..." here and sanitised to "" in APIClient,
|
||||||
|
// making photos disappear on inspections that also flagged an issue.
|
||||||
|
let existingFormData = inspection.formData
|
||||||
var data: [String: Any] = [:]
|
var data: [String: Any] = [:]
|
||||||
for (k, v) in formValues { data[k] = v }
|
for (k, v) in formValues {
|
||||||
|
if let s = v as? String, s.hasPrefix("local://"),
|
||||||
|
let saved = existingFormData[k] as? String, saved.hasPrefix("uploads/") {
|
||||||
|
// processPhotoQueue already uploaded this photo — keep the server path
|
||||||
|
data[k] = saved
|
||||||
|
} else {
|
||||||
|
data[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
inspection.formData = data
|
inspection.formData = data
|
||||||
inspection.overallScore = inspection.computeScore(fromSchema: formSchema)
|
inspection.overallScore = inspection.computeScore(fromSchema: formSchema)
|
||||||
inspection.status = "completed"
|
inspection.status = "completed"
|
||||||
|
|||||||
Reference in New Issue
Block a user