Improve content saving, label editing
This commit is contained in:
@ -160,7 +160,7 @@ private struct FileButtonView: View {
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
LabelEditingView(label: content.label)
|
||||
LabelEditingView(label: $content.label)
|
||||
Button("\(content.file?.id ?? "Select file")", action: { showFileSelectionSheet = true })
|
||||
OptionalTextField("", text: $content.downloadedFileName, prompt: "Downloaded file name")
|
||||
.textFieldStyle(.roundedBorder)
|
||||
@ -178,7 +178,7 @@ private struct UrlButtonView: View {
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
LabelEditingView(label: content.label)
|
||||
LabelEditingView(label: $content.label)
|
||||
TextField("", text: $content.url, prompt: Text("URL"))
|
||||
.textFieldStyle(.roundedBorder)
|
||||
}
|
||||
@ -192,7 +192,7 @@ private struct EventButtonView: View {
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
LabelEditingView(label: content.label)
|
||||
LabelEditingView(label: $content.label)
|
||||
TextField("", text: $content.event, prompt: Text("Javascript"))
|
||||
.textFieldStyle(.roundedBorder)
|
||||
}
|
||||
|
@ -35,47 +35,15 @@ struct InsertableLabels: View, InsertableCommandView {
|
||||
}
|
||||
}
|
||||
|
||||
@Environment(\.colorScheme)
|
||||
private var colorScheme
|
||||
|
||||
@ObservedObject
|
||||
private var model: Model
|
||||
|
||||
|
||||
|
||||
init(model: Model) {
|
||||
self.model = model
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 2) {
|
||||
ForEach(model.labels, id: \.icon) { label in
|
||||
HStack {
|
||||
Button(action: { remove(label) }) {
|
||||
Image(systemSymbol: .minusCircleFill)
|
||||
.foregroundStyle(.red)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
LabelEditingView(label: label)
|
||||
}
|
||||
.padding(.vertical, 2)
|
||||
.padding(.horizontal, 8)
|
||||
.background(colorScheme == .light ? Color.white : Color.black)
|
||||
.cornerRadius(8)
|
||||
}
|
||||
Button("Add", action: addLabel)
|
||||
.padding(.vertical, 2)
|
||||
}
|
||||
LabelCreationView(labels: $model.labels)
|
||||
}
|
||||
|
||||
private func addLabel() {
|
||||
model.labels.append(.init(icon: .clockFill, value: "Value"))
|
||||
}
|
||||
|
||||
private func remove(_ label: ContentLabel) {
|
||||
guard let index = model.labels.firstIndex(of: label) else {
|
||||
return
|
||||
}
|
||||
model.labels.remove(at: index)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,54 @@
|
||||
import SwiftUI
|
||||
|
||||
struct LabelCreationView: View {
|
||||
|
||||
@Environment(\.colorScheme)
|
||||
private var colorScheme
|
||||
|
||||
@Binding
|
||||
var labels: [ContentLabel]
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
ForEach($labels) { label in
|
||||
HStack {
|
||||
Button(action: { remove(label.wrappedValue) }) {
|
||||
Image(systemSymbol: .minusCircleFill)
|
||||
.foregroundStyle(.red)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
LabelEditingView(label: label)
|
||||
}
|
||||
.padding(.vertical, 2)
|
||||
.padding(.horizontal, 8)
|
||||
.background(colorScheme == .light ? Color.white : Color.black)
|
||||
.cornerRadius(8)
|
||||
}
|
||||
.onMove(perform: moveLabel)
|
||||
Button("Add new label", action: addLabel)
|
||||
.padding(.vertical, 2)
|
||||
}
|
||||
.frame(minHeight: 250)
|
||||
}
|
||||
|
||||
private func addLabel() {
|
||||
var label = ContentLabel(icon: .statisticsTime, value: "Value")
|
||||
var number = 0
|
||||
while labels.contains(label) {
|
||||
number += 1
|
||||
label.value = "Value \(number)"
|
||||
}
|
||||
labels.append(label)
|
||||
}
|
||||
|
||||
private func remove(_ label: ContentLabel) {
|
||||
guard let index = labels.firstIndex(of: label) else {
|
||||
return
|
||||
}
|
||||
labels.remove(at: index)
|
||||
}
|
||||
|
||||
private func moveLabel(from source: IndexSet, to destination: Int) {
|
||||
labels.move(fromOffsets: source, toOffset: destination)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user