From 2fb34f43d0f7311f18931aaf52a24e9b698e5f54 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Sat, 9 Jan 2021 14:18:54 +0300 Subject: [PATCH] Increasing timeout limit. Fixing search filtering --- AutoCat.xcodeproj/project.pbxproj | 4 ++-- AutoCat/Controllers/SearchController.swift | 4 +++- AutoCat/Utils/Api.swift | 9 ++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index b377d04..0226fb0 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -847,7 +847,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 64; + CURRENT_PROJECT_VERSION = 65; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; @@ -870,7 +870,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 64; + CURRENT_PROJECT_VERSION = 65; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; diff --git a/AutoCat/Controllers/SearchController.swift b/AutoCat/Controllers/SearchController.swift index f146316..c53aa91 100644 --- a/AutoCat/Controllers/SearchController.swift +++ b/AutoCat/Controllers/SearchController.swift @@ -44,7 +44,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe //.throttle(.seconds(2), scheduler: MainScheduler.instance) .debounce(.milliseconds(500), scheduler: MainScheduler.instance) .do(onNext: { _ in self.pageLoadingIndicator.startAnimating() }) - .flatMap { Api.getVehicles(with: $0, pageToken: self.datasource.pageToken).catchErrorJustReturn(PagedResponse()) } + .flatMap { Api.getVehicles(with: $0, pageToken: self.datasource.pageToken).do(onError: { print($0) }).catchErrorJustReturn(PagedResponse()) } .observeOn(MainScheduler.instance) .do(onNext: { if let count = $0.count { @@ -89,6 +89,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe guard self.filter.searchString != newQuery else { return } self.filter.searchString = newQuery + self.datasource.reset() self.filterRelay.accept(self.filter) } @@ -100,6 +101,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe controller.filter = self.filter controller.onDone = { self.filter = controller.filter + self.datasource.reset() self.filterRelay.accept(self.filter) } self.navigationController?.pushViewController(controller, animated: true) diff --git a/AutoCat/Utils/Api.swift b/AutoCat/Utils/Api.swift index bdb5df5..c6a34f4 100644 --- a/AutoCat/Utils/Api.swift +++ b/AutoCat/Utils/Api.swift @@ -4,6 +4,13 @@ import RxCocoa class Api { + private static let session: URLSession = { + let sessionConfig = URLSessionConfiguration.default + sessionConfig.timeoutIntervalForRequest = 60.0 + sessionConfig.timeoutIntervalForResource = 60.0 + return URLSession(configuration: sessionConfig) + }() + // MARK: - Private wrappres private static func genError(_ msg: String, suggestion: String, code: Int = 0) -> Error { @@ -39,7 +46,7 @@ class Api { return Single.error(self.genError("Error creating request", suggestion: "")) } - return URLSession.shared.rx.data(request: request).asSingle().map { data in + return self.session.rx.data(request: request).asSingle().map { data in // let str = String(data: data, encoding: .utf8) // print("================================") // if let string = str?.replacingOccurrences(of: "\\\"", with: "\"")