Sort posts, improve list update
This commit is contained in:
parent
c38d8e0264
commit
66bf3aa536
@ -1,5 +1,45 @@
|
||||
import SwiftUI
|
||||
|
||||
private struct PostListItem: View {
|
||||
|
||||
@Environment(\.language)
|
||||
private var language
|
||||
|
||||
@ObservedObject
|
||||
var post: Post
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
LocalizedPostListItem(id: post.id, post: post.localized(in: language))
|
||||
if post.isDraft {
|
||||
TextIndicator(text: "Draft", background: .yellow)
|
||||
} else {
|
||||
if post.german.text.isEmpty {
|
||||
TextIndicator(text: "DE", background: .yellow)
|
||||
}
|
||||
if post.english.text.isEmpty {
|
||||
TextIndicator(text: "EN", background: .yellow)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct LocalizedPostListItem: View {
|
||||
|
||||
let id: String
|
||||
|
||||
@ObservedObject
|
||||
var post: LocalizedPost
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Text(post.title ?? id)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct PostListView: View {
|
||||
|
||||
@Environment(\.language)
|
||||
@ -25,19 +65,18 @@ struct PostListView: View {
|
||||
return content.posts.filter { $0.contains(searchString) }
|
||||
}
|
||||
|
||||
private var filteredAndSortedPosts: [Post] {
|
||||
filteredPosts.sorted(ascending: false) { $0.startDate }
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
TextField("", text: $searchString, prompt: Text("Search"))
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.padding(.horizontal, 8)
|
||||
List(filteredPosts, selection: $selectedPost) { post in
|
||||
HStack {
|
||||
Text(post.title(in: language))
|
||||
Spacer()
|
||||
if post.isDraft {
|
||||
TextIndicator(text: "Draft")
|
||||
}
|
||||
}.tag(post)
|
||||
List(filteredAndSortedPosts, selection: $selectedPost) { post in
|
||||
PostListItem(post: post)
|
||||
.tag(post)
|
||||
}
|
||||
}.onAppear {
|
||||
if selectedPost == nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user