ChWebsiteApp/CHDataManagement/Views/Files/FileContentView.swift
2024-12-05 09:17:33 +01:00

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