Separate post and page view to files
This commit is contained in:
65
CHDataManagement/Views/Posts/PostImageView.swift
Normal file
65
CHDataManagement/Views/Posts/PostImageView.swift
Normal file
@ -0,0 +1,65 @@
|
||||
import SwiftUI
|
||||
|
||||
struct PostImageView: View {
|
||||
|
||||
@ObservedObject
|
||||
var image: FileResource
|
||||
|
||||
var body: some View {
|
||||
if let preview = image.imageToDisplay {
|
||||
preview
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.frame(maxWidth: 300, maxHeight: 200)
|
||||
.cornerRadius(8)
|
||||
} else if image.type.isImage {
|
||||
VStack {
|
||||
Image(systemSymbol: .exclamationmarkTriangle)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(height: 100)
|
||||
Text(image.id)
|
||||
.font(.title)
|
||||
Text("Failed to load image")
|
||||
.font(.body)
|
||||
}
|
||||
.frame(width: 300, height: 200)
|
||||
.background(Color.gray)
|
||||
.cornerRadius(8)
|
||||
} else if image.type.isVideo {
|
||||
VStack {
|
||||
Image(systemSymbol: .film)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(height: 100)
|
||||
Text(image.id)
|
||||
.font(.title)
|
||||
Button("Generate preview") {
|
||||
generateVideoPreview(image)
|
||||
}
|
||||
.font(.body)
|
||||
}
|
||||
.frame(width: 300, height: 200)
|
||||
.background(Color.gray)
|
||||
.cornerRadius(8)
|
||||
} else {
|
||||
VStack {
|
||||
Image(systemSymbol: .exclamationmarkTriangle)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(height: 100)
|
||||
Text(image.id)
|
||||
.font(.title)
|
||||
Text("Invalid media type")
|
||||
.font(.body)
|
||||
}
|
||||
.frame(width: 300, height: 200)
|
||||
.background(Color.gray)
|
||||
.cornerRadius(8)
|
||||
}
|
||||
}
|
||||
|
||||
private func generateVideoPreview(_ image: FileResource) {
|
||||
image.createVideoThumbnail()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user