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