Product Page¶
The ProductPage is the detailed view for a specific marketplace listing. It provides buyers with a comprehensive breakdown of the item, an interactive media gallery, and direct actions to either add the item to their cart or immediately initiate a purchase negotiation.
The interface is structured using a responsive CSS Grid with a maximum width of 1500px, splitting the layout into a sticky media gallery on the left and scrollable product details on the right for desktop users.
Component Architecture¶
The page aggregates several sub-components to organize the dense product data into digestible sections.
1. Media Gallery & Lightbox¶
- Main Viewer: Displays the currently selected image or video. Videos feature an absolute-positioned play button overlay and fall back to thumbnails when available.
- Thumbnails: A horizontally scrollable list of all attached media. Clicking a thumbnail updates the
mainMediaIndexstate to swap the main viewer's content. - CarouselModal: Clicking the main image triggers a high-z-index, full-screen lightbox for immersive viewing.
2. Action Buttons¶
- Buy Now: Triggers the
useFetchChatIdhook. This acts as the direct checkout flow by generating (or retrieving) a dedicated chat room with the seller for this specific product, instantly redirecting the user to/inbox/:chatId. - Add to Cart: Triggers the
useCreateCartmutation. If the product is already in the cart (isInCart), the button dynamically changes its label and routes the user to the/cartpage instead.
3. Tabbed Content Interface¶
To prevent vertical UI clutter, secondary information is organized into three toggleable tabs:
- Details Tab: Displays the product specifications (category, location, quantity), listing rules (delivery/payment terms), and specific product conditions.
- Comments Tab: Reuses the social comment thread component (
CommentsTab). - Reviews Tab: Uses
useFetchReviewto display an infinitely scrolling list of verified buyer reviews, including their star ratings and feedback.
State Management & Cache Seeding¶
This page uses @tanstack/react-query to ensure instant load times by intelligently reusing existing data.
- Initial Data Seeding: The
useFetchPosthook is configured with aninitialDatafunction. Before making a network request, it scans the deeply nested["posts"]infinite query cache (from the Main Feed or Marketplace). If it finds a matching product ID, it instantly paints the UI with that cached data while fetching fresh data in the background. - Infinite Reviews: The
ReviewsTabusesreact-intersection-observerto fetch the next cursor-based page of product reviews automatically when the user reaches the bottom of the tab.
API Endpoints & Data Structures¶
The product page interacts with the backend via several endpoints through the authApi Axios instance.
1. Fetch Product Details¶
Retrieves the complete data object for a specific product post.
- Endpoint:
GET /posts/post_retrieve/:postId - Authorization: Required (Bearer Token)
- Response Structure (
ExtendPostType): Returns the standardPostTypecombined with anis_cartboolean to indicate if the user already has this item staged.
2. Fetch Product Reviews (Infinite)¶
Retrieves the paginated list of reviews associated with this specific product.
- Endpoint:
GET /posts/review/ - Query Parameters:
productId: The ID of the current product.c: Cursor string for pagination.- Authorization: Required (Bearer Token)
- Response Structure (
PaginatedReviews):{ "next": "url_string | null", "previous": "url_string | null", "results": [ { "review_id": "string", "product": "string", "text": "string", "created_at": "ISO 8601 string", "rating": 5, "author": { "id": "string", "username": "string", "email": "string", "profile": { /* ReviewUserProfile */ } } } ] }
3. Action Endpoints¶
- Buy Now (Chat):
POST /chat/confirm_chat/ - Add to Cart:
POST /posts/cart/