Add visibility property to Tag, improve UI
This commit is contained in:
@ -2,14 +2,25 @@ import SwiftUI
|
||||
|
||||
struct TagDetailView: View {
|
||||
|
||||
@Binding
|
||||
var tagIsVisible: Bool
|
||||
|
||||
@ObservedObject
|
||||
var tag: LocalizedTag
|
||||
|
||||
@EnvironmentObject
|
||||
private var content: Content
|
||||
|
||||
@State
|
||||
private var showImagePicker = false
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
Toggle("Appears in overviews", isOn: $tagIsVisible)
|
||||
.toggleStyle(.switch)
|
||||
.font(.callout)
|
||||
.foregroundStyle(.secondary)
|
||||
|
||||
Text("Name")
|
||||
.font(.callout)
|
||||
.foregroundStyle(.secondary)
|
||||
@ -40,14 +51,23 @@ struct TagDetailView: View {
|
||||
Text("Thumbnail")
|
||||
.font(.callout)
|
||||
.foregroundStyle(.secondary)
|
||||
Text(tag.thumbnail ?? "-")
|
||||
.padding(.top, 1)
|
||||
.padding(.bottom)
|
||||
Button(action: { showImagePicker = true }) {
|
||||
Text(tag.thumbnail?.id ?? "Select")
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.foregroundStyle(.blue)
|
||||
}
|
||||
.padding()
|
||||
.sheet(isPresented: $showImagePicker) {
|
||||
ImagePickerView(showImagePicker: $showImagePicker) { image in
|
||||
tag.thumbnail = image
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
TagDetailView(tag: Tag.mock.english)
|
||||
TagDetailView(
|
||||
tagIsVisible: .constant(true),
|
||||
tag: Tag.mock.english)
|
||||
}
|
||||
|
@ -1,5 +1,20 @@
|
||||
import SwiftUI
|
||||
|
||||
private struct SelectedTagView: View {
|
||||
|
||||
@Environment(\.language)
|
||||
private var language
|
||||
|
||||
@ObservedObject
|
||||
var tag: Tag
|
||||
|
||||
var body: some View {
|
||||
TagDetailView(
|
||||
tagIsVisible: $tag.isVisible,
|
||||
tag: tag.localized(in: language))
|
||||
}
|
||||
}
|
||||
|
||||
struct TagsListView: View {
|
||||
|
||||
@Environment(\.language)
|
||||
@ -20,13 +35,18 @@ struct TagsListView: View {
|
||||
}
|
||||
} detail: {
|
||||
if let selectedTag {
|
||||
TagDetailView(tag: selectedTag.localized(in: language))
|
||||
SelectedTagView(tag: selectedTag)
|
||||
} else {
|
||||
Text("Select a tag to show the details")
|
||||
.font(.largeTitle)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
if selectedTag == nil {
|
||||
selectedTag = content.tags.first
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user