96 lines
2.7 KiB
Swift
96 lines
2.7 KiB
Swift
import SwiftUI
|
|
|
|
struct LocalizedPostContentView: 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 {
|
|
Text("Images/Video")
|
|
.font(.headline)
|
|
Button("Images") {
|
|
fileTypeToSelect = .image
|
|
showImagePicker = true
|
|
}
|
|
.disabled(post.hasVideos)
|
|
Button("Videos") {
|
|
fileTypeToSelect = .video
|
|
showImagePicker = true
|
|
}
|
|
.disabled(post.hasImages)
|
|
Button("Transfer from \(language.next.text)") {
|
|
post.images = other.images
|
|
}
|
|
.disabled(other.images.isEmpty)
|
|
}
|
|
ScrollView(.horizontal) {
|
|
HStack(alignment: .center, spacing: 8) {
|
|
ForEach(post.images) { image in
|
|
PostImageView(image: image)
|
|
}
|
|
}
|
|
}
|
|
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
|
|
}
|
|
}
|