Skip to content

feat: add recently viewed posts backend and dashboard integration#151

Open
AYUSH-P-SINGH wants to merge 1 commit into
ARUNNG2004:mainfrom
AYUSH-P-SINGH:api_post_view
Open

feat: add recently viewed posts backend and dashboard integration#151
AYUSH-P-SINGH wants to merge 1 commit into
ARUNNG2004:mainfrom
AYUSH-P-SINGH:api_post_view

Conversation

@AYUSH-P-SINGH

Copy link
Copy Markdown

Pull Request Description

Summary

This PR adds support for tracking recently viewed posts for authenticated users. Whenever a user opens the comments section of a post from the dashboard, the application records that post in the user's recentlyViewed history.

The backend maintains a unique, ordered list of recently viewed posts in Firestore, ensuring duplicate entries are moved to the top and the history never exceeds 10 posts.


What This PR Does

Backend

  • Added a new POST endpoint:
POST /api/posts/view

The endpoint:

  • Accepts userId and postId.
  • Validates that the referenced post exists.
  • Retrieves the user's existing recentlyViewed history.
  • Removes any previous occurrence of the viewed post.
  • Inserts the post at the beginning of the list.
  • Limits the history to the most recent 10 unique posts.
  • Updates the user's Firestore document using a merge operation.

Frontend

Updated the dashboard feed to automatically track recently viewed posts.

When a user expands a post's comments section (toggleComments), the frontend asynchronously calls the /api/posts/view endpoint without affecting the user experience.


Implementation Details

New

  • app/api/posts/view/route.js

    • Implements the recently viewed posts API.
    • Validates requests.
    • Updates the user's recentlyViewed array in Firestore.

Modified

  • app/page.js

    • Integrates recently viewed tracking into the comments toggle workflow.

Testing

Backend

  • ✅ Verified that the API correctly stores recently viewed posts.
  • ✅ Confirmed duplicate post views move the post to the top instead of creating duplicate entries.
  • ✅ Verified the history is capped at 10 unique posts.
  • ✅ Confirmed empty histories are handled correctly.
  • ✅ Verified invalid or non-existent posts are rejected appropriately.

Project Validation

  • npm run check:structure
  • npm run build

Both completed successfully.


Type of Change

  • ✅ ✨ New feature (non-breaking change)

Checklist

  • ✅ My code follows the project's coding standards.
  • ✅ I have performed a self-review of my code.
  • ✅ My changes introduce no new warnings or errors.
  • ✅ The feature has been tested locally.
  • ✅ Existing functionality remains unaffected.

FIXES #149

@netlify

netlify Bot commented Jul 11, 2026

Copy link
Copy Markdown

👷 Deploy request for devconnectai pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 09878a7

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.

FEATURE(BACKEND):Add Recently Viewed Posts

1 participant