Refactor active-post toolbar buttons into extracted view

This commit is contained in:
Angelo Stavrow 2020-11-27 11:02:18 -05:00
parent 28d3b6f831
commit 3114d037b3
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
3 changed files with 38 additions and 14 deletions

View File

@ -77,22 +77,9 @@ struct ContentView: View {
) )
}) })
} }
ToolbarItem(placement: .status) {
if let selectedPost = model.selectedPost {
PostEditorStatusToolbarView(post: selectedPost)
}
}
ToolbarItemGroup(placement: .primaryAction) { ToolbarItemGroup(placement: .primaryAction) {
if let selectedPost = model.selectedPost { if let selectedPost = model.selectedPost {
Button(action: { ActivePostToolbarView(activePost: selectedPost)
DispatchQueue.main.async {
LocalStorageManager().saveContext()
model.publish(post: selectedPost)
}
}, label: { Image(systemName: "paperplane") })
.disabled(selectedPost.body.isEmpty || selectedPost.status == PostStatus.published.rawValue)
Button(action: {}, label: { Image(systemName: "square.and.arrow.up") })
.disabled(selectedPost.status == PostStatus.local.rawValue)
} }
} }
} }

View File

@ -62,6 +62,7 @@
17B996D92502D23E0017B536 /* WFAPost+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B996D62502D23E0017B536 /* WFAPost+CoreDataClass.swift */; }; 17B996D92502D23E0017B536 /* WFAPost+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B996D62502D23E0017B536 /* WFAPost+CoreDataClass.swift */; };
17B996DA2502D23E0017B536 /* WFAPost+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B996D72502D23E0017B536 /* WFAPost+CoreDataProperties.swift */; }; 17B996DA2502D23E0017B536 /* WFAPost+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B996D72502D23E0017B536 /* WFAPost+CoreDataProperties.swift */; };
17B996DB2502D23E0017B536 /* WFAPost+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B996D72502D23E0017B536 /* WFAPost+CoreDataProperties.swift */; }; 17B996DB2502D23E0017B536 /* WFAPost+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B996D72502D23E0017B536 /* WFAPost+CoreDataProperties.swift */; };
17BC618A25715318003363CA /* ActivePostToolbarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17BC617825715068003363CA /* ActivePostToolbarView.swift */; };
17C42E622507D8E600072984 /* PostStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17C42E612507D8E600072984 /* PostStatus.swift */; }; 17C42E622507D8E600072984 /* PostStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17C42E612507D8E600072984 /* PostStatus.swift */; };
17C42E632507D8E600072984 /* PostStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17C42E612507D8E600072984 /* PostStatus.swift */; }; 17C42E632507D8E600072984 /* PostStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17C42E612507D8E600072984 /* PostStatus.swift */; };
17C42E652509237800072984 /* PostListFilteredView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17C42E642509237800072984 /* PostListFilteredView.swift */; }; 17C42E652509237800072984 /* PostListFilteredView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17C42E642509237800072984 /* PostListFilteredView.swift */; };
@ -151,6 +152,7 @@
17B5103A2515448D00E9631F /* Credits.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = "<group>"; }; 17B5103A2515448D00E9631F /* Credits.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = "<group>"; };
17B996D62502D23E0017B536 /* WFAPost+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WFAPost+CoreDataClass.swift"; sourceTree = SOURCE_ROOT; }; 17B996D62502D23E0017B536 /* WFAPost+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WFAPost+CoreDataClass.swift"; sourceTree = SOURCE_ROOT; };
17B996D72502D23E0017B536 /* WFAPost+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WFAPost+CoreDataProperties.swift"; sourceTree = SOURCE_ROOT; }; 17B996D72502D23E0017B536 /* WFAPost+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WFAPost+CoreDataProperties.swift"; sourceTree = SOURCE_ROOT; };
17BC617825715068003363CA /* ActivePostToolbarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivePostToolbarView.swift; sourceTree = "<group>"; };
17C42E612507D8E600072984 /* PostStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostStatus.swift; sourceTree = "<group>"; }; 17C42E612507D8E600072984 /* PostStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostStatus.swift; sourceTree = "<group>"; };
17C42E642509237800072984 /* PostListFilteredView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostListFilteredView.swift; sourceTree = "<group>"; }; 17C42E642509237800072984 /* PostListFilteredView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostListFilteredView.swift; sourceTree = "<group>"; };
17C42E6F250AA12200072984 /* NSManagedObjectContext+ExecuteAndMergeChanges.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectContext+ExecuteAndMergeChanges.swift"; sourceTree = "<group>"; }; 17C42E6F250AA12200072984 /* NSManagedObjectContext+ExecuteAndMergeChanges.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectContext+ExecuteAndMergeChanges.swift"; sourceTree = "<group>"; };
@ -316,6 +318,14 @@
path = PostEditor; path = PostEditor;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
17BC617725715042003363CA /* Navigation */ = {
isa = PBXGroup;
children = (
17BC617825715068003363CA /* ActivePostToolbarView.swift */,
);
path = Navigation;
sourceTree = "<group>";
};
17D4F3722514EE4400517CE6 /* Resources */ = { 17D4F3722514EE4400517CE6 /* Resources */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -393,6 +403,7 @@
children = ( children = (
17DF329224C87D3500BCE2E3 /* Info.plist */, 17DF329224C87D3500BCE2E3 /* Info.plist */,
17DF329324C87D3500BCE2E3 /* macOS.entitlements */, 17DF329324C87D3500BCE2E3 /* macOS.entitlements */,
17BC617725715042003363CA /* Navigation */,
17A67CAC251A5D8D002F163D /* PostEditor */, 17A67CAC251A5D8D002F163D /* PostEditor */,
17A5388924DDA50500DEFF9A /* Settings */, 17A5388924DDA50500DEFF9A /* Settings */,
17B5103A2515448D00E9631F /* Credits.rtf */, 17B5103A2515448D00E9631F /* Credits.rtf */,
@ -754,6 +765,7 @@
1753F6AC24E431CC00309365 /* MacPreferencesView.swift in Sources */, 1753F6AC24E431CC00309365 /* MacPreferencesView.swift in Sources */,
1756DC0424FEE18400207AB8 /* WFACollection+CoreDataProperties.swift in Sources */, 1756DC0424FEE18400207AB8 /* WFACollection+CoreDataProperties.swift in Sources */,
17B996DB2502D23E0017B536 /* WFAPost+CoreDataProperties.swift in Sources */, 17B996DB2502D23E0017B536 /* WFAPost+CoreDataProperties.swift in Sources */,
17BC618A25715318003363CA /* ActivePostToolbarView.swift in Sources */,
171BFDFB24D4AF8300888236 /* CollectionListView.swift in Sources */, 171BFDFB24D4AF8300888236 /* CollectionListView.swift in Sources */,
17A67CAF251A5DD7002F163D /* PostEditorView.swift in Sources */, 17A67CAF251A5DD7002F163D /* PostEditorView.swift in Sources */,
17DF32AB24C87D3500BCE2E3 /* WriteFreely_MultiPlatformApp.swift in Sources */, 17DF32AB24C87D3500BCE2E3 /* WriteFreely_MultiPlatformApp.swift in Sources */,

View File

@ -0,0 +1,25 @@
import SwiftUI
struct ActivePostToolbarView: View {
@EnvironmentObject var model: WriteFreelyModel
@ObservedObject var activePost: WFAPost
var body: some View {
HStack(spacing: 16) {
PostEditorStatusToolbarView(post: activePost)
HStack(spacing: 4) {
Button(action: { publishPost(activePost) }, label: { Image(systemName: "paperplane") })
.disabled(activePost.body.isEmpty || activePost.status == PostStatus.published.rawValue)
Button(action: {}, label: { Image(systemName: "square.and.arrow.up") })
.disabled(activePost.status == PostStatus.local.rawValue)
}
}
}
private func publishPost(_ post: WFAPost) {
DispatchQueue.main.async {
LocalStorageManager().saveContext()
model.publish(post: post)
}
}
}