mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Add error handling to top-level content view
This commit is contained in:
parent
3a53bec184
commit
a3b805a319
@ -2,11 +2,13 @@ import SwiftUI
|
|||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
@EnvironmentObject var model: WriteFreelyModel
|
@EnvironmentObject var model: WriteFreelyModel
|
||||||
|
@EnvironmentObject var errorHandling: ErrorHandling
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
CollectionListView()
|
CollectionListView()
|
||||||
|
.withErrorHandling()
|
||||||
.toolbar {
|
.toolbar {
|
||||||
Button(
|
Button(
|
||||||
action: {
|
action: {
|
||||||
@ -36,6 +38,7 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
CollectionListView()
|
CollectionListView()
|
||||||
|
.withErrorHandling()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
@ -56,6 +59,18 @@ struct ContentView: View {
|
|||||||
|
|
||||||
Text("Select a post, or create a new local draft.")
|
Text("Select a post, or create a new local draft.")
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
|
|
||||||
|
EmptyView()
|
||||||
|
.onChange(of: model.hasError) { value in
|
||||||
|
if value {
|
||||||
|
if let error = model.currentError {
|
||||||
|
self.errorHandling.handle(error: error)
|
||||||
|
} else {
|
||||||
|
self.errorHandling.handle(error: AppError.genericError)
|
||||||
|
}
|
||||||
|
model.hasError = false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.environmentObject(model)
|
.environmentObject(model)
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ struct WriteFreely_MultiPlatformApp: App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.withErrorHandling()
|
||||||
.environmentObject(model)
|
.environmentObject(model)
|
||||||
.environment(\.managedObjectContext, LocalStorageManager.standard.container.viewContext)
|
.environment(\.managedObjectContext, LocalStorageManager.standard.container.viewContext)
|
||||||
// .preferredColorScheme(preferences.selectedColorScheme) // See PreferencesModel for info.
|
// .preferredColorScheme(preferences.selectedColorScheme) // See PreferencesModel for info.
|
||||||
|
Loading…
Reference in New Issue
Block a user