Add labels to posts

This commit is contained in:
Christoph Hagen
2025-01-26 20:32:44 +01:00
parent 06b4c1ed76
commit 42fa08b43d
15 changed files with 273 additions and 30 deletions

View File

@ -17,6 +17,10 @@ final class LocalizedPost: ObservableObject {
@Published
var images: [FileResource]
/// The labels to show beneath the title
@Published
var labels: [ContentLabel]
/// The text to show for the link to the `linkedPage`
@Published
var pageLinkText: String?
@ -29,6 +33,7 @@ final class LocalizedPost: ObservableObject {
text: String,
lastModified: Date? = nil,
images: [FileResource] = [],
labels: [ContentLabel] = [],
pageLinkText: String? = nil,
linkPreview: LinkPreview = .init()) {
self.content = content
@ -36,6 +41,7 @@ final class LocalizedPost: ObservableObject {
self.text = text
self.lastModified = lastModified
self.images = images
self.labels = labels
self.pageLinkText = pageLinkText
self.linkPreview = linkPreview
}
@ -86,12 +92,14 @@ extension LocalizedPost {
text: data.text,
lastModified: data.lastModifiedDate,
images: data.images.compactMap(context.postMedia),
labels: data.labels?.compactMap { ContentLabel(context: context, data: $0) } ?? [],
pageLinkText: data.pageLinkText,
linkPreview: .init(context: context, data: data.linkPreview))
}
var data: Data {
.init(images: images.map { $0.id },
labels: labels.map { $0.data }.nonEmpty,
title: title,
text: text,
lastModifiedDate: lastModified,
@ -102,6 +110,7 @@ extension LocalizedPost {
/// The structure to store the metadata of a localized post
struct Data: Codable {
let images: [String]
let labels: [ContentLabel.Data]?
let title: String?
let text: String
let lastModifiedDate: Date?