Fix id of Items, saving
This commit is contained in:
@ -78,6 +78,10 @@ struct AddFileView: View {
|
||||
}
|
||||
|
||||
private func importSelectedFiles() {
|
||||
guard !filesToAdd.isEmpty else {
|
||||
dismiss()
|
||||
return
|
||||
}
|
||||
for file in filesToAdd {
|
||||
guard file.isSelected else {
|
||||
print("Skipping unselected file \(file.uniqueId)")
|
||||
|
@ -41,7 +41,7 @@ struct FileContentView: View {
|
||||
.foregroundStyle(.secondary)
|
||||
case .text, .code:
|
||||
TextFileContentView(file: file)
|
||||
.id(file.id + file.modifiedDate.description)
|
||||
.id(file.identifier + file.modifiedDate.description)
|
||||
case .video:
|
||||
VStack {
|
||||
if let image = file.imageToDisplay {
|
||||
|
@ -72,11 +72,12 @@ struct FileDetailView: View {
|
||||
}
|
||||
|
||||
IdPropertyView(
|
||||
id: $file.id,
|
||||
id: $file.identifier,
|
||||
title: "Name",
|
||||
footer: "The unique name of the file, which is also used to reference it in posts and pages.",
|
||||
validation: file.isValid,
|
||||
update: { file.update(id: $0) })
|
||||
.id(file.id)
|
||||
|
||||
switch language {
|
||||
case .english:
|
||||
@ -154,7 +155,7 @@ struct FileDetailView: View {
|
||||
}
|
||||
|
||||
private func showFileInFinder() {
|
||||
content.storage.openFinderWindow(withSelectedFile: file.id)
|
||||
content.storage.openFinderWindow(withSelectedFile: file.identifier)
|
||||
}
|
||||
|
||||
private func markFileAsChanged() {
|
||||
@ -169,11 +170,11 @@ struct FileDetailView: View {
|
||||
|
||||
private func replaceFile() {
|
||||
guard let url = openFilePanel() else {
|
||||
print("File '\(file.id)': No file selected as replacement")
|
||||
print("File '\(file.identifier)': No file selected as replacement")
|
||||
return
|
||||
}
|
||||
guard content.storage.importExternalFile(at: url, fileId: file.id) else {
|
||||
print("File '\(file.id)': Failed to replace file")
|
||||
guard content.storage.importExternalFile(at: url, fileId: file.identifier) else {
|
||||
print("File '\(file.identifier)': Failed to replace file")
|
||||
return
|
||||
}
|
||||
|
||||
@ -197,7 +198,7 @@ struct FileDetailView: View {
|
||||
|
||||
let response = panel.runModal()
|
||||
guard response == .OK else {
|
||||
print("File '\(file.id)': Failed to select file to replace")
|
||||
print("File '\(file.identifier)': Failed to select file to replace")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -209,8 +210,8 @@ struct FileDetailView: View {
|
||||
return
|
||||
}
|
||||
|
||||
guard content.storage.removeFileContent(file: file.id) else {
|
||||
print("File '\(file.id)': Failed to delete file to make it external")
|
||||
guard content.storage.removeFileContent(file: file.identifier) else {
|
||||
print("File '\(file.identifier)': Failed to delete file to make it external")
|
||||
return
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
@ -220,8 +221,8 @@ struct FileDetailView: View {
|
||||
}
|
||||
|
||||
private func deleteFile() {
|
||||
guard content.storage.delete(file: file.id) else {
|
||||
print("File '\(file.id)': Failed to delete file in content folder")
|
||||
guard content.storage.delete(file: file.identifier) else {
|
||||
print("File '\(file.identifier)': Failed to delete file in content folder")
|
||||
return
|
||||
}
|
||||
content.remove(file)
|
||||
|
@ -32,7 +32,7 @@ struct FileListView: View {
|
||||
guard !searchString.isEmpty else {
|
||||
return filesBySelectedType
|
||||
}
|
||||
return filesBySelectedType.filter { $0.id.contains(searchString) }
|
||||
return filesBySelectedType.filter { $0.identifier.contains(searchString) }
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@ -55,10 +55,10 @@ struct FileListView: View {
|
||||
LazyVStack(spacing: 0) {
|
||||
ForEach(filteredFiles) { file in
|
||||
SelectableListItem(selected: selectedFile == file) {
|
||||
Text(file.id)
|
||||
Text(file.identifier)
|
||||
.lineLimit(1)
|
||||
}
|
||||
.id(file.id)
|
||||
.id(file.identifier)
|
||||
.onTapGesture {
|
||||
selectedFile = file
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ final class FileToAdd: ObservableObject {
|
||||
}
|
||||
|
||||
var idAlreadyExists: Bool {
|
||||
content.files.contains { $0.id == uniqueId }
|
||||
content.files.contains { $0.identifier == uniqueId }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ struct MultiFileSelectionView: View {
|
||||
guard !searchString.isEmpty else {
|
||||
return filesBySelectedType
|
||||
}
|
||||
return filesBySelectedType.filter { $0.id.contains(searchString) }
|
||||
return filesBySelectedType.filter { $0.identifier.contains(searchString) }
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@ -59,7 +59,7 @@ struct MultiFileSelectionView: View {
|
||||
.foregroundStyle(.red)
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture { deselect(file: file) }
|
||||
Text(file.id)
|
||||
Text(file.identifier)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
@ -99,7 +99,7 @@ struct MultiFileSelectionView: View {
|
||||
Image(systemSymbol: .plusCircleFill)
|
||||
.foregroundStyle(.green)
|
||||
}
|
||||
Text(file.id)
|
||||
Text(file.identifier)
|
||||
Spacer()
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
|
@ -49,9 +49,9 @@ struct TextFileContentView: View {
|
||||
|
||||
private func reload() {
|
||||
fileContent = file.textContent()
|
||||
loadedFile = file.id
|
||||
loadedFile = file.identifier
|
||||
loadedFileDate = file.modifiedDate
|
||||
print("Loaded content of file \(file.id)")
|
||||
print("Loaded content of file \(file.identifier)")
|
||||
}
|
||||
|
||||
private func save() {
|
||||
@ -59,25 +59,25 @@ struct TextFileContentView: View {
|
||||
print("[ERROR] Text File View: No file loaded to save")
|
||||
return
|
||||
}
|
||||
guard loadedFile == file.id else {
|
||||
guard loadedFile == file.identifier 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)")
|
||||
print("Text File View: Not saving changed file \(file.identifier)")
|
||||
reload()
|
||||
return
|
||||
}
|
||||
guard fileContent != "" else {
|
||||
print("Text File View: Not saving empty file \(file.id)")
|
||||
print("Text File View: Not saving empty file \(file.identifier)")
|
||||
return
|
||||
}
|
||||
guard file.save(textContent: fileContent) else {
|
||||
print("[ERROR] Text File View: Failed to save file \(file.id)")
|
||||
print("[ERROR] Text File View: Failed to save file \(file.identifier)")
|
||||
return
|
||||
}
|
||||
loadedFileDate = file.modifiedDate
|
||||
print("Text File View: Saved file \(file.id)")
|
||||
print("Text File View: Saved file \(file.identifier)")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user