Consolidate images and files

This commit is contained in:
Christoph Hagen
2024-12-09 12:18:55 +01:00
parent 394cf7a2e4
commit 4f08526978
77 changed files with 1970 additions and 1619 deletions

View File

@ -1,37 +1,68 @@
import SwiftUI
import SFSafeSymbols
struct FileContentView: View {
private let iconSize: CGFloat = 150
@ObservedObject
var file: FileResource
@EnvironmentObject
private var content: Content
@State
private var fileContent: String = ""
var body: some View {
VStack {
if fileContent != "" {
TextEditor(text: $fileContent)
.font(.body.monospaced())
.textEditorStyle(.plain)
} else {
Text("The file is not a text file")
.onAppear(perform: loadFileContent)
switch file.type {
case .image:
file.imageToDisplay
.resizable()
.aspectRatio(contentMode: .fit)
case .model:
VStack {
Image(systemSymbol: .cubeTransparent)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: iconSize)
Text("No preview available")
.font(.title)
}
.foregroundStyle(.secondary)
case .text, .code:
TextFileContentView(file: file)
.id(file.id)
case .video:
VStack {
Image(systemSymbol: .film)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: iconSize)
Text("No preview available")
.font(.title)
}
.foregroundStyle(.secondary)
case .other:
VStack {
Image(systemSymbol: .docQuestionmark)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: iconSize)
Text("No preview available")
.font(.title)
}
.foregroundStyle(.secondary)
}
}.padding()
}
}
private func loadFileContent() {
do {
fileContent = try content.storage.fileContent(for: file.uniqueId)
} catch {
print(error)
fileContent = ""
}
extension FileContentView: MainContentView {
init(item: FileResource) {
self.file = item
}
static let itemDescription = "a file"
}
#Preview {