Fix spacing when collapsing sidebar, add other buttons to toolbar

This commit is contained in:
Angelo Stavrow 2020-11-25 14:11:57 -05:00
parent 39ae839052
commit 1e432c6adb
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 48 additions and 9 deletions

View File

@ -2,24 +2,54 @@ import SwiftUI
struct ContentView: View {
@EnvironmentObject var model: WriteFreelyModel
@Binding var sidebarIsHidden: Bool
var body: some View {
NavigationView {
#if os(macOS)
SidebarView()
.toolbar {
Button(action: {
NSApp.keyWindow?.contentViewController?.tryToPerform(
#selector(NSSplitViewController.toggleSidebar(_:)),
with: nil
)
}, label: { Image(systemName: "sidebar.left") })
Button(
action: {
NSApp.keyWindow?.contentViewController?.tryToPerform(
#selector(NSSplitViewController.toggleSidebar(_:)), with: nil
)
withAnimation { self.sidebarIsHidden.toggle() }
},
label: { Image(systemName: "sidebar.left") }
)
Spacer()
Button(action: {}, label: { Image(systemName: "square.and.pencil") })
}
#else
SidebarView()
#endif
#if os(macOS)
PostListView(selectedCollection: nil, showAllPosts: model.account.isLoggedIn)
.toolbar {
ToolbarItem(placement: .navigation) {
Button(action: {}, label: { Image(systemName: "arrow.clockwise") })
.padding(.leading, sidebarIsHidden ? 8 : 0)
.animation(.linear)
}
ToolbarItem(placement: .status) {
if let selectedPost = model.selectedPost {
PostStatusBadgeView(post: selectedPost)
}
}
ToolbarItemGroup(placement: .primaryAction) {
if let selectedPost = model.selectedPost {
Button(action: {}, label: { Image(systemName: "paperplane") })
.disabled(selectedPost.body.isEmpty)
Button(action: {}, label: { Image(systemName: "square.and.arrow.up") })
.disabled(selectedPost.status == PostStatus.local.rawValue)
}
}
}
#else
PostListView(selectedCollection: nil, showAllPosts: model.account.isLoggedIn)
#endif
Text("Select a post, or create a new local draft.")
.foregroundColor(.secondary)
@ -72,7 +102,7 @@ struct ContentView_Previews: PreviewProvider {
let context = LocalStorageManager.persistentContainer.viewContext
let model = WriteFreelyModel()
return ContentView()
return ContentView(sidebarIsHidden: .constant(false))
.environment(\.managedObjectContext, context)
.environmentObject(model)
}

View File

@ -6,11 +6,12 @@ struct WriteFreely_MultiPlatformApp: App {
#if os(macOS)
@State private var selectedTab = 0
@State private var sidebarIsHidden: Bool = false
#endif
var body: some Scene {
WindowGroup {
ContentView()
ContentView(sidebarIsHidden: $sidebarIsHidden)
.onAppear(perform: {
if let lastDraft = model.editor.fetchLastDraftFromUserDefaults() {
self.model.selectedPost = lastDraft
@ -23,7 +24,15 @@ struct WriteFreely_MultiPlatformApp: App {
// .preferredColorScheme(preferences.selectedColorScheme) // See PreferencesModel for info.
}
.commands {
SidebarCommands()
CommandGroup(after: .sidebar) {
Button("Toggle Sidebar") {
NSApp.keyWindow?.contentViewController?.tryToPerform(
#selector(NSSplitViewController.toggleSidebar(_:)), with: nil
)
withAnimation { self.sidebarIsHidden.toggle() }
}
.keyboardShortcut("s", modifiers: [.command, .option])
}
}
#if os(macOS)