Add gpx type, fix file replacement

This commit is contained in:
Christoph Hagen
2025-04-29 16:57:02 +02:00
parent 3c7681b769
commit f3de1b72b6
4 changed files with 20 additions and 3 deletions

View File

@ -41,7 +41,7 @@ struct FileContentView: View {
.foregroundStyle(.secondary)
case .text, .code:
TextFileContentView(file: file)
.id(file.id)
.id(file.id + file.modifiedDate.description)
case .video:
VStack {
if let image = file.imageToDisplay {

View File

@ -11,6 +11,9 @@ struct TextFileContentView: View {
@State
private var loadedFile: String?
@State
private var loadedFileDate: Date = .now
var body: some View {
VStack {
if fileContent != "" {
@ -47,6 +50,7 @@ struct TextFileContentView: View {
private func reload() {
fileContent = file.textContent()
loadedFile = file.id
loadedFileDate = file.modifiedDate
print("Loaded content of file \(file.id)")
}
@ -57,6 +61,12 @@ struct TextFileContentView: View {
}
guard loadedFile == file.id else {
print("[ERROR] Text File View: Not saving since file changed")
reload()
return
}
guard loadedFileDate == file.modifiedDate else {
print("Text File View: Not saving changed file \(file.id)")
reload()
return
}
guard fileContent != "" else {
@ -67,6 +77,7 @@ struct TextFileContentView: View {
print("[ERROR] Text File View: Failed to save file \(file.id)")
return
}
loadedFileDate = file.modifiedDate
print("Text File View: Saved file \(file.id)")
}
}