Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F10700664
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
View Options
diff --git a/Shared/Navigation/ContentView.swift b/Shared/Navigation/ContentView.swift
index 6422683..d10f9f0 100644
--- a/Shared/Navigation/ContentView.swift
+++ b/Shared/Navigation/ContentView.swift
@@ -1,26 +1,29 @@
import SwiftUI
struct ContentView: View {
@EnvironmentObject var model: WriteFreelyModel
var body: some View {
NavigationView {
SidebarView()
PostListView(selectedCollection: allPostsCollection)
Text("Select a post, or create a new draft.")
.foregroundColor(.secondary)
}
.environmentObject(model)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
let model = WriteFreelyModel()
model.collections = CollectionListModel(with: [userCollection1, userCollection2, userCollection3])
+ for post in testPostData {
+ model.store.add(post)
+ }
return ContentView()
.environmentObject(model)
}
}
diff --git a/Shared/PostList/PostListView.swift b/Shared/PostList/PostListView.swift
index 978e0dc..1250472 100644
--- a/Shared/PostList/PostListView.swift
+++ b/Shared/PostList/PostListView.swift
@@ -1,111 +1,115 @@
import SwiftUI
struct PostListView: View {
@EnvironmentObject var model: WriteFreelyModel
@State var selectedCollection: PostCollection
#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
)
}
}
}
.environmentObject(model)
.navigationTitle(selectedCollection.title)
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button(action: {
let post = Post()
model.store.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()
model.store.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 model.store.posts
} else {
return model.store.posts.filter {
$0.collection.title == collection.title
}
}
}
}
struct PostList_Previews: PreviewProvider {
static var previews: some View {
- Group {
+ let model = WriteFreelyModel()
+ for post in testPostData {
+ model.store.add(post)
+ }
+ return Group {
PostListView(selectedCollection: allPostsCollection)
- .environmentObject(WriteFreelyModel())
+ .environmentObject(model)
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Jun 7, 12:00 AM (12 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3259528
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment