Fixes & optimizations

This commit is contained in:
Thomas Ricouard 2023-12-13 12:37:07 +01:00
parent 232e031559
commit 8d7b6f382e
3 changed files with 21 additions and 22 deletions

View file

@ -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)
}

View file

@ -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, +)
}

View file

@ -273,6 +273,7 @@ public struct TimelineView: View {
ToolbarItem(placement: .topBarTrailing) {
switch timeline {
case let .hashtag(tag, _):
if !tagGroups.isEmpty {
Menu {
Section("tag-groups.edit.section.title") {
ForEach(tagGroups) { group in
@ -291,6 +292,7 @@ public struct TimelineView: View {
} label: {
Image(systemName: "ellipsis")
}
}
default:
EmptyView()
}