ChWebsiteApp/CHDataManagement/Views/Files/TextFileContentView.swift
2024-12-09 12:18:55 +01:00

39 lines
986 B
Swift

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)")
}
}