40 lines
857 B
Swift
40 lines
857 B
Swift
import SwiftUI
|
|
|
|
struct FileContentView: View {
|
|
|
|
@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)
|
|
}
|
|
}.padding()
|
|
}
|
|
|
|
private func loadFileContent() {
|
|
do {
|
|
fileContent = try content.storage.fileContent(for: file.uniqueId)
|
|
} catch {
|
|
print(error)
|
|
fileContent = ""
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
FileContentView(file: .mock)
|
|
}
|