Consolidate images and files
This commit is contained in:
38
CHDataManagement/Views/Files/TextFileContentView.swift
Normal file
38
CHDataManagement/Views/Files/TextFileContentView.swift
Normal file
@ -0,0 +1,38 @@
|
||||
import SwiftUI
|
||||
|
||||
struct TextFileContentView: View {
|
||||
|
||||
@ObservedObject
|
||||
var file: FileResource
|
||||
|
||||
@State
|
||||
private var fileContent: String = ""
|
||||
|
||||
var body: some View {
|
||||
if fileContent != "" {
|
||||
TextEditor(text: $fileContent)
|
||||
.font(.body.monospaced())
|
||||
.textEditorStyle(.plain)
|
||||
//.background(.clear)
|
||||
} else {
|
||||
VStack {
|
||||
Image(systemSymbol: .docText)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 150)
|
||||
Text("No preview available")
|
||||
.font(.title)
|
||||
}
|
||||
.foregroundStyle(.secondary)
|
||||
.onAppear(perform: loadFileContent)
|
||||
}
|
||||
}
|
||||
|
||||
private func loadFileContent() {
|
||||
guard fileContent == "" else {
|
||||
return
|
||||
}
|
||||
fileContent = file.textContent()
|
||||
print("Loaded content of file \(file.id)")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user