@@ -5,62 +5,86 @@ struct ContentView: View {
5
5
@EnvironmentObject var errorHandling : ErrorHandling
6
6
7
7
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 " ) }
17
24
)
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. " )
27
26
}
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
+ }
34
40
}
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 ( )
35
55
}
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 ( )
54
56
}
55
57
}
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
56
72
}
57
- #else
58
- PostListView ( selectedCollection: model. selectedCollection, showAllPosts: model. showAllPosts)
59
- . withErrorHandling ( )
60
- #endif
61
-
62
- NoSelectedPostView ( isConnected: $model. hasNetworkConnection)
63
73
}
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
+ )
64
88
. environmentObject ( model)
65
89
. onChange ( of: model. hasError) { value in
66
90
if value {
@@ -72,6 +96,7 @@ struct ContentView: View {
72
96
model. hasError = false
73
97
}
74
98
}
99
+ #endif
75
100
}
76
101
}
77
102
0 commit comments