mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Fix spacing when collapsing sidebar, add other buttons to toolbar
This commit is contained in:
parent
39ae839052
commit
1e432c6adb
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user