Generate labels from workout

This commit is contained in:
Christoph Hagen
2025-08-22 00:01:51 +02:00
parent 9ec207014c
commit f972a2c020
8 changed files with 108 additions and 14 deletions

View File

@@ -3,7 +3,10 @@ import SwiftUI
struct PostLabelsView: View {
@ObservedObject
var post: LocalizedPost
var post: Post
@ObservedObject
var localized: LocalizedPost
@ObservedObject
var other: LocalizedPost
@@ -17,11 +20,11 @@ struct PostLabelsView: View {
var body: some View {
ScrollView(.horizontal) {
HStack(spacing: 5) {
if post.labels.isEmpty {
if localized.labels.isEmpty {
Text("Labels")
.font(.headline)
}
ForEach(post.labels) { label in
ForEach(localized.labels) { label in
HStack {
PageIconView(icon: label.icon)
.frame(maxWidth: 16, maxHeight: 16)
@@ -45,16 +48,16 @@ struct PostLabelsView: View {
}.buttonStyle(.plain)
if !other.labels.isEmpty {
Button("Transfer") {
post.labels = other.labels.map {
localized.labels = other.labels.map {
// Copy instead of reference
ContentLabel(icon: $0.icon, value: $0.value)
}
}
}
if !post.labels.isEmpty {
if !localized.labels.isEmpty {
Button("Copy") {
var command = "```labels"
for label in post.labels {
for label in localized.labels {
command += "\n\(label.icon.rawValue): \(label.value)"
}
command += "\n```"
@@ -63,23 +66,28 @@ struct PostLabelsView: View {
pasteboard.setString(command, forType: .string)
}
}
if let workout = post.associatedWorkout {
Button("From workout") {
post.updateLabelsFromWorkout()
}
}
}
.padding(.vertical, 2)
}
.sheet(isPresented: $showLabelEditor) {
LabelModificationView(labels: $post.labels)
LabelModificationView(labels: $localized.labels)
}
}
func addLabel() {
post.labels.append(.init(icon: .clockFill, value: "Value"))
localized.labels.append(.init(icon: .clockFill, value: "Value"))
}
func remove(_ label: ContentLabel) {
guard let index = post.labels.firstIndex(of: label) else {
guard let index = localized.labels.firstIndex(of: label) else {
return
}
post.labels.remove(at: index)
localized.labels.remove(at: index)
}
}