Skip to content

feat: community comments support rich text and media array (#805)#807

Open
clbotdev wants to merge 3 commits into
mainfrom
feat/community-comments-rich-text
Open

feat: community comments support rich text and media array (#805)#807
clbotdev wants to merge 3 commits into
mainfrom
feat/community-comments-rich-text

Conversation

@clbotdev

Copy link
Copy Markdown
Collaborator

Summary

Community comments/replies now support rich text (ProseMirror) and media attachments, matching the feature set already available for community posts. Closes #805.

Changes

Backend

  • packages/orm-models/src/models/community-comment.ts — Changed content field in both CommunityCommentSchema and ReplySchema from String to mongoose.Schema.Types.Mixed to store ProseMirror documents. Added TextEditorContent type import to interfaces.
  • apps/web/graphql/communities/helpers.ts — Added normalizeTextEditorContent() call in formatComment() to automatically convert existing string-based comments to ProseMirror format for backward compatibility.
  • apps/web/graphql/communities/logic.ts — Updated postComment() parameter type from content: string to content: TextEditorContent | string.
  • apps/web/graphql/communities/mutation.ts — Updated GraphQL mutation to pass content as JSONObject and include media in postComment arguments.
  • apps/web/graphql/communities/types.ts — Updated GraphQL type definitions for comment content and media fields.
  • packages/common-models/ — Updated TypeScript interfaces to include TextEditorContent | string union type for content.

Frontend

  • apps/web/components/community/comment.tsx — Added rich text rendering using <TextRenderer> for ProseMirror content, with backward-compatible plain string display for existing comments. Added media display via <MediaPreview>.
  • apps/web/components/community/comment-section.tsx — Replaced <Textarea> with <Editor> (TextEditor) for rich text input. Added media upload capabilities (file attachment popover, GIF selector, YouTube link). Updated GraphQL mutations to send content as JSON and include media array.

Backward Compatibility

Existing string-based comments are automatically normalized to ProseMirror format via normalizeTextEditorContent() in the GraphQL helper layer. The Mongoose schema accepting Mixed type ensures old string values remain valid in the database. The frontend renders both formats seamlessly.

Ubuntu added 3 commits June 19, 2026 18:09
The apps/web/models/CommunityComment.ts file had content: { type: String } on both
the ReplySchema and CommunityCommentSchema, causing Mongoose validation errors
when posting rich text content (which is an object, not a string).

The orm-models package already had the correct Mixed type, but the web app
model at apps/web/models/ was never updated to match. This caused:
- 'Cast to string failed' when posting comments with rich text content
- 'Cast to string failed' when posting replies with rich text content

Fixed by changing both content field definitions to use mongoose.Schema.Types.Mixed,
matching the CommunityPost schema pattern.
…courselit/orm-models

Follow the Course.ts pattern — import InternalCommunityComment,
InternalReply, and CommunityCommentSchema from @courselit/orm-models,
wrap in mongoose.model(), and re-export types.

Removes ~75 lines of duplicated schema and interface code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Community comments should support rich text and media array

1 participant