diff --git a/CharcoalDemo/CharcoalDemo/DemoTableViewController.swift b/CharcoalDemo/CharcoalDemo/DemoTableViewController.swift index 01b402c2..8a16e479 100644 --- a/CharcoalDemo/CharcoalDemo/DemoTableViewController.swift +++ b/CharcoalDemo/CharcoalDemo/DemoTableViewController.swift @@ -44,11 +44,7 @@ extension DemoTableViewController: UITableViewDelegate { charcoalViewController.freeTextFilterDataSource = self charcoalViewController.freeTextFilterDelegate = self charcoalViewController.searchLocationDataSource = searchLocationDataSource - if let setup = row.setup { - charcoalViewController.filterContainer = setup.filterContainer - charcoalViewController.configure(with: setup.verticals) - charcoalViewController.updateReloadVerticalsButton(isVisible: setup.showVerticalsReloadButton) - } + charcoalViewController.filterContainer = row.setup?.filterContainer charcoalViewController.selectionDelegate = self } else if let viewController = viewController as? DrawerPresentationViewController { let charcoalViewController = viewController.charcoalViewController @@ -56,11 +52,7 @@ extension DemoTableViewController: UITableViewDelegate { charcoalViewController.freeTextFilterDataSource = self charcoalViewController.freeTextFilterDelegate = self charcoalViewController.searchLocationDataSource = searchLocationDataSource - if let setup = row.setup { - charcoalViewController.filterContainer = setup.filterContainer - charcoalViewController.configure(with: setup.verticals) - charcoalViewController.updateReloadVerticalsButton(isVisible: setup.showVerticalsReloadButton) - } + charcoalViewController.filterContainer = row.setup?.filterContainer charcoalViewController.selectionDelegate = self viewController.transitioningDelegate = viewController.transition @@ -87,11 +79,10 @@ extension DemoTableViewController: CharcoalViewControllerSelectionDelegate { return } - if let subVertical = setup.verticals.first(where: { $0.id == vertical.id }) { - setup.current = subVertical + if let submarket = setup.markets.first(where: { $0.id == vertical.id }) { + setup.current = submarket viewController.isLoading = true viewController.filterContainer = setup.filterContainer - viewController.configure(with: setup.verticals) viewController.isLoading = false } } @@ -108,17 +99,8 @@ extension DemoTableViewController: CharcoalViewControllerSelectionDelegate { print("🔥 Did select external filter with key '\(key)' and value '\(value ?? "nil")'") } - func charcoalViewControllerDidSelectReloadVerticals(_ viewController: CharcoalViewController) { - let verticals: [DemoVertical] = .multiple - if let setup = currentRow?.setup { - setup.verticals = verticals - setup.current = verticals.first - } - viewController.updateReloadVerticalsButton(isVisible: false) - viewController.configure(with: verticals) - } - func charcoalViewController(_ viewController: CharcoalViewController, didChangeSelection selection: [URLQueryItem], origin: SelectionChangeOrigin) {} + func charcoalViewController(_ viewController: CharcoalViewController, didSelect selection: CharcoalViewController.MapSelection) {} } extension DemoTableViewController: CharcoalViewControllerTextEditingDelegate { diff --git a/CharcoalDemo/CharcoalDemo/Extensions/FilterContainerExtensions.swift b/CharcoalDemo/CharcoalDemo/Extensions/FilterContainerExtensions.swift index 21ebe5e4..d1093e5d 100644 --- a/CharcoalDemo/CharcoalDemo/Extensions/FilterContainerExtensions.swift +++ b/CharcoalDemo/CharcoalDemo/Extensions/FilterContainerExtensions.swift @@ -9,9 +9,13 @@ extension FilterContainer { rootFilters: [Filter] = defaultRootFilters(), freeTextFilter: Filter? = .freeText, inlineFilter: Filter? = defaultInlineFilter(), - numberOfResults: Int = 123 + numberOfResults: Int = 123, + numberOfVerticals: Int = 4, + lastVerticalIsExternal: Bool = true ) -> FilterContainer { - FilterContainer(rootFilters: rootFilters, freeTextFilter: freeTextFilter, inlineFilter: inlineFilter, numberOfResults: numberOfResults) + let container = FilterContainer(rootFilters: rootFilters, freeTextFilter: freeTextFilter, inlineFilter: inlineFilter, numberOfResults: numberOfResults) + container.verticals = DemoVertical.create(numberOfVerticals, lastVerticalIsExternal: lastVerticalIsExternal) + return container } static func defaultRootFilters(isContextFilters: Bool = false, includePolygonSearch: Bool = true) -> [Filter] { diff --git a/CharcoalDemo/CharcoalDemo/Models/DemoSections.swift b/CharcoalDemo/CharcoalDemo/Models/DemoSections.swift index 0f4dfc98..4367acc8 100644 --- a/CharcoalDemo/CharcoalDemo/Models/DemoSections.swift +++ b/CharcoalDemo/CharcoalDemo/Models/DemoSections.swift @@ -31,9 +31,8 @@ enum DemoSections: CaseIterable { ] case .verticals: return [ - Row(title: "Single vertical", filterContainer: .standard, verticals: .none), - Row(title: "Multiple verticals", filterContainer: .standard, verticals: .multiple), - Row(title: "Failed to load verticals", filterContainer: .standard, verticals: .none, showVerticalsReloadButton: true) + Row(title: "Single vertical", filterContainer: .singleVertical), + Row(title: "Multiple verticals", filterContainer: .multipleVerticals), ] case .misc: return [ @@ -45,7 +44,11 @@ enum DemoSections: CaseIterable { } extension FilterContainer { - static var standard: FilterContainer { + static var singleVertical: FilterContainer { + create(numberOfVerticals: 0) + } + + static var multipleVerticals: FilterContainer { create() } diff --git a/CharcoalDemo/CharcoalDemo/Models/DemoVertical.swift b/CharcoalDemo/CharcoalDemo/Models/DemoVertical.swift index 07437cd9..ac4a430a 100644 --- a/CharcoalDemo/CharcoalDemo/Models/DemoVertical.swift +++ b/CharcoalDemo/CharcoalDemo/Models/DemoVertical.swift @@ -17,18 +17,8 @@ class DemoVertical: Vertical { self.isCurrent = isCurrent self.isExternal = isExternal } -} - -extension Array where Element == DemoVertical { - static var none: [DemoVertical] { - create(0) - } - - static var multiple: [DemoVertical] { - create(4) - } - static func create(_ count: Int = 4, lastVerticalIsExternal: Bool = true) -> [DemoVertical] { + static func create(_ count: Int, lastVerticalIsExternal: Bool) -> [DemoVertical] { guard count >= 1 else { return [] } return (1 ... count).map { let isExternal = lastVerticalIsExternal && count > 1 && ($0 % count == 0) diff --git a/CharcoalDemo/CharcoalDemo/Models/Row.swift b/CharcoalDemo/CharcoalDemo/Models/Row.swift index 5e0c4ea5..ab47be0a 100644 --- a/CharcoalDemo/CharcoalDemo/Models/Row.swift +++ b/CharcoalDemo/CharcoalDemo/Models/Row.swift @@ -20,18 +20,7 @@ struct Row { self.usingBottomSheet = usingBottomSheet } - init( - title: String, - type: UIViewController.Type = CharcoalViewController.self, - filterContainer: FilterContainer, - verticals: [DemoVertical] = .multiple, - showVerticalsReloadButton: Bool = false - ) { - self.init( - title: title, - type: type, - setup: Setup(filterContainer: filterContainer, verticals: verticals, showVerticalsReloadButton: showVerticalsReloadButton), - usingBottomSheet: true - ) + init(title: String, type: UIViewController.Type = CharcoalViewController.self, filterContainer: FilterContainer) { + self.init(title: title, type: type, setup: Setup(filterContainer: filterContainer), usingBottomSheet: true) } } diff --git a/CharcoalDemo/CharcoalDemo/Setup.swift b/CharcoalDemo/CharcoalDemo/Setup.swift index 4e17fc3e..f0b4e51f 100644 --- a/CharcoalDemo/CharcoalDemo/Setup.swift +++ b/CharcoalDemo/CharcoalDemo/Setup.swift @@ -7,8 +7,7 @@ import UIKit class Setup { var filterContainer: FilterContainer - var verticals: [DemoVertical] - let showVerticalsReloadButton: Bool + let markets: [DemoVertical] var current: DemoVertical? { didSet { @@ -17,10 +16,9 @@ class Setup { } } - init(filterContainer: FilterContainer, verticals: [DemoVertical], showVerticalsReloadButton: Bool = false) { - defer { current = verticals.first } + init(filterContainer: FilterContainer) { + defer { current = markets.first } self.filterContainer = filterContainer - self.verticals = verticals - self.showVerticalsReloadButton = showVerticalsReloadButton + markets = (filterContainer.verticals as? [DemoVertical]) ?? [] } } diff --git a/CharcoalDemo/SnapshotTests/FilterContainerTests.swift b/CharcoalDemo/SnapshotTests/FilterContainerTests.swift index 3d58d449..1bc1c633 100644 --- a/CharcoalDemo/SnapshotTests/FilterContainerTests.swift +++ b/CharcoalDemo/SnapshotTests/FilterContainerTests.swift @@ -7,19 +7,10 @@ class FilterContainerTests: XCTestCase { private func snapshot( _ filterContainer: FilterContainer, - verticals: [DemoVertical] = .multiple, - showReloadVerticalsButton: Bool = false, record recording: Bool = false, testName: String = #function ) { - assertSnapshots( - matching: filterContainer, - verticals: verticals, - showReloadVerticalsButton: showReloadVerticalsButton, - delay: 0.1, - record: recording, - testName: testName - ) + assertSnapshots(matching: filterContainer, delay: 0.1, record: recording, testName: testName) } override func setUp() { @@ -32,13 +23,10 @@ class FilterContainerTests: XCTestCase { // MARK: - Tests func testSingleVertical() { - snapshot(.standard, verticals: .none) + snapshot(.singleVertical) } func testMultipleVerticals() { - snapshot(.standard, verticals: .multiple) - } - func testFailedToLoadVerticals() { - snapshot(.standard, verticals: .none, showReloadVerticalsButton: true) + snapshot(.multipleVerticals) } func testContextFilter() { snapshot(.contextFilter) diff --git a/CharcoalDemo/SnapshotTests/XCTestCaseExtensions.swift b/CharcoalDemo/SnapshotTests/XCTestCaseExtensions.swift index f1494f06..4d51f483 100644 --- a/CharcoalDemo/SnapshotTests/XCTestCaseExtensions.swift +++ b/CharcoalDemo/SnapshotTests/XCTestCaseExtensions.swift @@ -29,15 +29,13 @@ extension XCTestCase { func assertSnapshots( matching filterContainer: FilterContainer, - verticals: [DemoVertical], - showReloadVerticalsButton: Bool = false, includeIPad: Bool = true, delay: TimeInterval? = nil, record recording: Bool = false, file: StaticString = #file, testName: String = #function ) { - let viewController = getViewController(for: filterContainer, verticals: verticals, showReloadVerticalsButton: showReloadVerticalsButton) + let viewController = getViewController(for: filterContainer) assertSnapshots( matching: viewController, device: .iPhone, @@ -59,15 +57,9 @@ extension XCTestCase { } } - private func getViewController( - for filterContainer: FilterContainer, - verticals: [DemoVertical], - showReloadVerticalsButton: Bool - ) -> UIViewController { + private func getViewController(for filterContainer: FilterContainer) -> UIViewController { let viewController = CharcoalViewController() viewController.filterContainer = filterContainer - viewController.configure(with: verticals) - viewController.updateReloadVerticalsButton(isVisible: showReloadVerticalsButton) return viewController } } diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testContextFilter.iPad_darkMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testContextFilter.iPad_darkMode.png index e155885a..5fb5dbbb 100644 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testContextFilter.iPad_darkMode.png and b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testContextFilter.iPad_darkMode.png differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testContextFilter.iPad_lightMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testContextFilter.iPad_lightMode.png index a90be983..09b7b4d3 100644 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testContextFilter.iPad_lightMode.png and b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testContextFilter.iPad_lightMode.png differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testContextFilter.iPhone_darkMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testContextFilter.iPhone_darkMode.png index acc8496b..76012d29 100644 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testContextFilter.iPhone_darkMode.png and b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testContextFilter.iPhone_darkMode.png differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testContextFilter.iPhone_lightMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testContextFilter.iPhone_lightMode.png index f9986350..7077e6de 100644 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testContextFilter.iPhone_lightMode.png and b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testContextFilter.iPhone_lightMode.png differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testFailedToLoadVerticals.iPad_darkMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testFailedToLoadVerticals.iPad_darkMode.png deleted file mode 100644 index 4ab51b71..00000000 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testFailedToLoadVerticals.iPad_darkMode.png and /dev/null differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testFailedToLoadVerticals.iPad_lightMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testFailedToLoadVerticals.iPad_lightMode.png deleted file mode 100644 index 32e86e26..00000000 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testFailedToLoadVerticals.iPad_lightMode.png and /dev/null differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testFailedToLoadVerticals.iPhone_darkMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testFailedToLoadVerticals.iPhone_darkMode.png deleted file mode 100644 index e8cbf106..00000000 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testFailedToLoadVerticals.iPhone_darkMode.png and /dev/null differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testFailedToLoadVerticals.iPhone_lightMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testFailedToLoadVerticals.iPhone_lightMode.png deleted file mode 100644 index 2cf3e3f9..00000000 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testFailedToLoadVerticals.iPhone_lightMode.png and /dev/null differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testMultipleVerticals.iPad_darkMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testMultipleVerticals.iPad_darkMode.png index 6653dfe2..ddd2ef0c 100644 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testMultipleVerticals.iPad_darkMode.png and b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testMultipleVerticals.iPad_darkMode.png differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testMultipleVerticals.iPad_lightMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testMultipleVerticals.iPad_lightMode.png index 3119d37e..e241cae7 100644 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testMultipleVerticals.iPad_lightMode.png and b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testMultipleVerticals.iPad_lightMode.png differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testMultipleVerticals.iPhone_darkMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testMultipleVerticals.iPhone_darkMode.png index 8970d239..aeef807d 100644 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testMultipleVerticals.iPhone_darkMode.png and b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testMultipleVerticals.iPhone_darkMode.png differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testMultipleVerticals.iPhone_lightMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testMultipleVerticals.iPhone_lightMode.png index 82f2826a..9ebc0738 100644 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testMultipleVerticals.iPhone_lightMode.png and b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testMultipleVerticals.iPhone_lightMode.png differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testPolygonSearchDisabled.iPad_darkMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testPolygonSearchDisabled.iPad_darkMode.png index 6653dfe2..ddd2ef0c 100644 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testPolygonSearchDisabled.iPad_darkMode.png and b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testPolygonSearchDisabled.iPad_darkMode.png differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testPolygonSearchDisabled.iPad_lightMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testPolygonSearchDisabled.iPad_lightMode.png index 3119d37e..e241cae7 100644 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testPolygonSearchDisabled.iPad_lightMode.png and b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testPolygonSearchDisabled.iPad_lightMode.png differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testPolygonSearchDisabled.iPhone_darkMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testPolygonSearchDisabled.iPhone_darkMode.png index 8970d239..aeef807d 100644 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testPolygonSearchDisabled.iPhone_darkMode.png and b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testPolygonSearchDisabled.iPhone_darkMode.png differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testPolygonSearchDisabled.iPhone_lightMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testPolygonSearchDisabled.iPhone_lightMode.png index 82f2826a..9ebc0738 100644 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testPolygonSearchDisabled.iPhone_lightMode.png and b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testPolygonSearchDisabled.iPhone_lightMode.png differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testSingleVertical.iPad_darkMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testSingleVertical.iPad_darkMode.png index 6653dfe2..ddd2ef0c 100644 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testSingleVertical.iPad_darkMode.png and b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testSingleVertical.iPad_darkMode.png differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testSingleVertical.iPad_lightMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testSingleVertical.iPad_lightMode.png index 3119d37e..e241cae7 100644 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testSingleVertical.iPad_lightMode.png and b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testSingleVertical.iPad_lightMode.png differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testSingleVertical.iPhone_darkMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testSingleVertical.iPhone_darkMode.png index 8970d239..aeef807d 100644 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testSingleVertical.iPhone_darkMode.png and b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testSingleVertical.iPhone_darkMode.png differ diff --git a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testSingleVertical.iPhone_lightMode.png b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testSingleVertical.iPhone_lightMode.png index 82f2826a..9ebc0738 100644 Binary files a/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testSingleVertical.iPhone_lightMode.png and b/CharcoalDemo/SnapshotTests/__Snapshots__/FilterContainerTests/testSingleVertical.iPhone_lightMode.png differ diff --git a/Sources/Charcoal/CharcoalViewController.swift b/Sources/Charcoal/CharcoalViewController.swift index d9416b04..c31cf031 100644 --- a/Sources/Charcoal/CharcoalViewController.swift +++ b/Sources/Charcoal/CharcoalViewController.swift @@ -17,7 +17,8 @@ public protocol CharcoalViewControllerSelectionDelegate: AnyObject { func charcoalViewController(_ viewController: CharcoalViewController, didChangeSelection selection: [URLQueryItem], origin: SelectionChangeOrigin) - func charcoalViewControllerDidSelectReloadVerticals(_ viewController: CharcoalViewController) + func charcoalViewController(_ viewController: CharcoalViewController, + didSelect selection: CharcoalViewController.MapSelection) } public protocol CharcoalViewControllerMapDelegate: AnyObject { @@ -53,6 +54,12 @@ public final class CharcoalViewController: UINavigationController { selectedFilters(in: filterContainer?.allFilters) } + public enum MapSelection { + case openPolygonSearch + case openRadiusSearch + case initialArea + } + // MARK: - Private properties private var selectionHasChanged = false @@ -65,9 +72,8 @@ public final class CharcoalViewController: UINavigationController { }() private var rootFilterViewController: RootFilterViewController? + private var calloutOverlay: CalloutOverlay? - private var verticals: [Vertical]? - private var isReloadVerticalsButtonVisible: Bool? // MARK: - Lifecycle @@ -128,17 +134,6 @@ public final class CharcoalViewController: UINavigationController { } } - public func configure(with verticals: [Vertical]) { - self.verticals = verticals - updateReloadVerticalsButton(isVisible: false) - rootFilterViewController?.configure(with: verticals) - } - - public func updateReloadVerticalsButton(isVisible: Bool) { - isReloadVerticalsButtonVisible = isVisible - rootFilterViewController?.updateReloadVerticalsButton(isVisible: isVisible) - } - // MARK: - Private private func configure(with filterContainer: FilterContainer?) { @@ -156,12 +151,6 @@ public final class CharcoalViewController: UINavigationController { rootFilterViewController?.rootDelegate = self rootFilterViewController?.freeTextFilterDataSource = freeTextFilterDataSource rootFilterViewController?.freeTextFilterDelegate = freeTextFilterDelegate - if let verticals { - rootFilterViewController?.configure(with: verticals) - } - if let isReloadVerticalsButtonVisible { - rootFilterViewController?.updateReloadVerticalsButton(isVisible: isReloadVerticalsButtonVisible) - } setViewControllers([rootFilterViewController].compactMap({ $0 }), animated: false) } } @@ -230,10 +219,6 @@ extension CharcoalViewController: RootFilterViewControllerDelegate { selectionDelegate?.charcoalViewController(self, didSelect: vertical) } - func rootFilterViewControllerDidSelectReloadVerticals(_ viewController: RootFilterViewController) { - selectionDelegate?.charcoalViewControllerDidSelectReloadVerticals(self) - } - private func handleFilterSelectionChange(from origin: SelectionChangeOrigin) { if let filterContainer = filterContainer { let queryItems = selectionStore.queryItems(for: filterContainer) @@ -379,6 +364,11 @@ extension CharcoalViewController: MapFilterViewControllerDelegate { public func mapFilterViewControllerDidDismiss(_ mapFilterViewController: MapFilterViewController) { mapDelegate?.charcoalViewControllerDidDismissMapSearch(self) } + + public func mapFilterViewController(_ mapFilterViewController: MapFilterViewController, + didSelect selection: CharcoalViewController.MapSelection) { + selectionDelegate?.charcoalViewController(self, didSelect: selection) + } } // MARK: - CalloutOverlayDelegate diff --git a/Sources/Charcoal/Filters/Map/MapFilterViewController.swift b/Sources/Charcoal/Filters/Map/MapFilterViewController.swift index 5de0576b..7e91e5c5 100644 --- a/Sources/Charcoal/Filters/Map/MapFilterViewController.swift +++ b/Sources/Charcoal/Filters/Map/MapFilterViewController.swift @@ -5,6 +5,8 @@ import UIKit public protocol MapFilterViewControllerDelegate: AnyObject { + func mapFilterViewController(_ mapFilterViewController: MapFilterViewController, + didSelect selection: CharcoalViewController.MapSelection) func mapFilterViewControllerDidDismiss(_ mapFilterViewController: MapFilterViewController) } @@ -175,6 +177,10 @@ public class MapFilterViewController: FilterViewController { mapPolygonFilterViewController : mapRadiusFilterViewController display(selectedViewController) updateToggleButtonLabel() + + let openedSearch: CharcoalViewController.MapSelection = + selectedViewController == mapRadiusFilterViewController ? .openRadiusSearch : .openPolygonSearch + mapFilterDelegate?.mapFilterViewController(self, didSelect: openedSearch) } private func updateToggleButtonLabel() { @@ -216,6 +222,10 @@ extension MapFilterViewController: MapPolygonFilterViewControllerDelegate { delegate?.filterViewControllerWillEndTextEditing(self) } + func mapPolygonFilterViewControllerDidSelectInitialArea(_ mapPolygonFilterViewController: MapPolygonFilterViewController) { + mapFilterDelegate?.mapFilterViewController(self, didSelect: .initialArea) + } + func mapPolygonFilterViewControllerDidSelectFilter(_ mapPolygonFilterViewController: MapPolygonFilterViewController) { mapRadiusFilterViewController.resetFilterValues() } diff --git a/Sources/Charcoal/Filters/Map/Polygon/MapPolygonFilterViewController.swift b/Sources/Charcoal/Filters/Map/Polygon/MapPolygonFilterViewController.swift index 42af1ba1..dbe48668 100644 --- a/Sources/Charcoal/Filters/Map/Polygon/MapPolygonFilterViewController.swift +++ b/Sources/Charcoal/Filters/Map/Polygon/MapPolygonFilterViewController.swift @@ -8,6 +8,7 @@ import UIKit protocol MapPolygonFilterViewControllerDelegate: AnyObject { func mapPolygonFilterViewControllerDidSelectFilter(_ mapPolygonFilterViewController: MapPolygonFilterViewController) + func mapPolygonFilterViewControllerDidSelectInitialArea(_ mapPolygonFilterViewController: MapPolygonFilterViewController) func mapPolygonFilterViewController(_ mapPolygonFilterViewController: MapPolygonFilterViewController, searchIsEnabled: Bool) func mapPolygonFilterViewControllerWillBeginTextEditing(_ mapPolygonFilterViewController: MapPolygonFilterViewController) func mapPolygonFilterViewControllerWillEndTextEditing(_ mapPolygonFilterViewController: MapPolygonFilterViewController) @@ -545,6 +546,7 @@ extension MapPolygonFilterViewController: MapPolygonFilterViewDelegate { mapPolygonFilterView.drawPolygon(with: annotations) mapPolygonFilterView.configure(for: .polygonSelection) updateFilterValues() + delegate?.mapPolygonFilterViewControllerDidSelectInitialArea(self) } func mapPolygonFilterViewDidSelectLocationButton(_ mapPolygonFilterView: MapPolygonFilterView) { diff --git a/Sources/Charcoal/Filters/Root/RootFilterViewController.swift b/Sources/Charcoal/Filters/Root/RootFilterViewController.swift index 7a38dd1b..cfa61dde 100644 --- a/Sources/Charcoal/Filters/Root/RootFilterViewController.swift +++ b/Sources/Charcoal/Filters/Root/RootFilterViewController.swift @@ -12,7 +12,6 @@ protocol RootFilterViewControllerDelegate: AnyObject { func rootFilterViewController(_ viewController: RootFilterViewController, didSelectFreeTextFilter filter: Filter) func rootFilterViewController(_ viewController: RootFilterViewController, didSelectSuggestionAt index: Int, filter: Filter) func rootFilterViewController(_ viewController: RootFilterViewController, didSelectVertical vertical: Vertical) - func rootFilterViewControllerDidSelectReloadVerticals(_ viewController: RootFilterViewController) } final class RootFilterViewController: FilterViewController { @@ -60,17 +59,6 @@ final class RootFilterViewController: FilterViewController { return button }() - private lazy var reloadButton: UIBarButtonItem = { - let button = UIBarButtonItem( - title: "root.loadVerticals".localized(), - style: .plain, - target: self, - action: #selector(reloadTapped) - ) - button.setTitleTextAttributes([.font: UIFont.bodyStrong, .foregroundColor: UIColor.textAction]) - return button - }() - private lazy var verticalViewController: VerticalListViewController = { let viewController = VerticalListViewController() viewController.delegate = self @@ -88,7 +76,6 @@ final class RootFilterViewController: FilterViewController { // MARK: - Filter private var filterContainer: FilterContainer - private var verticals: [Vertical]? // MARK: - Init @@ -156,23 +143,11 @@ final class RootFilterViewController: FilterViewController { func set(filterContainer: FilterContainer) { self.filterContainer = filterContainer + updateNavigationTitleView() updateBottomButtonTitle() reloadFilters() } - func configure(with verticals: [Vertical]) { - self.verticals = verticals - updateNavigationTitleView() - } - - func updateReloadVerticalsButton(isVisible: Bool) { - if isVisible { - navigationItem.leftBarButtonItem = reloadButton - } else { - navigationItem.leftBarButtonItem = nil - } - } - func showLoadingIndicator(_ show: Bool) { resetButton.isEnabled = !show verticalSelectorView.isEnabled = !show @@ -216,7 +191,7 @@ final class RootFilterViewController: FilterViewController { } private func updateNavigationTitleView() { - if let vertical = verticals?.first(where: { $0.isCurrent }) { + if let vertical = filterContainer.verticals?.first(where: { $0.isCurrent }) { verticalSelectorView.delegate = self verticalSelectorView.configure( withTitle: "root.verticalSelector.title".localized(), @@ -286,10 +261,6 @@ final class RootFilterViewController: FilterViewController { present(alertController, animated: true) } - - @objc private func reloadTapped() { - rootDelegate?.rootFilterViewControllerDidSelectReloadVerticals(self) - } } // MARK: - UITableViewDataSource @@ -407,7 +378,7 @@ extension RootFilterViewController: VerticalSelectorViewDelegate { } private func showVerticalViewController() { - guard let verticals else { return } + guard let verticals = filterContainer.verticals else { return } showResetButton(false) verticalSelectorView.arrowDirection = .up @@ -456,7 +427,7 @@ extension RootFilterViewController: VerticalSelectorViewDelegate { extension RootFilterViewController: VerticalListViewControllerDelegate { func verticalListViewController(_ verticalViewController: VerticalListViewController, didSelectVerticalAtIndex index: Int) { - if let vertical = verticals?[safe: index], !vertical.isCurrent { + if let vertical = filterContainer.verticals?[safe: index], !vertical.isCurrent { freeTextFilterViewController?.searchBar.text = nil hideVerticalViewController() rootDelegate?.rootFilterViewController(self, didSelectVertical: vertical) diff --git a/Sources/Charcoal/Models/FilterContainer.swift b/Sources/Charcoal/Models/FilterContainer.swift index 1b817714..d7abbe40 100644 --- a/Sources/Charcoal/Models/FilterContainer.swift +++ b/Sources/Charcoal/Models/FilterContainer.swift @@ -5,6 +5,10 @@ import Foundation public class FilterContainer { + // MARK: - Public properties + + public var verticals: [Vertical]? + // MARK: - Internal properties public private(set) var rootFilters: [Filter] diff --git a/Sources/Charcoal/Resources/en.lproj/Localizable.strings b/Sources/Charcoal/Resources/en.lproj/Localizable.strings index 9bbcd4b3..de450db7 100644 --- a/Sources/Charcoal/Resources/en.lproj/Localizable.strings +++ b/Sources/Charcoal/Resources/en.lproj/Localizable.strings @@ -26,7 +26,6 @@ "root.title" = "Filter search"; "root.verticalSelector.title" = "More categories"; -"root.loadVerticals" = "Load categories"; "range.slider.lowValueAccessibilityLabel" = "Slider for low value"; "range.slider.highValueAccessibilityLabel" = "Slider for high value"; diff --git a/Sources/Charcoal/Resources/nb.lproj/Localizable.strings b/Sources/Charcoal/Resources/nb.lproj/Localizable.strings index f6aa3916..fb5b485c 100644 --- a/Sources/Charcoal/Resources/nb.lproj/Localizable.strings +++ b/Sources/Charcoal/Resources/nb.lproj/Localizable.strings @@ -26,7 +26,6 @@ "root.title" = "Filtrer søket"; "root.verticalSelector.title" = "Flere kategorier"; -"root.loadVerticals" = "Hent kategorier"; "range.slider.lowValueAccessibilityLabel" = "Slider for lav verdi"; "range.slider.highValueAccessibilityLabel" = "Slider for høy verdi";