diff --git a/Packages/DesignSystem/Sources/DesignSystem/Views/TagChartView.swift b/Packages/DesignSystem/Sources/DesignSystem/Views/TagChartView.swift index 1d124ba9..38be3c10 100644 --- a/Packages/DesignSystem/Sources/DesignSystem/Views/TagChartView.swift +++ b/Packages/DesignSystem/Sources/DesignSystem/Views/TagChartView.swift @@ -3,15 +3,17 @@ import Charts import Models public struct TagChartView: View { - let tag: Tag + @State private var sortedHistory: [Tag.History] = [] public init(tag: Tag) { - self.tag = tag + _sortedHistory = .init(initialValue: tag.history.sorted { + Int($0.day) ?? 0 < Int($1.day) ?? 0 + }) } public var body: some View { - Chart(tag.sortedHistory) { data in - AreaMark(x: .value("day", tag.sortedHistory.firstIndex(where: { $0.id == data.id }) ?? 0), + Chart(sortedHistory) { data in + AreaMark(x: .value("day", sortedHistory.firstIndex(where: { $0.id == data.id }) ?? 0), y: .value("uses", Int(data.uses) ?? 0)) .interpolationMethod(.catmullRom) } diff --git a/Packages/Models/Sources/Models/Tag.swift b/Packages/Models/Sources/Models/Tag.swift index 987dc124..0069dc41 100644 --- a/Packages/Models/Sources/Models/Tag.swift +++ b/Packages/Models/Sources/Models/Tag.swift @@ -27,11 +27,6 @@ public struct Tag: Codable, Identifiable, Equatable, Hashable { public let following: Bool public let history: [History] - public var sortedHistory: [History] { - history.sorted { - Int($0.day) ?? 0 < Int($1.day) ?? 0 - } - } public var totalUses: Int { history.compactMap { Int($0.uses) }.reduce(0, +) } diff --git a/Packages/Timeline/Sources/Timeline/TimelineView.swift b/Packages/Timeline/Sources/Timeline/TimelineView.swift index 36778e58..77ead6ab 100644 --- a/Packages/Timeline/Sources/Timeline/TimelineView.swift +++ b/Packages/Timeline/Sources/Timeline/TimelineView.swift @@ -273,23 +273,25 @@ public struct TimelineView: View { ToolbarItem(placement: .topBarTrailing) { switch timeline { case let .hashtag(tag, _): - Menu { - Section("tag-groups.edit.section.title") { - ForEach(tagGroups) { group in - Button { - if group.tags.contains(tag) { - group.tags.removeAll(where: { $0 == tag }) - } else { - group.tags.append(tag) + if !tagGroups.isEmpty { + Menu { + Section("tag-groups.edit.section.title") { + ForEach(tagGroups) { group in + Button { + if group.tags.contains(tag) { + group.tags.removeAll(where: { $0 == tag }) + } else { + group.tags.append(tag) + } + } label: { + Label(group.title, + systemImage: group.tags.contains(tag) ? "checkmark.rectangle.fill" : "checkmark.rectangle") } - } label: { - Label(group.title, - systemImage: group.tags.contains(tag) ? "checkmark.rectangle.fill" : "checkmark.rectangle") } } + } label: { + Image(systemName: "ellipsis") } - } label: { - Image(systemName: "ellipsis") } default: EmptyView()