Page MenuHomeMusing Studio

No OneTemporary

diff --git a/Shared/PostList/PostListView.swift b/Shared/PostList/PostListView.swift
index 89ae444..9a89b7c 100644
--- a/Shared/PostList/PostListView.swift
+++ b/Shared/PostList/PostListView.swift
@@ -1,108 +1,111 @@
import SwiftUI
struct PostListView: View {
@EnvironmentObject var postStore: PostStore
@State var selectedCollection: PostCollection
- @State var isPresentingSettings = false
+
+ #if os(iOS)
+ @State private var isPresentingSettings = false
+ #endif
var body: some View {
#if os(iOS)
GeometryReader { geometry in
List {
ForEach(showPosts(for: selectedCollection)) { post in
NavigationLink(
destination: PostEditorView(post: post)
) {
PostCellView(
post: post
)
}
}
}
.navigationTitle(selectedCollection.title)
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button(action: {
let post = Post()
postStore.add(post)
}, label: {
Image(systemName: "square.and.pencil")
})
}
ToolbarItem(placement: .bottomBar) {
HStack {
Button(action: {
isPresentingSettings = true
}, label: {
Image(systemName: "gear")
}).sheet(
isPresented: $isPresentingSettings,
onDismiss: {
isPresentingSettings = false
},
content: {
SettingsView(isPresented: $isPresentingSettings)
}
)
Spacer()
Text(pluralizedPostCount(for: showPosts(for: selectedCollection)))
.foregroundColor(.secondary)
}
.padding()
.frame(width: geometry.size.width)
}
}
}
#else //if os(macOS)
List {
ForEach(showPosts(for: selectedCollection)) { post in
NavigationLink(
destination: PostEditorView(post: post)
) {
PostCellView(
post: post
)
}
}
}
.navigationTitle(selectedCollection.title)
.navigationSubtitle(pluralizedPostCount(for: showPosts(for: selectedCollection)))
.toolbar {
Button(action: {
let post = Post()
postStore.add(post)
}, label: {
Image(systemName: "square.and.pencil")
})
}
#endif
}
private func pluralizedPostCount(for posts: [Post]) -> String {
if posts.count == 1 {
return "1 post"
} else {
return "\(posts.count) posts"
}
}
private func showPosts(for collection: PostCollection) -> [Post] {
if collection == allPostsCollection {
return postStore.posts
} else {
return postStore.posts.filter {
$0.collection.title == collection.title
}
}
}
}
struct PostList_Previews: PreviewProvider {
static var previews: some View {
Group {
PostListView(selectedCollection: allPostsCollection)
.environmentObject(testPostStore)
}
}
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, May 15, 7:38 AM (15 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3239566

Event Timeline