Fixes & optimizations
This commit is contained in:
parent
232e031559
commit
8d7b6f382e
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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, +)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue