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 import Models
public struct TagChartView: View { public struct TagChartView: View {
let tag: Tag @State private var sortedHistory: [Tag.History] = []
public init(tag: Tag) { 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 { public var body: some View {
Chart(tag.sortedHistory) { data in Chart(sortedHistory) { data in
AreaMark(x: .value("day", tag.sortedHistory.firstIndex(where: { $0.id == data.id }) ?? 0), AreaMark(x: .value("day", sortedHistory.firstIndex(where: { $0.id == data.id }) ?? 0),
y: .value("uses", Int(data.uses) ?? 0)) y: .value("uses", Int(data.uses) ?? 0))
.interpolationMethod(.catmullRom) .interpolationMethod(.catmullRom)
} }

View file

@ -27,11 +27,6 @@ public struct Tag: Codable, Identifiable, Equatable, Hashable {
public let following: Bool public let following: Bool
public let history: [History] public let history: [History]
public var sortedHistory: [History] {
history.sorted {
Int($0.day) ?? 0 < Int($1.day) ?? 0
}
}
public var totalUses: Int { public var totalUses: Int {
history.compactMap { Int($0.uses) }.reduce(0, +) history.compactMap { Int($0.uses) }.reduce(0, +)
} }

View file

@ -273,23 +273,25 @@ public struct TimelineView: View {
ToolbarItem(placement: .topBarTrailing) { ToolbarItem(placement: .topBarTrailing) {
switch timeline { switch timeline {
case let .hashtag(tag, _): case let .hashtag(tag, _):
Menu { if !tagGroups.isEmpty {
Section("tag-groups.edit.section.title") { Menu {
ForEach(tagGroups) { group in Section("tag-groups.edit.section.title") {
Button { ForEach(tagGroups) { group in
if group.tags.contains(tag) { Button {
group.tags.removeAll(where: { $0 == tag }) if group.tags.contains(tag) {
} else { group.tags.removeAll(where: { $0 == tag })
group.tags.append(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: default:
EmptyView() EmptyView()