Improve page indicators, adding items
This commit is contained in:
@ -17,18 +17,16 @@ struct AddPostView: View {
|
||||
@State
|
||||
private var newPostId = ""
|
||||
|
||||
private let allowedCharactersInPostId = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "-")).inverted
|
||||
|
||||
init(selected: Binding<Post?>) {
|
||||
self._selectedPost = selected
|
||||
}
|
||||
|
||||
private var idExists: Bool {
|
||||
content.posts.contains { $0.id == newPostId }
|
||||
!content.isNewIdForPost(newPostId)
|
||||
}
|
||||
|
||||
private var containsInvalidCharacters: Bool {
|
||||
newPostId.rangeOfCharacter(from: allowedCharactersInPostId) != nil
|
||||
private var isInvalidId: Bool {
|
||||
!content.isValidIdForTagOrPageOrPost(newPostId)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@ -45,7 +43,7 @@ struct AddPostView: View {
|
||||
} else if idExists {
|
||||
Text("A post with the same id already exists")
|
||||
.foregroundStyle(Color.red)
|
||||
} else if containsInvalidCharacters {
|
||||
} else if isInvalidId {
|
||||
Text("The id contains invalid characters")
|
||||
.foregroundStyle(Color.red)
|
||||
} else {
|
||||
@ -59,7 +57,7 @@ struct AddPostView: View {
|
||||
Button(action: addNewPost) {
|
||||
Text("Create")
|
||||
}
|
||||
.disabled(newPostId.isEmpty || containsInvalidCharacters || idExists)
|
||||
.disabled(isInvalidId || idExists)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
|
Reference in New Issue
Block a user