Set new post ids
This commit is contained in:
@@ -5,6 +5,12 @@ struct PostList: View {
|
||||
@EnvironmentObject
|
||||
private var content: Content
|
||||
|
||||
@State
|
||||
private var showNewPostIdSheet = false
|
||||
|
||||
@State
|
||||
private var newPostId = ""
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
if content.posts.isEmpty {
|
||||
@@ -15,7 +21,7 @@ struct PostList: View {
|
||||
.listRowSeparator(.hidden)
|
||||
}
|
||||
HorizontalCenter {
|
||||
Button(action: addNewPost) {
|
||||
Button(action: { showNewPostIdSheet = true }) {
|
||||
Text("Add post")
|
||||
}
|
||||
.padding()
|
||||
@@ -31,12 +37,24 @@ struct PostList: View {
|
||||
}
|
||||
}
|
||||
.listStyle(.plain)
|
||||
//.scrollContentBackground(.hidden)
|
||||
.sheet(isPresented: $showNewPostIdSheet, onDismiss: addNewPost) {
|
||||
TextEntrySheet(title: "Enter the new post id", text: $newPostId)
|
||||
}
|
||||
}
|
||||
|
||||
private func addNewPost() {
|
||||
let id = newPostId.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard id != "" else {
|
||||
return
|
||||
}
|
||||
|
||||
guard !content.posts.contains(where: { $0.id == id }) else {
|
||||
print("ID \(id) already exists")
|
||||
return
|
||||
}
|
||||
|
||||
let post = Post(
|
||||
id: "new",
|
||||
id: id,
|
||||
isDraft: true,
|
||||
createdDate: .now,
|
||||
startDate: .now,
|
||||
|
Reference in New Issue
Block a user