Skip to content

Commit

Permalink
Fix item count for scenario where parent container has a document tha…
Browse files Browse the repository at this point in the history
…t multiple tags matching under the parent container
  • Loading branch information
vincode-io committed Jun 8, 2024
1 parent 5be7ab7 commit 1957f33
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions VinOutlineKit/Sources/VinOutlineKit/TagDocuments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,7 @@ public final class TagDocuments: Identifiable, DocumentContainer {
#endif

public var itemCount: Int? {
guard let tag else { return nil }
var count = account?.documents?.filter({ $0.hasTag(tag) }).count ?? 0

for child in children {
count += child.itemCount ?? 0
}

return count
documents.count
}

public var children = [DocumentContainer]()
Expand All @@ -42,16 +35,14 @@ public final class TagDocuments: Identifiable, DocumentContainer {
public weak var tag: Tag?

public var documents: [Document] {
get async throws {
guard let tag, let documents = account?.documents else { return [] }
var docs = Set(documents.filter { $0.hasTag(tag) })

for child in children {
docs.formUnion(try await child.documents)
}

return Array(docs)
guard let tag, let documents = account?.documents else { return [] }
var docs = Set(documents.filter { $0.hasTag(tag) })

for case let child as TagDocuments in children {
docs.formUnion(child.documents)
}

return Array(docs)
}

public init(account: Account, tag: Tag) {
Expand Down

0 comments on commit 1957f33

Please sign in to comment.