From aa0259f33dfb99ae6377e58f184e3ad7c045b1a6 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Wed, 21 Jul 2021 08:34:16 -0400 Subject: [PATCH] Better onboarding! --- Clocker/Onboarding/OnboardingSearchController.swift | 11 +++++++++-- Clocker/Preferences/General/SearchDataSource.swift | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Clocker/Onboarding/OnboardingSearchController.swift b/Clocker/Onboarding/OnboardingSearchController.swift index f6fe97fa..371474c1 100644 --- a/Clocker/Onboarding/OnboardingSearchController.swift +++ b/Clocker/Onboarding/OnboardingSearchController.swift @@ -84,8 +84,9 @@ class OnboardingSearchController: NSViewController { let selectedType = searchResultsDataSource.placeForRow(resultsTableView.selectedRow) switch selectedType { case .city: - let filteredGoogleResult = searchResultsDataSource.retrieveFilteredResultFromGoogleAPI(resultsTableView.selectedRow) - addTimezoneToDefaults(filteredGoogleResult!) + if let filteredGoogleResult = searchResultsDataSource.retrieveFilteredResultFromGoogleAPI(resultsTableView.selectedRow) { + addTimezoneToDefaults(filteredGoogleResult) + } return case .timezone: cleanupAfterInstallingTimezone() @@ -422,6 +423,8 @@ class OnboardingSearchController: NSViewController { private func resetSearchView() { searchResultsDataSource.cleanupFilterArray() + searchResultsDataSource.timezoneFilteredArray = [] + searchResultsDataSource.calculateChangesets() resultsTableView.reloadData() searchBar.stringValue = CLEmptyString searchBar.placeholderString = "Press Enter to Search" @@ -513,4 +516,8 @@ extension OnboardingSearchController: NSSearchFieldDelegate { // return true if the action was handled; otherwise false return false } + + func searchFieldDidEndSearching(_ sender: NSSearchField) { + self.search(sender) + } } diff --git a/Clocker/Preferences/General/SearchDataSource.swift b/Clocker/Preferences/General/SearchDataSource.swift index 2a83a106..93622ec1 100644 --- a/Clocker/Preferences/General/SearchDataSource.swift +++ b/Clocker/Preferences/General/SearchDataSource.swift @@ -75,6 +75,10 @@ class SearchDataSource: NSObject { } func retrieveFilteredResultFromGoogleAPI(_ index: Int) -> TimezoneData? { + if index >= filteredArray.count { + return nil + } + return filteredArray[index % filteredArray.count] }