From b18182453a497b2db77336f131f5e22c6a8a913a Mon Sep 17 00:00:00 2001 From: David <62899351+davidclaveau@users.noreply.github.com> Date: Tue, 13 Feb 2024 14:06:03 -0800 Subject: [PATCH] fix issue with journey details toggle not deleting waterbodies --- .../WatercraftInspectionViewController.swift | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ipad/ViewControllers/Watercraft Inspections/WatercraftInspectionViewController.swift b/ipad/ViewControllers/Watercraft Inspections/WatercraftInspectionViewController.swift index ca8ca60..d002d45 100644 --- a/ipad/ViewControllers/Watercraft Inspections/WatercraftInspectionViewController.swift +++ b/ipad/ViewControllers/Watercraft Inspections/WatercraftInspectionViewController.swift @@ -1408,16 +1408,30 @@ extension WatercraftInspectionViewController: UICollectionViewDataSource, UIColl private func getJourneyDetailsCellType(for indexPath: IndexPath) -> JourneyDetailsSectionRow { guard let model = self.model else {return .Divider} - // If the prev commercial/unknown/stored are toggled off, we delete the cities from model + // If the prev commercial/unknown/stored are toggled OFF, we delete the cities from model if !arePreviousTogglesChecked(ref: model) && model.previousWaterBodies.isEmpty { model.deleteMajorCity(isPrevious: true) } - // If the dest commercial/unknown/stored are toggled off, we delete the cities from model + // If the prev commercial/unknown/stored are toggled ON, we delete the waterbodies from model + if arePreviousTogglesChecked(ref: model) && !model.previousWaterBodies.isEmpty { + for index in stride(from: model.previousWaterBodies.count - 1, through: 0, by: -1) { + model.removePreviousWaterBody(at: index) + } + } + + // If the dest commercial/unknown/stored are toggled OFF, we delete the cities from model if !areDestinationTogglesChecked(ref: model) && model.destinationWaterBodies.isEmpty { model.deleteMajorCity(isPrevious: false) } + // If the dest commercial/unknown/stored are toggled ON, we delete the waterbodies from model + if areDestinationTogglesChecked(ref: model) && !model.destinationWaterBodies.isEmpty { + for index in stride(from: model.destinationWaterBodies.count - 1, through: 0, by: -1) { + model.removeDestinationWaterBody(at: index) + } + } + // Header for "Journey Details" always at top if indexPath.row == 0 { return .Header