Skip to content

Commit 8205673

Browse files
committed
Refactor status toolbar out of PostEditorView and fix macOS build error
1 parent afa026d commit 8205673

File tree

4 files changed

+127
-37
lines changed

4 files changed

+127
-37
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import SwiftUI
2+
3+
struct PostEditorStatusToolbarView: View {
4+
#if os(iOS)
5+
@Environment(\.horizontalSizeClass) var horizontalSizeClass
6+
#endif
7+
@EnvironmentObject var model: WriteFreelyModel
8+
9+
@ObservedObject var post: Post
10+
11+
var body: some View {
12+
if post.hasNewerRemoteCopy {
13+
#if os(iOS)
14+
if horizontalSizeClass == .compact {
15+
VStack {
16+
PostStatusBadgeView(post: post)
17+
HStack {
18+
Text("⚠️ Newer copy on server. Replace local copy?")
19+
.font(.caption)
20+
.foregroundColor(.secondary)
21+
Button(action: {
22+
model.updateFromServer(post: post)
23+
}, label: {
24+
Image(systemName: "square.and.arrow.down")
25+
})
26+
}
27+
.padding(.bottom)
28+
}
29+
.padding(.top)
30+
} else {
31+
HStack {
32+
PostStatusBadgeView(post: post)
33+
.padding(.trailing)
34+
Text("⚠️ Newer copy on server. Replace local copy?")
35+
.font(.callout)
36+
.foregroundColor(.secondary)
37+
Button(action: {
38+
model.updateFromServer(post: post)
39+
}, label: {
40+
Image(systemName: "square.and.arrow.down")
41+
})
42+
}
43+
}
44+
#else
45+
HStack {
46+
PostStatusBadgeView(post: post)
47+
.padding(.trailing)
48+
Text("⚠️ Newer copy on server. Replace local copy?")
49+
.font(.callout)
50+
.foregroundColor(.secondary)
51+
Button(action: {
52+
model.updateFromServer(post: post)
53+
}, label: {
54+
Image(systemName: "square.and.arrow.down")
55+
})
56+
}
57+
#endif
58+
} else {
59+
PostStatusBadgeView(post: post)
60+
}
61+
}
62+
}
63+
64+
struct ToolbarView_LocalPreviews: PreviewProvider {
65+
static var previews: some View {
66+
let model = WriteFreelyModel()
67+
let post = testPost
68+
return PostEditorStatusToolbarView(post: post)
69+
.environmentObject(model)
70+
}
71+
}
72+
73+
struct ToolbarView_RemotePreviews: PreviewProvider {
74+
static var previews: some View {
75+
let model = WriteFreelyModel()
76+
let newerRemotePost = Post(
77+
title: testPost.wfPost.title ?? "",
78+
body: testPost.wfPost.body,
79+
createdDate: testPost.wfPost.createdDate ?? Date(),
80+
status: testPost.status,
81+
collection: testPost.collection
82+
)
83+
newerRemotePost.hasNewerRemoteCopy = true
84+
return PostEditorStatusToolbarView(post: newerRemotePost)
85+
.environmentObject(model)
86+
}
87+
}
88+
89+
#if os(iOS)
90+
struct ToolbarView_CompactLocalPreviews: PreviewProvider {
91+
static var previews: some View {
92+
let model = WriteFreelyModel()
93+
let post = testPost
94+
return PostEditorStatusToolbarView(post: post)
95+
.environmentObject(model)
96+
.environment(\.horizontalSizeClass, .compact)
97+
}
98+
}
99+
#endif
100+
101+
#if os(iOS)
102+
struct ToolbarView_CompactRemotePreviews: PreviewProvider {
103+
static var previews: some View {
104+
let model = WriteFreelyModel()
105+
let newerRemotePost = Post(
106+
title: testPost.wfPost.title ?? "",
107+
body: testPost.wfPost.body,
108+
createdDate: testPost.wfPost.createdDate ?? Date(),
109+
status: testPost.status,
110+
collection: testPost.collection
111+
)
112+
newerRemotePost.hasNewerRemoteCopy = true
113+
return PostEditorStatusToolbarView(post: newerRemotePost)
114+
.environmentObject(model)
115+
.environment(\.horizontalSizeClass, .compact)
116+
}
117+
}
118+
#endif

Shared/PostEditor/PostEditorView.swift

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import SwiftUI
22

33
struct PostEditorView: View {
4-
@Environment(\.horizontalSizeClass) var horizontalSizeClass
54
@EnvironmentObject var model: WriteFreelyModel
65

76
@ObservedObject var post: Post
@@ -30,40 +29,7 @@ struct PostEditorView: View {
3029
.padding()
3130
.toolbar {
3231
ToolbarItem(placement: .status) {
33-
if post.hasNewerRemoteCopy {
34-
if horizontalSizeClass == .compact {
35-
VStack {
36-
PostStatusBadgeView(post: post)
37-
HStack {
38-
Text("⚠️ Newer copy on server. Replace local copy?")
39-
.font(.caption)
40-
.foregroundColor(.secondary)
41-
Button(action: {
42-
model.updateFromServer(post: post)
43-
}, label: {
44-
Image(systemName: "square.and.arrow.down")
45-
})
46-
}
47-
.padding(.bottom)
48-
}
49-
.padding(.top)
50-
} else {
51-
HStack {
52-
PostStatusBadgeView(post: post)
53-
.padding(.trailing)
54-
Text("⚠️ Newer copy on server. Replace local copy?")
55-
.font(.callout)
56-
.foregroundColor(.secondary)
57-
Button(action: {
58-
model.updateFromServer(post: post)
59-
}, label: {
60-
Image(systemName: "square.and.arrow.down")
61-
})
62-
}
63-
}
64-
} else {
65-
PostStatusBadgeView(post: post)
66-
}
32+
PostEditorStatusToolbarView(post: post)
6733
}
6834
ToolbarItem(placement: .primaryAction) {
6935
Button(action: {

WriteFreely-MultiPlatform.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
1756AE7A24CB65DF00FD7257 /* PostListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1756AE7924CB65DF00FD7257 /* PostListView.swift */; };
3535
1756AE7B24CB65DF00FD7257 /* PostListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1756AE7924CB65DF00FD7257 /* PostListView.swift */; };
3636
1756AE8124CB844500FD7257 /* View+Keyboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1756AE8024CB844500FD7257 /* View+Keyboard.swift */; };
37+
1756DBB324FECDBB00207AB8 /* PostEditorStatusToolbarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1756DBB224FECDBB00207AB8 /* PostEditorStatusToolbarView.swift */; };
38+
1756DBB424FECDBB00207AB8 /* PostEditorStatusToolbarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1756DBB224FECDBB00207AB8 /* PostEditorStatusToolbarView.swift */; };
3739
1762DCB324EB086C0019C4EB /* CollectionListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1762DCB224EB086C0019C4EB /* CollectionListModel.swift */; };
3840
1762DCB424EB086C0019C4EB /* CollectionListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1762DCB224EB086C0019C4EB /* CollectionListModel.swift */; };
3941
1765F62A24E18EA200C9EBF0 /* SidebarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1765F62924E18EA200C9EBF0 /* SidebarView.swift */; };
@@ -90,6 +92,7 @@
9092
1756AE7624CB2EDD00FD7257 /* PostEditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostEditorView.swift; sourceTree = "<group>"; };
9193
1756AE7924CB65DF00FD7257 /* PostListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostListView.swift; sourceTree = "<group>"; };
9294
1756AE8024CB844500FD7257 /* View+Keyboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Keyboard.swift"; sourceTree = "<group>"; };
95+
1756DBB224FECDBB00207AB8 /* PostEditorStatusToolbarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostEditorStatusToolbarView.swift; sourceTree = "<group>"; };
9396
1762DCB224EB086C0019C4EB /* CollectionListModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionListModel.swift; sourceTree = "<group>"; };
9497
1765F62924E18EA200C9EBF0 /* SidebarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarView.swift; sourceTree = "<group>"; };
9598
17A5388724DDA31F00DEFF9A /* MacAccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacAccountView.swift; sourceTree = "<group>"; };
@@ -166,6 +169,7 @@
166169
isa = PBXGroup;
167170
children = (
168171
1756AE7624CB2EDD00FD7257 /* PostEditorView.swift */,
172+
1756DBB224FECDBB00207AB8 /* PostEditorStatusToolbarView.swift */,
169173
);
170174
path = PostEditor;
171175
sourceTree = "<group>";
@@ -546,6 +550,7 @@
546550
17120DAC24E1B99F002B9F6C /* AccountLoginView.swift in Sources */,
547551
17120DA924E1B2F5002B9F6C /* AccountLogoutView.swift in Sources */,
548552
171BFDFA24D4AF8300888236 /* CollectionListView.swift in Sources */,
553+
1756DBB324FECDBB00207AB8 /* PostEditorStatusToolbarView.swift in Sources */,
549554
17120DB224E1E19C002B9F6C /* SettingsHeaderView.swift in Sources */,
550555
1756AE7724CB2EDD00FD7257 /* PostEditorView.swift in Sources */,
551556
17DF32D524C8CA3400BCE2E3 /* PostStatusBadgeView.swift in Sources */,
@@ -587,6 +592,7 @@
587592
1762DCB424EB086C0019C4EB /* CollectionListModel.swift in Sources */,
588593
17A5389324DDED0000DEFF9A /* PreferencesView.swift in Sources */,
589594
1756AE6F24CB255B00FD7257 /* PostStore.swift in Sources */,
595+
1756DBB424FECDBB00207AB8 /* PostEditorStatusToolbarView.swift in Sources */,
590596
1756AE6C24CB1E4B00FD7257 /* Post.swift in Sources */,
591597
17A5388F24DDEC7400DEFF9A /* AccountView.swift in Sources */,
592598
1756AE7524CB26FA00FD7257 /* PostCellView.swift in Sources */,

WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
<key>WriteFreely-MultiPlatform (iOS).xcscheme_^#shared#^_</key>
88
<dict>
99
<key>orderHint</key>
10-
<integer>1</integer>
10+
<integer>0</integer>
1111
</dict>
1212
<key>WriteFreely-MultiPlatform (macOS).xcscheme_^#shared#^_</key>
1313
<dict>
1414
<key>orderHint</key>
15-
<integer>0</integer>
15+
<integer>1</integer>
1616
</dict>
1717
</dict>
1818
</dict>

0 commit comments

Comments
 (0)