Skip to content

feat: implement patch#41

Merged
mehdiasadli merged 1 commit into
mainfrom
v26-05-06
May 5, 2026
Merged

feat: implement patch#41
mehdiasadli merged 1 commit into
mainfrom
v26-05-06

Conversation

@mehdiasadli
Copy link
Copy Markdown
Contributor

@mehdiasadli mehdiasadli commented May 5, 2026

Summary by CodeRabbit

  • New Features

    • Leaderboard now supports time-period filtering (weekly, monthly, yearly, and all-time views).
    • New admin dashboard with site analytics, activity charts, top creators and players, recent games, and bulk job tracking.
    • Email notifications for post reactions, comments, and replies.
    • Two new achievement badges: Dominator and Survivor.
  • Chores

    • Released version 2026-05-patch6.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
xamsa-web Ready Ready Preview, Comment May 5, 2026 10:06am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR introduces five major features: leaderboard period filtering (week/month/year/all), post engagement email notifications for reactions/comments/replies, an admin staff dashboard with metrics and activity charts, new "dominator" and "survivor" badges with end-of-game evaluation, and updates to app release metadata for v26.05.06.

Changes

Leaderboard Period Support

Layer / File(s) Summary
Schema & Validation
packages/schemas/src/modules/user.ts
LeaderboardPeriodSchema enum added (week, month, year, all); GetGlobalLeaderboardInputSchema gains period field defaulting to "all"; GlobalLeaderboardRowSchema adds periodValue integer field for ranked metrics.
API Implementation
packages/api/src/modules/user/leaderboard-period.ts, global-leaderboard.ts
periodStart() utility computes UTC window boundaries (Jan 1 for year, month 1st for month, ISO-week Monday for week, null for all). Leaderboard query branches on period: lifetime path returns periodValue via lifetimePeriodValue() helper; windowed path aggregates per-user metrics over rolling windows via getWindowedLeaderboard(), with board-specific aggregation logic, deterministic ranking, tie handling, and offset pagination.
Web Route & UI
apps/web/src/routes/leaderboard/index.tsx
Adds period state and tablist selector; passes period to leaderboard query; updates board hint text to distinguish windowed vs. all-time contexts; metric labels and value rendering become period-aware (e.g., "Elo Δ" for windowed, displays row.periodValue with Elo-specific formatting).
Search Integration
apps/web/src/lib/home-search-commands.ts
Imports LeaderboardPeriodType and LEADERBOARD_PERIODS; updates analyzeHomeSearchQuery to parse leaderboard:<board>, leaderboard:<period>, or leaderboard:<board>:<period> (order-independent); builds search.tab and search.period accordingly.

Post Engagement Email Notifications

Layer / File(s) Summary
Database Schema
packages/db/prisma/migrations/20260505081345_v26_05_06_engagement_emails/migration.sql, packages/db/prisma/schema/post.prisma, packages/db/prisma/schema/auth.prisma, packages/db/prisma/schema/pack.prisma
Adds three notification tables (reactionEmailNotification, commentEmailNotification, replyEmailNotification) with sentAt timestamps and composite indexes on (recipientUserId, contentId, sentAt) for deduplication; Prisma relations added to User, Post, and Comment models.
Data Schemas
packages/schemas/src/db/schemas/models/*.schema.ts, packages/schemas/src/db/schemas/enums/*NotificationScalarFieldEnum.schema.ts
Zod schemas for three notification models and their scalar field enums.
Mail Templates
packages/mail/src/notifications.ts
Exports sendReactionEmail(), sendCommentEmail(), and sendReplyEmail() helpers that build transactional HTML with escaped snippets, conditional dev logging, and sendEmail() calls when enabled.
Notification Handlers
packages/api/src/lib/post-engagement-notifications.ts
Exports notifyReactionEmail(), notifyCommentEmail(), and notifyReplyEmail() which fetch relevant data, skip self-notifications, deduplicate within 15-minute window, resolve actor names/emojis, send mail via corresponding email function, and persist notification records on success.
Service Integration
packages/api/src/modules/reaction/service.ts, packages/api/src/modules/comment/service.ts
setReaction() now fires notifyReactionEmail() after transaction when reaction is newly created for a post; createComment() now fires notifyCommentEmail() for top-level post comments or notifyReplyEmail() for replies after transaction.

Admin Dashboard Staff Overview

Layer / File(s) Summary
Output Schema
packages/schemas/src/modules/admin.ts
Defines GetAdminOverviewOutputSchema and supporting component schemas (totals, recent 7d, top creators/players, recent games, 14-day activity grid, bulk job counts, role breakdown).
API Implementation
packages/api/src/modules/admin/overview.ts
getAdminOverview() executes parallel Prisma queries for global counts, 7-day deltas, top creators by pack plays, top players by ELO, recent completed games, per-day activity aggregates via $queryRaw/date_trunc, bulk job status counts, and role distribution. Returns normalized GetAdminOverviewOutputType.
Router Wiring
packages/api/src/modules/admin/router.ts
Adds adminRouter.getOverview route using moderatorProcedure, wired to getAdminOverview() with GetAdminOverviewOutputSchema output.
Dashboard UI
apps/web/src/routes/dashboard/index.tsx
Fetches admin overview via useQuery(); renders loading spinner and error alert states; displays sections for site totals with 7-day deltas, 14-day stacked bar activity chart, top creators/players tables, recent games with relative timestamps and optional winner/pack display, bulk job status tiles with "Open jobs" link, and quick links; UI components include StatTile, TotalsSection, ActivitySection, UserMini, TopCreatorsSection, TopPlayersSection, formatRelative() helper, RecentGamesSection, JobsSection.

Badge Enhancements

Layer / File(s) Summary
Schema Updates
packages/schemas/src/modules/badge.ts
BadgeIdSchema enum extended to include "dominator" and "survivor".
Badge Catalog
packages/utils/src/badges.ts
Adds two new badge entries with id/name/description/requirements/color/icon/period/type/category/assignment metadata; updates BADGE_ID_ZOD_TUPLE to recognize the new IDs.
Game Finalization Logic
packages/api/src/modules/game/finalize-game.ts
Extends appendGameBadgeEvent() to accept "dominator" and "survivor" badge IDs; adds conditional logic after per-topic genius/dunce awards to evaluate dominator (winner score margin threshold and player-count minimum) and survivor (runner-up score margin) conditions and award respective badges to winner when met.

Release & Metadata Updates

Layer / File(s) Summary
App Release Metadata
packages/utils/src/app-releases.ts
Updates current CalVer baseline from patch 5 to patch 6 ({ year: 2026, month: 5, patch: 6 }); prepends new release entry for "2026-05-06" with title and highlights.
Roadmap Content
apps/web/src/lib/roadmap-content.ts
Marks v26.05.06 roadmap entry as implemented: true to reflect shipped status on staff dashboard.

Sequence Diagram(s)

sequenceDiagram
    participant User as Client User
    participant Web as Web App
    participant API as Backend API
    participant DB as Database
    participant Mail as Mail Service

    Note over User,Mail: Post Engagement Email Notification Flow
    User->>Web: Submit reaction/comment/reply
    Web->>API: POST /reactions or /comments
    API->>DB: Create reaction or comment in transaction
    DB-->>API: Return created record with IDs
    API->>API: Check dedupe (email notification within 15m)
    alt Dedupe miss (first notification)
        API->>DB: Fetch post & recipient user
        API->>DB: Fetch recipient email
        alt Email verified & not self-notification
            API->>Mail: sendReactionEmail / sendCommentEmail / sendReplyEmail
            Mail-->>API: Email sent
            API->>DB: Record notification event (reactionEmailNotification / commentEmailNotification / replyEmailNotification)
        end
    end
    API-->>Web: Success response
    Web-->>User: Display feedback

    Note over User,Mail: Admin Dashboard Overview Load
    User->>Web: Navigate to /dashboard (staff)
    Web->>API: GET orpc.admin.getOverview
    API->>DB: Parallel batch queries (totals, 7d deltas, top creators/players, recent games, 14d activity, jobs, roles)
    DB-->>API: Aggregated results
    API-->>Web: GetAdminOverviewOutputType
    Web->>Web: Render totals, activity chart, tables, job status
    Web-->>User: Display dashboard
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • asmelabs/xamsa#11: Modifies leaderboard code in packages/api/src/modules/user/global-leaderboard.ts and apps/web/src/routes/leaderboard/index.tsx for period-related functionality.
  • asmelabs/xamsa#23: Modifies game finalization badge-awarding logic in packages/api/src/modules/game/finalize-game.ts to support additional badge types.
  • asmelabs/xamsa#36: Modifies reaction service (packages/api/src/modules/reaction/service.ts) to add notification side-effects on reaction creation.

Suggested labels

app:web, pkg:api, database, size:xl

Poem

🐰 A rabbit hops through leaderboards of time,
From weeks to years in metrics sublime,
While emails flutter—reactions, comments too,
Admins now watch what all their players do,
Dominators and survivors earn their badge,
v26.05.06 ships without a smash!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'feat: implement patch' is vague and generic, using non-descriptive terms that do not convey meaningful information about the changeset. Replace with a more specific title that summarizes the main changes, such as 'feat: add leaderboard period filtering and post engagement notifications' or similar.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch v26-05-06

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mehdiasadli mehdiasadli merged commit e69e664 into main May 5, 2026
4 of 5 checks passed
@mehdiasadli mehdiasadli deleted the v26-05-06 branch May 5, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant