Fix tag assignment in post UI

This commit is contained in:
Christoph Hagen
2025-06-16 10:09:38 +02:00
parent 1d0eba9d78
commit 8508719dbe
13 changed files with 74 additions and 54 deletions

View File

@ -7,5 +7,6 @@ struct LinkedPageTagView: View {
var body: some View {
TagDisplayView(tags: $page.tags)
.id(page.id)
}
}

View File

@ -15,11 +15,24 @@ struct PostContentView: View {
}
var body: some View {
LocalizedPostContentView(
post: post.localized(in: language),
other: post.localized(in: language.next),
tags: $post.tags,
page: $post.linkedPage)
let localized = post.localized(in: language)
let other = post.localized(in: language.next)
VStack(alignment: .leading) {
PostImagesView(
post: localized,
other: other)
PostTitleView(post: localized)
if let page = post.linkedPage {
LinkedPageTagView(page: page)
} else {
TagDisplayView(tags: $post.tags)
}
PostLabelsView(
post: localized,
other: other)
PostTextView(post: localized)
}
.padding()
}
}

View File

@ -47,6 +47,7 @@ struct PostDetailView: View {
footer: "The id is used to link to post and store them",
validation: post.isValid,
update: { post.update(id: $0) })
.id(post.id)
BoolPropertyView(
title: "Draft",
@ -69,6 +70,7 @@ struct PostDetailView: View {
selectedPage: $post.linkedPage,
footer: "The page to open when clicking on the post")
.onChange(of: post.linkedPage) { oldValue, newValue in
if newValue != nil {
post.tags = []
} else {

View File

@ -1,38 +1,22 @@
import SwiftUI
struct LocalizedPostContentView: View {
struct PostImagesView: View {
@Environment(\.language)
private var language
@EnvironmentObject
private var content: Content
@ObservedObject
var post: LocalizedPost
@ObservedObject
var other: LocalizedPost
@Binding
var tags: [Tag]
@Binding
var page: Page?
@State
private var fileTypeToSelect: FileTypeCategory = .image
@State
private var showImagePicker = false
init(post: LocalizedPost, other: LocalizedPost, tags: Binding<[Tag]>, page: Binding<Page?>) {
self.post = post
self.other = other
self._tags = tags
self._page = page
}
var body: some View {
VStack(alignment: .leading) {
HStack {
@ -60,36 +44,11 @@ struct LocalizedPostContentView: View {
}
}
}
OptionalTextField("", text: $post.title)
.font(.system(size: 24, weight: .bold))
.foregroundStyle(Color.primary)
.textFieldStyle(.plain)
.lineLimit(2)
.frame(minHeight: 30)
if let page = page {
LinkedPageTagView(page: page)
} else {
TagDisplayView(tags: $tags)
}
PostLabelsView(post: post, other: other)
TextEditor(text: $post.text)
.font(.body)
.frame(minHeight: 150)
.textEditorStyle(.plain)
.padding(.vertical, 8)
.padding(.leading, 3)
.background(Color.gray.opacity(0.1))
.cornerRadius(8)
}
.padding()
.sheet(isPresented: $showImagePicker) {
MultiFileSelectionView(
selectedFiles: $post.images,
allowedType: fileTypeToSelect)
}
}
private func copyImagesFromOtherLanguage() {
post.images = other.images
}
}

View File

@ -0,0 +1,18 @@
import SwiftUI
struct PostTextView: View {
@ObservedObject
var post: LocalizedPost
var body: some View {
TextEditor(text: $post.text)
.font(.body)
.frame(minHeight: 150)
.textEditorStyle(.plain)
.padding(.vertical, 8)
.padding(.leading, 3)
.background(Color.gray.opacity(0.1))
.cornerRadius(8)
}
}

View File

@ -0,0 +1,16 @@
import SwiftUI
struct PostTitleView: View {
@ObservedObject
var post: LocalizedPost
var body: some View {
OptionalTextField("", text: $post.title)
.font(.system(size: 24, weight: .bold))
.foregroundStyle(Color.primary)
.textFieldStyle(.plain)
.lineLimit(2)
.frame(minHeight: 30)
}
}