@@ -5,62 +5,86 @@ struct ContentView: View {
55 @EnvironmentObject var errorHandling : ErrorHandling
66
77 var body : some View {
8- NavigationView {
9- #if os(macOS)
10- CollectionListView ( )
11- . withErrorHandling ( )
12- . toolbar {
13- Button (
14- action: {
15- NSApp . keyWindow? . contentViewController? . tryToPerform (
16- #selector( NSSplitViewController . toggleSidebar ( _: ) ) , with: nil
8+ #if os(macOS)
9+ WFNavigation (
10+ collectionList: {
11+ CollectionListView ( )
12+ . withErrorHandling ( )
13+ . toolbar {
14+ if #available( macOS 13 , * ) {
15+ EmptyView ( )
16+ } else {
17+ Button (
18+ action: {
19+ NSApp . keyWindow? . contentViewController? . tryToPerform (
20+ #selector( NSSplitViewController . toggleSidebar ( _: ) ) , with: nil
21+ )
22+ } ,
23+ label: { Image ( systemName: " sidebar.left " ) }
1724 )
18- } ,
19- label: { Image ( systemName: " sidebar.left " ) }
20- )
21- . help ( " Toggle the sidebar's visibility. " )
22- Spacer ( )
23- Button ( action: {
24- withAnimation {
25- // Un-set the currently selected post
26- self . model. selectedPost = nil
25+ . help ( " Toggle the sidebar's visibility. " )
2726 }
28- // Create the new-post managed object
29- let managedPost = model. editor. generateNewLocalPost ( withFont: model. preferences. font)
30- withAnimation {
31- DispatchQueue . main. async {
32- // Load the new post in the editor
33- self . model. selectedPost = managedPost
27+ Spacer ( )
28+ Button ( action: {
29+ withAnimation {
30+ // Un-set the currently selected post
31+ self . model. selectedPost = nil
32+ }
33+ // Create the new-post managed object
34+ let managedPost = model. editor. generateNewLocalPost ( withFont: model. preferences. font)
35+ withAnimation {
36+ DispatchQueue . main. async {
37+ // Load the new post in the editor
38+ self . model. selectedPost = managedPost
39+ }
3440 }
41+ } , label: { Image ( systemName: " square.and.pencil " ) } )
42+ . help ( " Create a new local draft. " )
43+ }
44+ . frame ( width: 200 )
45+ } ,
46+ postList: {
47+ ZStack {
48+ PostListView ( selectedCollection: model. selectedCollection, showAllPosts: model. showAllPosts)
49+ . withErrorHandling ( )
50+ . frame ( width: 300 )
51+ if model. isProcessingRequest {
52+ ZStack {
53+ Color ( NSColor . controlBackgroundColor) . opacity ( 0.75 )
54+ ProgressView ( )
3555 }
36- } , label: { Image ( systemName: " square.and.pencil " ) } )
37- . help ( " Create a new local draft. " )
38- }
39- . frame ( width: 200 )
40- #else
41- CollectionListView ( )
42- . withErrorHandling ( )
43- #endif
44-
45- #if os(macOS)
46- ZStack {
47- PostListView ( selectedCollection: model. selectedCollection, showAllPosts: model. showAllPosts)
48- . withErrorHandling ( )
49- . frame ( width: 300 )
50- if model. isProcessingRequest {
51- ZStack {
52- Color ( NSColor . controlBackgroundColor) . opacity ( 0.75 )
53- ProgressView ( )
5456 }
5557 }
58+ } ,
59+ postDetail: {
60+ NoSelectedPostView ( isConnected: $model. hasNetworkConnection)
61+ }
62+ )
63+ . environmentObject ( model)
64+ . onChange ( of: model. hasError) { value in
65+ if value {
66+ if let error = model. currentError {
67+ self . errorHandling. handle ( error: error)
68+ } else {
69+ self . errorHandling. handle ( error: AppError . genericError ( ) )
70+ }
71+ model. hasError = false
5672 }
57- #else
58- PostListView ( selectedCollection: model. selectedCollection, showAllPosts: model. showAllPosts)
59- . withErrorHandling ( )
60- #endif
61-
62- NoSelectedPostView ( isConnected: $model. hasNetworkConnection)
6373 }
74+ #else
75+ WFNavigation (
76+ collectionList: {
77+ CollectionListView ( )
78+ . withErrorHandling ( )
79+ } ,
80+ postList: {
81+ PostListView ( selectedCollection: model. selectedCollection, showAllPosts: model. showAllPosts)
82+ . withErrorHandling ( )
83+ } ,
84+ postDetail: {
85+ NoSelectedPostView ( isConnected: $model. hasNetworkConnection)
86+ }
87+ )
6488 . environmentObject ( model)
6589 . onChange ( of: model. hasError) { value in
6690 if value {
@@ -72,6 +96,7 @@ struct ContentView: View {
7296 model. hasError = false
7397 }
7498 }
99+ #endif
75100 }
76101}
77102
0 commit comments