Posts

This page describes how posts are created, edited, and validated in the social feature. All post and comment actions require the user to be logged in; the API client sends the session Bearer token automatically.

Create Post

Creating a post is done from the social feed via a modal (SocialCreatePostModal). The user chooses the type (text, photo, or video), enters content, and optionally attaches media. The form is validated with createPostSchema (Zod) before submission.

Validation Rules

  • Content — Required, trimmed, 1–1000 characters.
  • Photo — At least one image file (or image URL when editing/preview).
  • Video — One video file (or video URL when supported).

The helper canSubmitCreatePost mirrors these rules so the "Post" button can be disabled until the form is valid.

Create API

createPostAction (and createPostApi) build a FormData with content and, for photo/video, media (files). The request is POST /posts withmultipart/form-data. On success, the feed can be refreshed or the modal closed.

Edit Post

The edit flow lives at /social/edit/[id]. The page loads the post with getPostApi (GET /posts/:id), then the user can change content and media. Updates are sent with PUT /posts/:id (via updatePostApi). The same validation rules (content length, photo/video requirements) apply where applicable.

Comments

Comments are displayed on each post card and can be expanded/collapsed. To add a comment, the user types in the comment input (max 100 characters); the frontend calls createCommentApi with postId and content, which sends POST /comments. The comment list is updated from the API response or by refetching the post.

Data Types

Post and comment shapes are defined in src/features/social/types/: Post, SocialComment, UserSummary, and the API response types in post-api.ts (PostApi, ListPostsResponse, etc.). The mapper mapPostApiToPost converts API responses to the UI model (e.g. relative time for createdAt).