diff --git a/Shared/Navigation/ContentView.swift b/Shared/Navigation/ContentView.swift index d8c908b..ab1cd05 100644 --- a/Shared/Navigation/ContentView.swift +++ b/Shared/Navigation/ContentView.swift @@ -77,22 +77,9 @@ struct ContentView: View { ) }) } - ToolbarItem(placement: .status) { - if let selectedPost = model.selectedPost { - PostEditorStatusToolbarView(post: selectedPost) - } - } ToolbarItemGroup(placement: .primaryAction) { if let selectedPost = model.selectedPost { - Button(action: { - 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) + ActivePostToolbarView(activePost: selectedPost) } } } diff --git a/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj b/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj index 6829399..489cd38 100644 --- a/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj +++ b/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj @@ -62,6 +62,7 @@ 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 */; }; 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 */; }; 17C42E632507D8E600072984 /* PostStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17C42E612507D8E600072984 /* PostStatus.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 = ""; }; 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; }; + 17BC617825715068003363CA /* ActivePostToolbarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivePostToolbarView.swift; sourceTree = ""; }; 17C42E612507D8E600072984 /* PostStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostStatus.swift; sourceTree = ""; }; 17C42E642509237800072984 /* PostListFilteredView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostListFilteredView.swift; sourceTree = ""; }; 17C42E6F250AA12200072984 /* NSManagedObjectContext+ExecuteAndMergeChanges.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectContext+ExecuteAndMergeChanges.swift"; sourceTree = ""; }; @@ -316,6 +318,14 @@ path = PostEditor; sourceTree = ""; }; + 17BC617725715042003363CA /* Navigation */ = { + isa = PBXGroup; + children = ( + 17BC617825715068003363CA /* ActivePostToolbarView.swift */, + ); + path = Navigation; + sourceTree = ""; + }; 17D4F3722514EE4400517CE6 /* Resources */ = { isa = PBXGroup; children = ( @@ -393,6 +403,7 @@ children = ( 17DF329224C87D3500BCE2E3 /* Info.plist */, 17DF329324C87D3500BCE2E3 /* macOS.entitlements */, + 17BC617725715042003363CA /* Navigation */, 17A67CAC251A5D8D002F163D /* PostEditor */, 17A5388924DDA50500DEFF9A /* Settings */, 17B5103A2515448D00E9631F /* Credits.rtf */, @@ -754,6 +765,7 @@ 1753F6AC24E431CC00309365 /* MacPreferencesView.swift in Sources */, 1756DC0424FEE18400207AB8 /* WFACollection+CoreDataProperties.swift in Sources */, 17B996DB2502D23E0017B536 /* WFAPost+CoreDataProperties.swift in Sources */, + 17BC618A25715318003363CA /* ActivePostToolbarView.swift in Sources */, 171BFDFB24D4AF8300888236 /* CollectionListView.swift in Sources */, 17A67CAF251A5DD7002F163D /* PostEditorView.swift in Sources */, 17DF32AB24C87D3500BCE2E3 /* WriteFreely_MultiPlatformApp.swift in Sources */, diff --git a/macOS/Navigation/ActivePostToolbarView.swift b/macOS/Navigation/ActivePostToolbarView.swift new file mode 100644 index 0000000..58e223c --- /dev/null +++ b/macOS/Navigation/ActivePostToolbarView.swift @@ -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) + } + } +}