Skip to content

Instantly share code, notes, and snippets.

@mathonsunday
Last active June 8, 2021 21:53
Show Gist options
  • Save mathonsunday/785381df5e290ec1fb9c9b6061aefa8e to your computer and use it in GitHub Desktop.
Save mathonsunday/785381df5e290ec1fb9c9b6061aefa8e to your computer and use it in GitHub Desktop.
private func loadMoreListings() {
if listingViewModelsLegacy.value == nil {
loadingEvents.on(.next(.loadingList))
}
guard let searchQuery = SearchQuery.deepCopy(model: searchQuery) else {
return
}
currentListRequest?.cancel()
currentListRequest = nil
searchQuery.geography = nil
searchQuery.num = 25
searchQuery.start = 0
searchQuery.sortOrder = .l1ScoreConsumerDown
searchQuery.agentSearch = nil
searchQuery.includeInContract = true
searchQuery.centerPoint = nil
searchQuery.mapSearchProperties = nil
searchQuery.latestTransactionOnly = false
searchQuery.connectedGeos = nil
searchQuery.facetFieldNames = [SearchQueryFacetConstants.fieldKeys.comingSoon.rawValue]
searchQuery.zoomLevel = nil
let request = SearchRelationsRequest()
request.searchQuery = searchQuery
request.relationTypes = [.boards]
currentListRequest = userListingRelationService.listSearchRelations(request: request, onNext: { [weak self] response, source in
guard source == .network else {
return
}
self?.update(listingRelations: response.listingRelations ?? [])
if let totalResults = response.totalNumResults {
self?.totalResults.value = totalResults
}
if self?.totalResults.value == 0 {
self?.loadingEvents.on(.next(.pageLoaded(page: .zero)))
return
}
self?.loadingEvents.on(.next(.idle))
}, onError: { [weak self] error in
if error.code == NSURLErrorCancelled {
return
}
self?.loadingEvents.on(.next(.idle))
})
}
private func update(listingRelations: [ProcessedListingRelation]) {
let showStar = true
let newListings = ListingCardViewModelLegacy.fromListingRelations(listingRelations,
isAgent: user?.isAgent ?? false,
photoInteractionEnabled: true,
isSelectable: false,
showStar: showStar)
listingViewModelsLegacy.value = newListings.nilIfEmpty
loadingEvents.on(.next(.pageLoaded(page: Page.zero)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment