✨ feat: add comment and tag collections with metadata and mock data
This commit is contained in:
+12
-12
@@ -24,12 +24,12 @@
|
||||
|
||||
const CONTENT_MEDIA_LOOKUP = ["blocks.heroImage.image:medialib", "blocks.image:medialib"].join(",")
|
||||
const NAVIGATION_CONTENT_LOOKUP = "elements.page:content"
|
||||
const CONTENT_COMMENTS_AGGREGATE = {
|
||||
collection: "comments",
|
||||
const CONTENT_COMMENT_AGGREGATE = {
|
||||
collection: "comment",
|
||||
foreignField: "contentId",
|
||||
op: "count",
|
||||
filter: { active: true },
|
||||
as: "commentsCount",
|
||||
as: "commentCount",
|
||||
}
|
||||
|
||||
let { url = "" }: { url?: string } = $props()
|
||||
@@ -138,7 +138,7 @@
|
||||
}
|
||||
let loading = $state(true)
|
||||
let notFound = $state(false)
|
||||
let comments = $state<any[]>([])
|
||||
let commentList = $state<any[]>([])
|
||||
|
||||
// Header scroll detection
|
||||
let scrolled = $state(false)
|
||||
@@ -187,7 +187,7 @@
|
||||
filter: { lang, path: routePath, active: true },
|
||||
sort: "sort",
|
||||
limit: 1,
|
||||
aggregate: CONTENT_COMMENTS_AGGREGATE,
|
||||
aggregate: CONTENT_COMMENT_AGGREGATE,
|
||||
lookup: CONTENT_MEDIA_LOOKUP,
|
||||
})
|
||||
|
||||
@@ -200,13 +200,13 @@
|
||||
}
|
||||
|
||||
try {
|
||||
comments = await getCachedEntries("comments", {
|
||||
commentList = await getCachedEntries("comment", {
|
||||
filter: { active: true, contentId: contentEntry.id as string },
|
||||
sort: "sort",
|
||||
})
|
||||
} catch (e) {
|
||||
console.error("Failed to load comments", e)
|
||||
comments = []
|
||||
console.error("Failed to load comment", e)
|
||||
commentList = []
|
||||
}
|
||||
} else {
|
||||
notFound = true
|
||||
@@ -396,14 +396,14 @@
|
||||
<div class="page-enter">
|
||||
<BlockRenderer blocks={contentEntry.blocks} />
|
||||
|
||||
{#if (contentEntry as any)?._aggregate?.commentsCount !== undefined}
|
||||
{#if (contentEntry as any)?._aggregate?.commentCount !== undefined}
|
||||
<div class="max-w-6xl mx-auto px-6 py-8 border-t border-gray-100 my-12">
|
||||
<h3 class="text-xl font-bold mb-6">
|
||||
Kommentare ({(contentEntry as any)._aggregate.commentsCount})
|
||||
Kommentare ({(contentEntry as any)._aggregate.commentCount})
|
||||
</h3>
|
||||
{#if comments && comments.length > 0}
|
||||
{#if commentList && commentList.length > 0}
|
||||
<div class="space-y-6">
|
||||
{#each comments as comment}
|
||||
{#each commentList as comment}
|
||||
<div class="bg-gray-50 p-6 rounded-lg">
|
||||
<div class="font-bold text-gray-900 mb-2">{comment.author}</div>
|
||||
<p class="text-gray-700 whitespace-pre-wrap">{comment.message}</p>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
import contentData from "../../mocking/content.json"
|
||||
import medialibData from "../../mocking/medialib.json"
|
||||
import navigationData from "../../mocking/navigation.json"
|
||||
import commentsData from "../../mocking/comments.json"
|
||||
import commentsData from "../../mocking/comment.json"
|
||||
|
||||
type EJsonObjectId = {
|
||||
$oid: string
|
||||
@@ -26,7 +26,7 @@ const mockRegistry: Record<string, Record<string, unknown>[]> = {
|
||||
content: normalizeMockCollection(contentData as Record<string, unknown>[]),
|
||||
medialib: normalizeMockCollection(medialibData as Record<string, unknown>[]),
|
||||
navigation: normalizeMockCollection(navigationData as Record<string, unknown>[]),
|
||||
comments: normalizeMockCollection(commentsData as Record<string, unknown>[]),
|
||||
comment: normalizeMockCollection(commentsData as Record<string, unknown>[]),
|
||||
}
|
||||
|
||||
function isEJsonObjectId(value: unknown): value is EJsonObjectId {
|
||||
@@ -263,7 +263,7 @@ function applyAggregate(entry: Record<string, unknown>, options?: ApiOptions): R
|
||||
continue
|
||||
}
|
||||
|
||||
// "comments:contentId:count"
|
||||
// "comment:contentId:count"
|
||||
const parts = spec.split(":")
|
||||
if (parts.length < 3) continue
|
||||
const targetCollection = parts[0]
|
||||
|
||||
Reference in New Issue
Block a user