Fix id of Items, saving

This commit is contained in:
Christoph Hagen
2025-06-11 08:19:44 +02:00
parent 5970ce2e9f
commit 1d0eba9d78
64 changed files with 233 additions and 217 deletions

View File

@ -7,11 +7,17 @@ class Item: ChangeObservingItem, Identifiable {
@Published
private var changeToggle = false
/// A session-id for the item for identification
let id = UUID()
/// The unique, persistent identifier of the item
///
/// This identifier is not used for `Identifiable`, since it may be changed through the UI.
@Published
var id: String
var identifier: String
init(content: Content, id: String) {
self.id = id
self.identifier = id
super.init(content: content)
observeChanges()
@ -44,14 +50,14 @@ class Item: ChangeObservingItem, Identifiable {
}
var itemId: ItemId {
.init(type: itemType, id: id)
.init(type: itemType, id: identifier)
}
}
extension Item: Equatable {
static func == (lhs: Item, rhs: Item) -> Bool {
lhs.id == rhs.id && lhs.itemType == rhs.itemType
lhs.id == rhs.id
}
}
@ -59,13 +65,12 @@ extension Item: Hashable {
func hash(into hasher: inout Hasher) {
hasher.combine(id)
hasher.combine(itemType)
}
}
extension Item: Comparable {
static func < (lhs: Item, rhs: Item) -> Bool {
lhs.id < rhs.id && lhs.itemType < rhs.itemType
lhs.identifier < rhs.identifier && lhs.itemType < rhs.itemType
}
}

View File

@ -31,11 +31,11 @@ extension ItemReference: Identifiable {
case .feed:
return "1-feed"
case .post(let post):
return "2-post-\(post.id)"
return "2-post-\(post.identifier)"
case .page(let page):
return "3-page-\(page.id)"
return "3-page-\(page.identifier)"
case .tagPage(let tag):
return "5-tag-\(tag.id)"
return "5-tag-\(tag.identifier)"
case .tagOverview:
return "4-tag-overview"
}
@ -76,11 +76,11 @@ extension ItemReference: CustomStringConvertible {
case .feed:
return "Feed"
case .post(let post):
return "Post \(post.id)"
return "Post \(post.identifier)"
case .page(let page):
return "Page \(page.id)"
return "Page \(page.identifier)"
case .tagPage(let tag):
return "Tag \(tag.id)"
return "Tag \(tag.identifier)"
case .tagOverview:
return "Tag Overview"
}