Show errors during loading
This commit is contained in:
@ -40,9 +40,6 @@ final class Content: ObservableObject {
|
||||
@Published
|
||||
private(set) var shouldGenerateWebsite = false
|
||||
|
||||
@State
|
||||
var selectedFile: FileResource?
|
||||
|
||||
let imageGenerator: ImageGenerator
|
||||
|
||||
init(settings: Settings,
|
||||
@ -136,16 +133,18 @@ final class Content: ObservableObject {
|
||||
tag.remove(file)
|
||||
}
|
||||
settings.remove(file)
|
||||
if selectedFile == file {
|
||||
selectedFile = nil
|
||||
}
|
||||
}
|
||||
|
||||
func file(withOutputPath: String) -> FileResource? {
|
||||
files.first { $0.absoluteUrl == withOutputPath }
|
||||
}
|
||||
|
||||
private let errorPrinter = ErrorPrinter()
|
||||
|
||||
func loadFromDisk(callback: @escaping (_ errors: [String]) -> ()) {
|
||||
defer {
|
||||
storage.contentScope?.delegate = errorPrinter
|
||||
}
|
||||
DispatchQueue.global().async {
|
||||
let loader = ModelLoader(content: self, storage: self.storage)
|
||||
let result = loader.load()
|
||||
|
@ -3,6 +3,8 @@ import SwiftUI
|
||||
|
||||
final class FileResource: Item, LocalizedItem {
|
||||
|
||||
override var itemType: ItemType { .file }
|
||||
|
||||
let type: FileType
|
||||
|
||||
/// Indicate if the file content is stored by the app
|
||||
|
@ -7,6 +7,8 @@ enum ItemType: String, Equatable, Hashable {
|
||||
|
||||
case tag = "tag"
|
||||
|
||||
case file = "file"
|
||||
|
||||
case tagOverview = "tag-overview"
|
||||
}
|
||||
|
||||
|
@ -105,6 +105,12 @@ final class LoadingContext {
|
||||
return nil
|
||||
}
|
||||
return tagOverview
|
||||
case .file:
|
||||
guard let id = itemId.id else {
|
||||
error("Missing file id in itemId")
|
||||
return nil
|
||||
}
|
||||
return file(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,17 @@
|
||||
|
||||
final class LoadingErrorHandler: SecurityBookmarkErrorDelegate {
|
||||
|
||||
let context: LoadingContext
|
||||
|
||||
init(context: LoadingContext) {
|
||||
self.context = context
|
||||
}
|
||||
|
||||
func securityBookmark(error: String) {
|
||||
context.error("\(error)")
|
||||
}
|
||||
}
|
||||
|
||||
final class ModelLoader {
|
||||
|
||||
let content: Content
|
||||
@ -7,10 +20,14 @@ final class ModelLoader {
|
||||
|
||||
let context: LoadingContext
|
||||
|
||||
let errorHandler: LoadingErrorHandler
|
||||
|
||||
init(content: Content, storage: Storage) {
|
||||
self.content = content
|
||||
self.storage = storage
|
||||
self.context = .init(content: content)
|
||||
self.errorHandler = .init(context: context)
|
||||
storage.contentScope?.delegate = errorHandler
|
||||
}
|
||||
|
||||
func load() -> LoadingResult {
|
||||
|
Reference in New Issue
Block a user