Add insert button for links
This commit is contained in:
60
CHDataManagement/Views/Generic/TagPickerView.swift
Normal file
60
CHDataManagement/Views/Generic/TagPickerView.swift
Normal 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)
|
||||
}
|
30
CHDataManagement/Views/Generic/TagPropertyView.swift
Normal file
30
CHDataManagement/Views/Generic/TagPropertyView.swift
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user