Update page indicators

This commit is contained in:
Christoph Hagen 2025-05-02 23:14:47 +02:00
parent 1f4f32c9af
commit d0685c163c
2 changed files with 22 additions and 3 deletions

View File

@ -61,6 +61,14 @@ final class LocalizedPage: ChangeObservingItem {
content.isValidIdForTagOrPageOrPost(urlComponent) &&
!content.containsPage(withUrlComponent: urlComponent)
}
func update(hasContent: Bool) -> Bool {
if self.hasContent != hasContent {
self.hasContent = hasContent
return true
}
return false
}
}

View File

@ -153,7 +153,9 @@ final class Page: Item, DateItem, LocalizedItem {
guard content.storage.remove(pageContent: id, in: language) else {
return false
}
localized(in: language).hasContent = false
if localized(in: language).update(hasContent: false) {
self.didChange()
}
return true
}
@ -161,7 +163,9 @@ final class Page: Item, DateItem, LocalizedItem {
guard content.storage.save(pageContent: pageContent, for: id, in: language) else {
return false
}
localized(in: language).hasContent = true
if localized(in: language).update(hasContent: true) {
self.didChange()
}
return true
}
@ -169,8 +173,15 @@ final class Page: Item, DateItem, LocalizedItem {
Update the `hasContent` property of all localized pages.
*/
func updateContentExistence() {
var didUpdate = false
for language in ContentLanguage.allCases {
localized(in: language).hasContent = content.storage.hasPageContent(for: id, language: language)
let hasContent = content.storage.hasPageContent(for: id, language: language)
if localized(in: language).update(hasContent: hasContent) {
didUpdate = true
}
}
if didUpdate {
self.didChange()
}
}