Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions WordPress/Classes/ViewRelated/Tags/TagsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import WordPressAPI
import WordPressAPIInternal

protocol TaxonomyServiceProtocol {
func getTags(page: Int, recentlyUsed: Bool) async throws -> [AnyTermWithViewContext]
func getTags(page: Int, recentlyUsed: Bool) async throws -> (terms: [AnyTermWithViewContext], hasMore: Bool)
func searchTags(with query: String) async throws -> [AnyTermWithViewContext]
func createTag(name: String, description: String) async throws -> AnyTermWithViewContext
func updateTag(_ term: AnyTermWithViewContext, name: String, description: String) async throws -> AnyTermWithViewContext
Expand Down Expand Up @@ -38,7 +38,7 @@ class TagsService: TaxonomyServiceProtocol {
func getTags(
page: Int = 0,
recentlyUsed: Bool = false
) async throws -> [AnyTermWithViewContext] {
) async throws -> (terms: [AnyTermWithViewContext], hasMore: Bool) {
guard let remote else {
throw TagsServiceError.noRemoteService
}
Expand All @@ -52,7 +52,8 @@ class TagsService: TaxonomyServiceProtocol {

return try await withCheckedThrowingContinuation { continuation in
remote.getTagsWith(paging, success: { remoteTags in
continuation.resume(returning: remoteTags.map { AnyTermWithViewContext(tag: $0) })
let terms = remoteTags.map { AnyTermWithViewContext(tag: $0) }
continuation.resume(returning: (terms, terms.count == pageSize))
}, failure: { error in
continuation.resume(throwing: error)
})
Expand Down Expand Up @@ -254,7 +255,10 @@ class AnyTermService: TaxonomyServiceProtocol {
self.client = client
}

func getTags(page: Int = 0, recentlyUsed: Bool = false) async throws -> [AnyTermWithViewContext] {
func getTags(
page: Int = 0,
recentlyUsed: Bool = false
) async throws -> (terms: [AnyTermWithViewContext], hasMore: Bool) {
let perPage: UInt32 = 100
let params = TermListParams(
page: UInt32(page + 1),
Expand All @@ -268,7 +272,7 @@ class AnyTermService: TaxonomyServiceProtocol {
params: params
)

return response.data
return (response.data, response.nextPageParams != nil)
}

func searchTags(with query: String) async throws -> [AnyTermWithViewContext] {
Expand Down
6 changes: 3 additions & 3 deletions WordPress/Classes/ViewRelated/Tags/TagsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,16 @@ class TagsViewModel: ObservableObject {
}

let page = pageIndex ?? 0
let remoteTags = try await self.tagsService.getTags(
let result = try await self.tagsService.getTags(
page: page,
recentlyUsed: !self.isBrowseMode
)

let hasMore = remoteTags.count == 100
let hasMore = result.hasMore
let nextPage = hasMore ? page + 1 : nil

return TagsPaginatedResponse.Page(
items: remoteTags,
items: result.terms,
total: nil,
hasMore: hasMore,
nextPage: nextPage
Expand Down