Add gpx type, fix file replacement
This commit is contained in:
@@ -108,7 +108,11 @@ final class FileResource: Item, LocalizedItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func save(textContent: String) -> Bool {
|
func save(textContent: String) -> Bool {
|
||||||
content.storage.save(fileContent: textContent, for: id)
|
guard content.storage.save(fileContent: textContent, for: id) else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
modifiedDate = .now
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func dataContent() -> Foundation.Data? {
|
func dataContent() -> Foundation.Data? {
|
||||||
|
@@ -90,6 +90,8 @@ enum FileType: String {
|
|||||||
|
|
||||||
case txt
|
case txt
|
||||||
|
|
||||||
|
case gpx
|
||||||
|
|
||||||
// MARK: Model
|
// MARK: Model
|
||||||
|
|
||||||
case stl
|
case stl
|
||||||
@@ -164,7 +166,7 @@ enum FileType: String {
|
|||||||
return .video
|
return .video
|
||||||
case .mp3, .aac, .m4b, .m4a:
|
case .mp3, .aac, .m4b, .m4a:
|
||||||
return .audio
|
return .audio
|
||||||
case .json, .conf, .yaml, .txt:
|
case .json, .conf, .yaml, .txt, .gpx:
|
||||||
return .text
|
return .text
|
||||||
case .html, .cpp, .swift, .sh, .js, .css:
|
case .html, .cpp, .swift, .sh, .js, .css:
|
||||||
return .code
|
return .code
|
||||||
|
@@ -41,7 +41,7 @@ struct FileContentView: View {
|
|||||||
.foregroundStyle(.secondary)
|
.foregroundStyle(.secondary)
|
||||||
case .text, .code:
|
case .text, .code:
|
||||||
TextFileContentView(file: file)
|
TextFileContentView(file: file)
|
||||||
.id(file.id)
|
.id(file.id + file.modifiedDate.description)
|
||||||
case .video:
|
case .video:
|
||||||
VStack {
|
VStack {
|
||||||
if let image = file.imageToDisplay {
|
if let image = file.imageToDisplay {
|
||||||
|
@@ -11,6 +11,9 @@ struct TextFileContentView: View {
|
|||||||
@State
|
@State
|
||||||
private var loadedFile: String?
|
private var loadedFile: String?
|
||||||
|
|
||||||
|
@State
|
||||||
|
private var loadedFileDate: Date = .now
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
if fileContent != "" {
|
if fileContent != "" {
|
||||||
@@ -47,6 +50,7 @@ struct TextFileContentView: View {
|
|||||||
private func reload() {
|
private func reload() {
|
||||||
fileContent = file.textContent()
|
fileContent = file.textContent()
|
||||||
loadedFile = file.id
|
loadedFile = file.id
|
||||||
|
loadedFileDate = file.modifiedDate
|
||||||
print("Loaded content of file \(file.id)")
|
print("Loaded content of file \(file.id)")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,6 +61,12 @@ struct TextFileContentView: View {
|
|||||||
}
|
}
|
||||||
guard loadedFile == file.id else {
|
guard loadedFile == file.id else {
|
||||||
print("[ERROR] Text File View: Not saving since file changed")
|
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
|
return
|
||||||
}
|
}
|
||||||
guard fileContent != "" else {
|
guard fileContent != "" else {
|
||||||
@@ -67,6 +77,7 @@ struct TextFileContentView: View {
|
|||||||
print("[ERROR] Text File View: Failed to save file \(file.id)")
|
print("[ERROR] Text File View: Failed to save file \(file.id)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
loadedFileDate = file.modifiedDate
|
||||||
print("Text File View: Saved file \(file.id)")
|
print("Text File View: Saved file \(file.id)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user