Improve page indicators, adding items

This commit is contained in:
Christoph Hagen
2025-01-09 13:27:38 +01:00
parent 0590224f02
commit 0db6e411c3
23 changed files with 238 additions and 206 deletions

View File

@ -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()

View File

@ -35,7 +35,7 @@ struct PostListView: View {
Text(post.title(in: language))
Spacer()
if post.isDraft {
DraftIndicator()
TextIndicator(text: "Draft")
}
}.tag(post)
}

View File

@ -69,9 +69,6 @@ struct TagSelectionView: View {
return
}
selected.remove(at: index)
let insertIndex = tags.firstIndex(where: { $0 > tag }) ?? tags.endIndex
tags.insert(tag, at: insertIndex)
}
private func select(tag: Tag) {