Show file list and contents

This commit is contained in:
Christoph Hagen
2024-12-05 09:17:33 +01:00
parent c3309197c0
commit f2d78aef93
8 changed files with 220 additions and 18 deletions

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