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 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 struct SearchResult: Codable {
public let results: [Result] public let results: [Result]
public let status: String public let status: String
public let errorMessage: String?
public struct Result: Codable { public struct Result: Codable {
public let addressComponents: [AddressComponent] public let addressComponents: [AddressComponent]
public let formattedAddress: String public let formattedAddress: String
@ -48,6 +55,12 @@ public struct SearchResult: Codable {
case types case types
} }
} }
private enum CodingKeys: String, CodingKey {
case results = "results"
case status = "status"
case errorMessage = "error_message"
}
} }
public struct Timezone: Codable { public struct Timezone: Codable {

4
Clocker/Onboarding/OnboardingSearchController.swift

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

16
Clocker/Preferences/General/PreferencesViewController.swift

@ -481,22 +481,28 @@ extension PreferencesViewController {
return return
} }
guard let data = response else { guard let data = response, let searchResults = data.decode() else {
assertionFailure("Data was unexpectedly nil") assertionFailure("Data was unexpectedly nil")
return return
} }
let searchResults = data.decode() // let searchResults = data.decode()
if searchResults?.status == "ZERO_RESULTS" { if searchResults.status == ResultStatus.zeroResults {
self.findLocalSearchResultsForTimezones() self.findLocalSearchResultsForTimezones()
self.placeholderLabel.placeholderString = self.searchResultsDataSource.timezoneFilteredArray.isEmpty ? "No results! πŸ˜” Try entering the exact name." : CLEmptyString self.placeholderLabel.placeholderString = self.searchResultsDataSource.timezoneFilteredArray.isEmpty ? "No results! πŸ˜” Try entering the exact name." : CLEmptyString
self.reloadSearchResults() self.reloadSearchResults()
self.isActivityInProgress = false self.isActivityInProgress = false
return 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.findLocalSearchResultsForTimezones()
self.prepareUIForPresentingResults() self.prepareUIForPresentingResults()
} }
@ -670,7 +676,7 @@ extension PreferencesViewController {
return false return false
} }
if let status = unwrapped["status"] as? String, status == "ZERO_RESULTS" { if let status = unwrapped["status"] as? String, status == ResultStatus.zeroResults {
setErrorPlaceholders() setErrorPlaceholders()
return true return true
} }

Loading…
Cancel
Save