Show file list and contents
This commit is contained in:
39
CHDataManagement/Views/Files/FileContentView.swift
Normal file
39
CHDataManagement/Views/Files/FileContentView.swift
Normal file
@ -0,0 +1,39 @@
|
||||
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)
|
||||
}
|
Reference in New Issue
Block a user