Allow videos in posts, simplify post image view
This commit is contained in:
@ -15,7 +15,11 @@ struct PostContentView: View {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
LocalizedPostContentView(post: post)
|
||||
LocalizedPostContentView(
|
||||
post: post.localized(in: language),
|
||||
other: post.localized(in: language.next),
|
||||
tags: $post.tags,
|
||||
page: $post.linkedPage)
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,46 +32,6 @@ extension PostContentView: MainContentView {
|
||||
static let itemDescription = "a post"
|
||||
}
|
||||
|
||||
private struct LocalizedTitle: View {
|
||||
|
||||
@ObservedObject
|
||||
private var post: LocalizedPost
|
||||
|
||||
init(post: LocalizedPost) {
|
||||
self.post = post
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
OptionalTextField("", text: $post.title)
|
||||
.font(.system(size: 24, weight: .bold))
|
||||
.foregroundStyle(Color.primary)
|
||||
.textFieldStyle(.plain)
|
||||
.lineLimit(2)
|
||||
.frame(minHeight: 30)
|
||||
}
|
||||
}
|
||||
|
||||
private struct LocalizedContentEditor: View {
|
||||
|
||||
@ObservedObject
|
||||
private var post: LocalizedPost
|
||||
|
||||
init(post: LocalizedPost) {
|
||||
self.post = post
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
private struct LinkedPageTagView: View {
|
||||
|
||||
@ObservedObject
|
||||
@ -80,42 +44,114 @@ private struct LinkedPageTagView: View {
|
||||
|
||||
struct LocalizedPostContentView: View {
|
||||
|
||||
@ObservedObject
|
||||
var post: Post
|
||||
|
||||
@Environment(\.language)
|
||||
private var language
|
||||
|
||||
@EnvironmentObject
|
||||
private var content: Content
|
||||
|
||||
init(post: Post) {
|
||||
@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")
|
||||
Text("Images/Video")
|
||||
.font(.headline)
|
||||
Button("Transfer from \(language.next.text)", action: copyImagesFromOtherLanguage)
|
||||
.disabled(post.localized(in: language.next).images.isEmpty)
|
||||
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)
|
||||
}
|
||||
PostImagesView(post: post.localized(in: language))
|
||||
LocalizedTitle(post: post.localized(in: language))
|
||||
if let page = post.linkedPage {
|
||||
ScrollView(.horizontal) {
|
||||
HStack(alignment: .center, spacing: 8) {
|
||||
ForEach(post.images) { image in
|
||||
if image.type.isImage {
|
||||
image.imageToDisplay
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.frame(maxWidth: 300, maxHeight: 200)
|
||||
.cornerRadius(8)
|
||||
|
||||
} else {
|
||||
VStack {
|
||||
Image(systemSymbol: .film)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(height: 100)
|
||||
Text(image.id)
|
||||
.font(.title)
|
||||
}
|
||||
//.foregroundStyle(.secondary)
|
||||
.frame(width: 300, height: 200)
|
||||
.background(Color.gray)
|
||||
.cornerRadius(8)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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: $post.tags)
|
||||
TagDisplayView(tags: $tags)
|
||||
}
|
||||
LocalizedContentEditor(post: post.localized(in: language))
|
||||
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() {
|
||||
let images = post.localized(in: language.next).images
|
||||
post.localized(in: language).images = images
|
||||
post.images = other.images
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user