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 AddPageView: View {
@State
private var newPageId = ""
private let allowedCharactersInPageId = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "-")).inverted
init(selected: Binding<Page?>) {
self._selectedPage = selected
}
private var idExists: Bool {
content.pages.contains { $0.id == newPageId }
!content.isNewIdForPage(newPageId)
}
private var containsInvalidCharacters: Bool {
newPageId.rangeOfCharacter(from: allowedCharactersInPageId) != nil
private var isInvalidId: Bool {
!content.isValidIdForTagOrPageOrPost(newPageId)
}
var body: some View {
@ -42,12 +40,12 @@ struct AddPageView: View {
if newPageId.isEmpty {
Text("Enter the id of the new page to create")
.foregroundStyle(.secondary)
} else if isInvalidId {
Text("The id contains invalid characters")
.foregroundStyle(Color.red)
} else if idExists {
Text("A page with the same id already exists")
.foregroundStyle(Color.red)
} else if containsInvalidCharacters {
Text("The id contains invalid characters")
.foregroundStyle(Color.red)
} else {
Text("Create a new page with the id")
.foregroundStyle(.secondary)
@ -59,7 +57,7 @@ struct AddPageView: View {
Button(action: addNewPage) {
Text("Create")
}
.disabled(newPageId.isEmpty || containsInvalidCharacters || idExists)
.disabled(isInvalidId || idExists)
}
}
.padding()