Browse Source

Handle Request Denied case.

pull/113/head
Abhishek 3 years ago
parent
commit
bde5f1f86b
  1. 15
      Clocker/CoreModelKit/Sources/CoreModelKit/SearchResults.swift
  2. 4
      Clocker/Onboarding/OnboardingSearchController.swift
  3. 16
      Clocker/Preferences/General/PreferencesViewController.swift

15
Clocker/CoreModelKit/Sources/CoreModelKit/SearchResults.swift

@ -2,10 +2,17 @@
import Cocoa
public struct ResultStatus {
public static let okay = "OK"
public static let zeroResults = "ZERO_RESULTS"
public static let requestDenied = "REQUEST_DENIED"
}
public struct SearchResult: Codable {
public let results: [Result]
public let status: String
public let errorMessage: String?
public struct Result: Codable {
public let addressComponents: [AddressComponent]
public let formattedAddress: String
@ -48,6 +55,12 @@ public struct SearchResult: Codable {
case types
}
}
private enum CodingKeys: String, CodingKey {
case results = "results"
case status = "status"
case errorMessage = "error_message"
}
}
public struct Timezone: Codable {

4
Clocker/Onboarding/OnboardingSearchController.swift

@ -182,7 +182,7 @@ class OnboardingSearchController: NSViewController {
return true
}
if let status = unwrapped["status"] as? String, status == "ZERO_RESULTS" {
if let status = unwrapped["status"] as? String, status == ResultStatus.zeroResults {
setErrorPlaceholders()
return true
}
@ -365,7 +365,7 @@ class OnboardingSearchController: NSViewController {
let searchResults = data.decode()
if searchResults?.status == "ZERO_RESULTS" {
if searchResults?.status == ResultStatus.zeroResults {
self.setInfoLabel("No results! 😔 Try entering the exact name.")
setupForError()
return

16
Clocker/Preferences/General/PreferencesViewController.swift

@ -481,22 +481,28 @@ extension PreferencesViewController {
return
}
guard let data = response else {
guard let data = response, let searchResults = data.decode() else {
assertionFailure("Data was unexpectedly nil")
return
}
let searchResults = data.decode()
// let searchResults = data.decode()
if searchResults?.status == "ZERO_RESULTS" {
if searchResults.status == ResultStatus.zeroResults {
self.findLocalSearchResultsForTimezones()
self.placeholderLabel.placeholderString = self.searchResultsDataSource.timezoneFilteredArray.isEmpty ? "No results! 😔 Try entering the exact name." : CLEmptyString
self.reloadSearchResults()
self.isActivityInProgress = false
return
} else if searchResults.status == ResultStatus.requestDenied && searchResults.results.isEmpty {
self.findLocalSearchResultsForTimezones()
self.placeholderLabel.placeholderString = self.searchResultsDataSource.timezoneFilteredArray.isEmpty ? "Update Clocker to get a faster experience 😃" : CLEmptyString
self.reloadSearchResults()
self.isActivityInProgress = false
return
}
self.appendResultsToFilteredArray(searchResults!.results)
self.appendResultsToFilteredArray(searchResults.results)
self.findLocalSearchResultsForTimezones()
self.prepareUIForPresentingResults()
}
@ -670,7 +676,7 @@ extension PreferencesViewController {
return false
}
if let status = unwrapped["status"] as? String, status == "ZERO_RESULTS" {
if let status = unwrapped["status"] as? String, status == ResultStatus.zeroResults {
setErrorPlaceholders()
return true
}

Loading…
Cancel
Save