Add insert button for links

This commit is contained in:
Christoph Hagen
2025-02-27 22:51:49 +01:00
parent cdc84cdf4c
commit b08303cd12
5 changed files with 226 additions and 5 deletions

View File

@ -0,0 +1,60 @@
import SwiftUI
struct TagPickerView: View {
@EnvironmentObject
private var content: Content
@Environment(\.language)
private var language
@Environment(\.dismiss)
var dismiss
@Binding var selectedTag: Tag?
@State
private var newSelection: Tag?
init(selectedTag: Binding<Tag?>) {
self._selectedTag = selectedTag
self.newSelection = selectedTag.wrappedValue
// TODO: Fix assignment not working
}
var body: some View {
VStack {
Text("Select a tag to link to")
List(content.tags, selection: $newSelection) { tag in
let loc = tag.localized(in: language)
Text("\(loc.title) (\(tag.id))")
.tag(tag)
}
.frame(minHeight: 300)
HStack {
Button("Use selection") {
DispatchQueue.main.async {
self.selectedTag = self.newSelection
dismiss()
}
}
Button("Remove tag", role: .destructive) {
DispatchQueue.main.async {
self.selectedTag = nil
dismiss()
}
}
Button("Cancel", role: .cancel) {
dismiss()
}
}
}
.navigationTitle("Pick a tag")
.padding()
}
}
#Preview {
TagPickerView(selectedTag: .constant(nil))
.environmentObject(Content.mock)
}

View File

@ -0,0 +1,30 @@
import SwiftUI
struct TagPropertyView: View {
let title: LocalizedStringKey
@Binding
var selectedTag: Tag?
let footer: LocalizedStringKey
@State
private var showTagSelectionSheet = false
var body: some View {
GenericPropertyView(title: title, footer: footer) {
HStack {
Text(selectedTag?.id ?? "No tag selected")
Spacer()
Button("Select") {
showTagSelectionSheet = true
}
}
}
.sheet(isPresented: $showTagSelectionSheet) {
TagPickerView(selectedTag: $selectedTag)
}
}
}