Skip to content

feat: add comprehensive user activity stats to profile page#273

Merged
knoxiboy merged 2 commits into
knoxiboy:mainfrom
Harshit-Maurya838:feature/profile-activity-stats
May 25, 2026
Merged

feat: add comprehensive user activity stats to profile page#273
knoxiboy merged 2 commits into
knoxiboy:mainfrom
Harshit-Maurya838:feature/profile-activity-stats

Conversation

@Harshit-Maurya838
Copy link
Copy Markdown
Contributor

Description

This PR enhances the DoubtDesk profile page by introducing a comprehensive user activity statistics section to improve engagement visibility and gamification.

The implementation adds optimized backend aggregation APIs along with a responsive frontend stats grid displaying meaningful participation metrics for each user.

Related Issue

Closes #182

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update (README, guides, comments)
  • Style / UI change (no logic change)
  • Code refactor (no behavior change)
  • Test addition or update
  • Breaking change (fix or feature that would cause existing functionality to change)

Screenshots (if UI change)

Before After
image image

How Has This Been Tested?

  • Tested locally with npm run dev
  • Verified on mobile viewport (375px)
  • Verified on desktop viewport (1440px)

Checklist

  • I have tested my changes locally (npm run dev)
  • My code follows the existing code style (TypeScript, Tailwind, no any types)
  • I have not introduced unrelated changes (each PR should address one issue)
  • I have added comments where necessary
  • My branch is up to date with main
  • I have linked the related issue above
  • Screenshots are included (if this is a UI change)

@vercel
Copy link
Copy Markdown

vercel Bot commented May 24, 2026

@Harshit-Maurya838 is attempting to deploy a commit to the Karan Mani Tripathi 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot requested a review from knoxiboy May 24, 2026 12:38
@github-actions github-actions Bot added size/size/l gssoc'26 GSSoC program issue type:feature New feature labels May 24, 2026
@Harshit-Maurya838
Copy link
Copy Markdown
Contributor Author

@knoxiboy Please review this PR and I starred this Repo also

@knoxiboy knoxiboy added level:intermediate Intermediate level task and removed gssoc labels May 24, 2026
@knoxiboy knoxiboy requested a review from Copilot May 24, 2026 14:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new “Activity Stats” section to the profile page by introducing a dedicated backend stats endpoint and wiring the frontend to fetch and display additional engagement metrics.

Changes:

  • Added /api/profile/stats endpoint plus a DB aggregation helper to compute per-user activity metrics.
  • Updated the profile page UI to display a larger stats grid (including likes received, reply upvotes, doubts solved, active subject, member since).
  • Extended profile TypeScript types to represent the new activity stats payload.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
types/profile.ts Adds ActivityStats and CombinedStats interfaces for new stats data.
lib/profile/getProfileStats.ts New DB aggregation helper used by the stats API.
app/api/profile/stats/route.ts New API route that returns aggregated user activity stats.
app/profile/page.tsx Fetches /api/profile/stats and renders expanded stats grid on the profile page.
package-lock.json Lockfile metadata changes (platform-specific entries adjusted).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/profile/page.tsx
Comment on lines +138 to 143
.then(([profileRes, statsRes]: [ProfileData, { success: boolean, stats: ActivityStats }]) => {
if (profileRes.user && statsRes.success) {
setProfileData(profileRes);
setActivityStats(statsRes.stats);
setEmailNotificationsEnabled(profileRes.user.emailNotificationsEnabled ?? true);
} else {
Comment on lines +12 to +15
const replyQuery = db.select({
totalReplies: count(repliesTable.id),
totalReplyUpvotes: sum(repliesTable.upvotes).mapWith(Number),
}).from(repliesTable).where(or(eq(repliesTable.userEmail, email), eq(repliesTable.userName, userName)));
Comment on lines +24 to +26
const rawJoinDate = stats.userCreatedAt || (clerkUser?.createdAt ? new Date(clerkUser.createdAt) : new Date());
const memberSince = rawJoinDate instanceof Date ? rawJoinDate.toISOString() : new Date(rawJoinDate).toISOString();

Comment on lines +7 to +23
export async function GET(req: Request) {
try {
const { userId } = await auth();
if (!userId) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}

const clerkUser = await currentUser();
const email = clerkUser?.primaryEmailAddress?.emailAddress;
const name = clerkUser?.fullName || clerkUser?.firstName || "Unknown";

if (!email) {
return NextResponse.json({ error: "No email found" }, { status: 400 });
}

const stats = await getProfileStats(email, name);

Copy link
Copy Markdown
Owner

@knoxiboy knoxiboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: Thank you for starring the repository! The PR is approved.

@knoxiboy knoxiboy merged commit b00ba49 into knoxiboy:main May 25, 2026
5 of 8 checks passed
@knoxiboy knoxiboy added gssoc:approved Approved for GSSoC mentor:knoxiboy Reviewed by mentor knoxiboy quality:clean Clean code quality labels May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved for GSSoC gssoc'26 GSSoC program issue level:intermediate Intermediate level task mentor:knoxiboy Reviewed by mentor knoxiboy quality:clean Clean code quality type:feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add user activity stats to profile page (doubts asked, replies given, likes received)

3 participants