Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions apps/web/content/docs/content-engine/comments-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const comments = useContentComments({ queryKey, thread, ...actions })
| `onChanged` | `(queryClient) => void \| Promise<void>` | No | Refreshes your other queries after a successful write, such as a comment count elsewhere on the page |
| `branches` | `(ids) => Promise<Response>` | No | [`GET /thread/branches`](#get-threadbranches) with `root`, plus `ids` joined by commas only when there are any. Writes then re-read only the branch they touched instead of every loaded page. `live` needs it |
| `live` | `{ contentTypeId, rootId }` | No | The comment content type's `id` and the root record's id. Keeps the thread current over the WebSocket while it is mounted; ignored without `branches`. See [Live comments](/docs/content-engine/threads-live) |
| `history` | `{ list(id), entry(id, revisionId) }` | No | `GET /{id}/history` and `GET /{id}/history/{revisionId}`, which every type with `editorial` revisions has. An **edited** link next to the date then opens who edited the comment and what changed. Signed-in members only |

### Callback contract

Expand Down Expand Up @@ -95,10 +96,24 @@ Its `queryFn` throws when the thread route answers anything but `2xx`.

## `ContentComments`

The complete section: the count, the thread, **Load more comments**, the composer (hidden from guests), the actions menu, the delete confirmation and the report dialog. It scrolls to and rings the comment a `#comment-...` link points to, loading more pages until it appears.
The complete section, and the look every comment section in VitNode shares - Blog, Newsroom and Forum use it as is:

- Each top-level comment is a **card**: avatar, author, date and actions menu on a tinted header, then the text, its reactions, **Quote** and **Share**.
- Its replies sit inside the card in the order they were written, joined by a thin line. A reply to a reply says whom it answers ("In reply to Ada"), so deep conversations stay readable without indenting.
- A **Write a reply** field closes each card for members who can answer.
- Readers sort conversations by **Oldest**, **Newest** or **Most points** (each conversation's reaction points). A thread with more than ten conversations folds the middle ones behind a **Load more…** gap.
- Hidden comments fold behind a notice their author and moderators can open.

Below the conversations come **Load more comments**, the live status and the composer (hidden from guests). It scrolls to and rings the comment a `#comment-...` link points to, loading more pages until it appears.

```tsx
<ContentComments comments={comments} />
<ContentComments
anchorKey={comment => comment.slug}
authorIds={[article.author.id]}
comments={comments}
permalink={anchorId => `/blog/article/${article.slug}#${anchorId}`}
shareTitle={article.title}
/>
```

| Prop | Description |
Expand All @@ -107,11 +122,14 @@ The complete section: the count, the thread, **Load more comments**, the compose
| `className` | Classes for the `<section>` |
| `title` | Replaces the "N comments" heading |
| `anchorKey(record)` | What follows `comment-` in each comment's element id. Defaults to the id; return the slug to match slug permalinks |
| `permalink(anchorId)` | The link on each comment's date. Defaults to `#comment-...` on the same page |
| `permalink(anchorId)` | The link on each comment's date, and what **Share** shares. Defaults to `#comment-...` on the same page |
| `shareTitle` | The title **Share** sends along, usually the commented record's |
| `authorIds` | Users whose comments get an **Author** badge, such as the article's authors or the topic's starter |
| `points` | Shows each comment's points from reactions next to its reaction bar. Off by default |
| `render.author(record)` | Replaces the author's name |
| `render.body(record)` | Replaces the text |
| `render.meta(record)` | Adds details after the date, such as a badge |
| `render.actions(record)` | Adds buttons next to **Reply** |
| `render.actions(record)` | Adds buttons next to **Quote** and **Share** |

The section's element id is `comments`, so `#comments` links scroll to it. Its messages live in the `core.comments` namespace; add it to the page's route `messages` to load them with the page.

Expand Down Expand Up @@ -176,7 +194,7 @@ const MyComment = ({ node }) => {
| `contentCommentAuthor(record)`, `contentCommentAuthorName(person)` | Read the `author` person and the name to show |
| `useContentCommentErrorToast()` | Shows the section's message for a failed action's status |

The Blog plugin's `plugins/blog/src/pages/post-comments.tsx` is a complete custom layout: rail connectors, collapsible branches, share buttons and slug permalinks, with every action from these components.
Reach for these only when the shared look really doesn't fit: a comment section that looks different from every other one in the app is one more thing for readers to learn.

## Outcomes and errors

Expand Down
Binary file not shown.
24 changes: 8 additions & 16 deletions apps/web/content/docs/content-engine/threads-frontend.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ implementation:

import { Tab, Tabs } from "fumadocs-ui/components/tabs";

import { ImgDocs } from "@/components/fumadocs/img";
import tree from "./threads-frontend-tree.webp";

Replies let a comment answer another comment, so a conversation can branch. The thread route already returns each top-level comment followed by every answer below it, and the shared section draws them as a tree. This page raises the depth limit and tells the section about it, which turns on **Reply**.
Replies let a comment answer another comment, so a conversation can branch. The thread route already returns each top-level comment followed by every answer below it, and the shared section draws each conversation as a card. This page raises the depth limit and tells the section about it, which turns on **Reply**.

This continues the comment section from [Comments](/docs/content-engine/threads). Replies work with or without [Comment actions](/docs/content-engine/threads-editing).

Expand Down Expand Up @@ -82,7 +79,7 @@ import { COMMENT_MAX_DEPTH } from "@/content/comment"; // [!code ++]
maxDepth: COMMENT_MAX_DEPTH, // [!code ++]
```

That is the whole change. `create` already sends `parent: parentId`, which is now the comment being answered instead of `null`. The section shows **Reply** under every comment above the limit, opens a composer under it, and draws replies indented below their parent. Below three levels it stops indenting, so deep branches stay readable on a phone.
That is the whole change. `create` already sends `parent: parentId`, which is now the comment being answered instead of `null`. The section shows **Reply** under every comment above the limit and a **Write a reply** field at the bottom of each conversation. Replies sit inside their conversation's card in the order they were written, and a reply to a reply names whom it answers - no indenting, so deep conversations stay readable on a phone.

</Step>

Expand All @@ -92,16 +89,11 @@ That is the whole change. `create` already sends `parent: parentId`, which is no

Open an article with a comment and sign in as a member:

1. Click **Reply** under the comment, write an answer and click **Post comment**. **Comment posted** appears and the answer shows indented below the comment.
2. Reply to the reply, and again, until a reply sits at depth 4. That reply has no **Reply** button.
1. Click **Write a reply** under the comment, write an answer and click **Post comment**. **Comment posted** appears and the answer shows inside the comment's card.
2. Reply to the reply with its **Reply** button, and again, until a reply sits at depth 4. That reply has no **Reply** button, and each answer says "In reply to" whom.
3. Reload. The tree comes back the same way.

<ImgDocs
withoutBackground
className="*:max-w-full"
src={tree}
alt="A comment by Ada Lovelace with an indented reply by Grace Hopper, a reply to that reply, and a fourth-level reply without a Reply button"
/>
{/* Image prompt: A VitNode article's comment section in light theme: a card for Ada Lovelace's comment with a tinted header, her text, a reaction pill and Quote/Share icons, then inside the same card a reply by Grace Hopper and a reply to that reply marked "In reply to Grace Hopper", joined by a thin vertical line, and a "Write a reply" field at the bottom of the card. Oldest / Newest / Most points toggle above. 1440x900. */}

## Long conversations

Expand All @@ -112,14 +104,14 @@ Open an article with a comment and sign in as a member:

## Removed and hidden comments in a tree

- **Deleted with replies.** A comment deleted while it has replies stays as a **[deleted]** placeholder with no text and no author. It reads "Comment deleted by user" or "Comment removed by a moderator". Its replies keep their place, and you can still answer them.
- **Hidden with replies.** Readers who can't see a hidden comment get the same placeholder, so the branch below it stays readable. Its author and moderators see the real comment, marked **Hidden**. The section offers no **Reply** on a hidden comment.
- **Deleted with replies.** A top-level comment deleted while it has replies keeps its card, with a note instead of its text and author: "Comment deleted by user" or "Comment removed by a moderator". Its replies keep their place, and you can still answer them.
- **Hidden with replies.** Readers who can't see a hidden comment get the same note, so the conversation below it stays readable. Its author and moderators see the real comment folded behind "This comment was hidden." with **Show comment**. The section offers no **Reply** on a hidden comment.
- **Removed without replies.** The comment disappears. There's no branch below it to hold up.

The server keeps the tree valid on every write, in the AdminCP too: the parent must exist, be public and belong to the same article, a comment never answers itself or one of its own answers, and nothing nests deeper than `maxDepth`. A reply that breaks a rule answers `400`, and the composer keeps its text.

## Related

- [Notifications](/docs/content-engine/notifications): optional. Tell members about replies to their comments, sent by the server with no change to the section.
- [Comments API](/docs/content-engine/comments-api): build your own tree layout with `ContentCommentsRoot`, as the Blog plugin does with its connectors and collapsible branches.
- [Comments API](/docs/content-engine/comments-api): every `ContentComments` option, and the building blocks for a layout of your own.
- [thread reference](/docs/content-engine/reference#thread): every `thread` option.
7 changes: 5 additions & 2 deletions apps/web/content/docs/guides/blog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,16 @@ An edited comment shows **edited ▾** next to its date. It lists who wrote the

Above the conversation, **Oldest** (the default) reads them in the order they
started, **Newest** puts the conversations with the latest activity first, and
**Top** puts the most-reacted comments first, then the ones with the most
replies. The order holds while you read: a new reply shows up live but doesn't
**Most points** puts the comments whose reactions are worth the most points
(set in **AdminCP → Reactions**) first, then the ones with the most replies. The order holds while you read: a new reply shows up live but doesn't
move its conversation, and a new conversation joins at the top (Newest) or the
bottom. Pick a sort again to re-sort.

A busy article doesn't turn into a wall: past 10 conversations, the middle folds into a **12 hidden conversations** box between the first five and the last two. **Load more…** brings back ten at a time, and a link to one comment always shows them all.

This is the Content Engine's shared [comment section](/docs/content-engine/comments-api#contentcomments),
so forum topics and news articles look and behave the same way.

Comments are a Content Engine [thread](/docs/content-engine/threads): the
`blog.comment` content type, stored in `blog_comments`, with the article as the
thread's root. One conversation is shared by every translation of an article,
Expand Down
Loading
Loading