Skip to content

feat: implement patch#43

Merged
mehdiasadli merged 2 commits into
mainfrom
v26-05-08
May 6, 2026
Merged

feat: implement patch#43
mehdiasadli merged 2 commits into
mainfrom
v26-05-08

Conversation

@mehdiasadli
Copy link
Copy Markdown
Contributor

@mehdiasadli mehdiasadli commented May 6, 2026

Summary by CodeRabbit

Release Notes

New Features

  • Post insights dashboard for authors displaying analytics (views, reactions, comments, bookmarks) and top contributor rankings
  • View counter now displayed on posts
  • Keyboard shortcuts for faster game hosting and control
  • Enhanced pack filtering: language, difficulty bands, minimum topic count, and hide-finished toggle
  • Bulk delete functionality for managing pack topics
  • Daily play streak visualization on user profiles

@vercel
Copy link
Copy Markdown

vercel Bot commented May 6, 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 6, 2026 10:18am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 706c684b-a1a9-4ad0-9eef-06b02bae9091

📥 Commits

Reviewing files that changed from the base of the PR and between b718e20 and 65b2c9b.

📒 Files selected for processing (34)
  • apps/web/src/components/home/home-feed.tsx
  • apps/web/src/components/host-shortcuts-help.tsx
  • apps/web/src/components/host-view.tsx
  • apps/web/src/components/pack-filters.tsx
  • apps/web/src/components/pack-topics-list.tsx
  • apps/web/src/components/post-insights/post-insights-view.tsx
  • apps/web/src/components/profile/play-streak-strip.tsx
  • apps/web/src/hooks/use-host-shortcuts.ts
  • apps/web/src/hooks/use-post-view-tracker.ts
  • apps/web/src/lib/roadmap-content.ts
  • apps/web/src/routeTree.gen.ts
  • apps/web/src/routes/p/$postSlug.tsx
  • apps/web/src/routes/p/$postSlug/insights.tsx
  • apps/web/src/routes/packs/index.tsx
  • apps/web/src/routes/u/$username.tsx
  • packages/api/src/modules/pack/service.ts
  • packages/api/src/modules/post/router.ts
  • packages/api/src/modules/post/service.ts
  • packages/api/src/modules/topic/router.ts
  • packages/api/src/modules/topic/service.ts
  • packages/api/src/modules/user/router.ts
  • packages/api/src/modules/user/service.ts
  • packages/db/prisma/migrations/20260506072302_v26_05_08_pack_topics_and_post_views/migration.sql
  • packages/db/prisma/schema/pack.prisma
  • packages/db/prisma/schema/post.prisma
  • packages/schemas/src/db/schemas/enums/PackScalarFieldEnum.schema.ts
  • packages/schemas/src/db/schemas/enums/PostScalarFieldEnum.schema.ts
  • packages/schemas/src/db/schemas/models/Pack.schema.ts
  • packages/schemas/src/db/schemas/models/Post.schema.ts
  • packages/schemas/src/modules/pack.ts
  • packages/schemas/src/modules/post.ts
  • packages/schemas/src/modules/topic.ts
  • packages/schemas/src/modules/user.ts
  • packages/utils/src/app-releases.ts

📝 Walkthrough

Walkthrough

This PR introduces multiple distinct features: post view tracking with author insights analytics; host-side keyboard shortcuts for live game control; play streak display for user profiles; enhanced pack discovery through language, difficulty, and topic-count filtering; and bulk topic deletion with UI selection controls. Includes supporting database schema changes, API endpoints, and React components.

Changes

Post Views and Insights Analytics

Layer / File(s) Summary
Data Shape
packages/db/prisma/schema/post.prisma, packages/db/prisma/migrations/20260506072302_*, packages/schemas/src/db/schemas/models/Post.schema.ts, packages/schemas/src/db/schemas/enums/PostScalarFieldEnum.schema.ts
Post model adds totalViews field; migration backfills with default 0.
Post Service API
packages/api/src/modules/post/service.ts, packages/schemas/src/modules/post.ts
New service functions recordPostView (bumps view count) and getPostInsights (aggregates reaction, comment, bookmark rankings); PostRowType includes totalViews; new input/output schemas for both operations.
Post Router
packages/api/src/modules/post/router.ts
Adds recordView (public) and getInsights (protected) endpoints wired to service layer.
Client View Tracking
apps/web/src/hooks/use-post-view-tracker.ts
New hook using IntersectionObserver with 50% threshold and 1-second dwell to track post visibility; deduplicates via sessionStorage and calls orpc.post.recordView on qualifying views.
Home Feed Integration
apps/web/src/components/home/home-feed.tsx
Added EyeIcon import, usePostViewTracker hook call with cardRef, views display in engagement row with icon/count/tooltip, and author-only Insights action in post menu.
Insights Page
apps/web/src/routes/p/$postSlug/insights.tsx, apps/web/src/components/post-insights/post-insights-view.tsx, apps/web/src/routes/p/$postSlug.tsx, apps/web/src/routeTree.gen.ts
New protected insights route with SEO, data loading guard, and PostInsightsView component; parent route wired for nested rendering via Outlet; PostInsightsView renders headline stats (views/reactions/comments/bookmarks), reactions by emoji with bars, comments breakdown, and top user rosters.
Documentation & Roadmap
apps/web/src/lib/roadmap-content.ts
Added totalViews and post insights page tracking to v26.05.08 roadmap.

Host Keyboard Shortcuts for Live Games

Layer / File(s) Summary
Core Hook
apps/web/src/hooks/use-host-shortcuts.ts
New hook wiring keyboard shortcuts (pause/resume, advance, skip, reveal, finish, resolve buzz) to optimistic local mutations and ABly broadcasts; computes host action eligibility (canAct, canSkipQuestion, etc.) and manages help dialog visibility; returns { helpOpen, openHelp, closeHelp, toggleHelp }.
UI Component
apps/web/src/components/host-shortcuts-help.tsx
New HostShortcutsHelp component rendering BetterDialog with KeyboardIcon trigger and ROWS constant mapping shortcut keys to labels.
Host View Integration
apps/web/src/components/host-view.tsx
Wires useHostShortcuts hook, renders HostShortcutsHelp in header, and displays keyboard hint in footer when game is active/paused.

Profile Play Streak Feature

Layer / File(s) Summary
User Service & API
packages/api/src/modules/user/service.ts, packages/api/src/modules/user/router.ts, packages/schemas/src/modules/user.ts
New service function getPublicPlayStreak computes 60-day UTC daily play counts, current/longest streaks, and last60 array; router endpoint wired with input/output schemas.
Profile UI Component
apps/web/src/components/profile/play-streak-strip.tsx
New PlayStreakStrip component renders header with current/best streaks and total games; horizontal bar chart for up to 30 days with color intensity based on daily counts and per-day tooltips.
Profile Route Integration
apps/web/src/routes/u/$username.tsx
Fetches public play streak via getPublicPlayStreak(username) and renders PlayStreakStrip when data available.

Enhanced Pack Discovery Filters

Layer / File(s) Summary
Data Shape
packages/db/prisma/schema/pack.prisma, packages/db/prisma/migrations/20260506072302_*, packages/schemas/src/db/schemas/models/Pack.schema.ts, packages/schemas/src/db/schemas/enums/PackScalarFieldEnum.schema.ts, packages/schemas/src/modules/pack.ts
Pack model adds totalTopics field; migration backfills count from related topics; PackDifficultyBandSchema enum and type introduced; ListPacksFiltersSchema and output schemas include totalTopics.
Pack Service
packages/api/src/modules/pack/service.ts
Adds PDR_BANDS constant for difficulty ranges; listPacks extended with difficultyBands, minTopicCount, and additional filters (minAverageRating, minPlays, hasRatings, onlyMyPacks, canHost, hideFinishedByMe); new difficultyWhere and hideFinishedWhere clauses; select projection includes totalTopics.
Pack Filter UI
apps/web/src/components/pack-filters.tsx
Adds language and difficulty filter state via useQueryState; LANGUAGE_LABELS and DIFFICULTY_LABELS constants map schema options to labels; new UI sections for Languages and Difficulty with checkbox grids; Minimum topics input; Hide finished toggle for authenticated users; hasFilters and reset handlers expanded.
Packs Route
apps/web/src/routes/packs/index.tsx
Wires min_topics, hide_finished, languages, and difficulty query states into infinite query payload with conditional inclusion.

Topic Bulk Delete with Selection UI

Layer / File(s) Summary
Data Maintenance
packages/api/src/modules/topic/service.ts
Topic creation increments Pack.totalTopics by 1; deletion decrements by 1; new bulkDeleteTopics function validates pack ownership, deletes multiple topics in transaction, resequences remaining, decrements totalTopics by count, and returns deleted count.
Topic Router & Schemas
packages/api/src/modules/topic/router.ts, packages/schemas/src/modules/topic.ts
Router adds bulkDelete endpoint; schemas introduce BulkDeleteTopicsInputSchema (pack slug + array of topic slugs) and BulkDeleteTopicsOutputSchema (deleted count).
Topic List UI
apps/web/src/components/pack-topics-list.tsx
Major refactor adds selection mode with per-topic checkboxes; computed state: visibleTopics, selectedSlugs, allVisibleSelected, someVisibleSelected; selection bar shows count and bulk delete button; bulkDelete mutation with success/error/invalidation handling; TopicCard props expanded with selectMode, selected, onToggleSelected; conditional rendering switches between select and normal mode; empty state updated to use visibleTopics.

Sequence Diagram(s)

sequenceDiagram
    participant User as User<br/>(Browser)
    participant PostCard as Post Feed<br/>Card
    participant Observer as Intersection<br/>Observer
    participant SessionStore as Session<br/>Storage
    participant API as Post API<br/>recordView
    participant DB as Database

    User->>PostCard: Scroll into view
    PostCard->>Observer: Card enters viewport
    Observer->>Observer: Wait 1 second (dwell)
    Observer->>SessionStore: Check if postId seen?
    alt Already recorded in session
        SessionStore-->>Observer: Already seen
    else First time this session
        SessionStore-->>Observer: Not seen yet
        Observer->>API: recordView(postId)
        API->>DB: UPDATE post SET total_views = total_views + 1
        DB-->>API: Updated totalViews
        API-->>Observer: Success
        Observer->>SessionStore: Persist postId
    end
Loading
sequenceDiagram
    participant Host as Host<br/>(Browser)
    participant Hook as useHostShortcuts<br/>Hook
    participant Optimistic as Local Query<br/>State
    participant Ably as ABly<br/>Channel
    participant API as Game API<br/>(Mutation)
    participant Server as Server<br/>State

    Host->>Hook: Press '?' key
    Hook->>Hook: toggleHelp()
    Hook-->>Host: Show shortcuts dialog

    Host->>Hook: Press 'Space' (pause/resume)
    Hook->>Optimistic: Update game.status locally
    Hook-->>Host: UI updates immediately
    Hook->>Ably: Broadcast game event
    Hook->>API: Call advance/pause mutation
    API->>Server: Update server state
    Server-->>API: Confirm
    alt Mutation succeeds
        API->>Optimistic: Invalidate query cache
    else Mutation fails
        Optimistic->>Optimistic: Revert optimistic update
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes


Possibly related PRs

  • asmelabs/xamsa#36: Directly related — both modify post components, API/router/service, schemas, and home feed behavior for post analytics.
  • asmelabs/xamsa#12: Related — both modify pack-topics-list and TopicCard deletion/bulk delete behavior.
  • asmelabs/xamsa#14: Related — both modify profile route (apps/web/src/routes/u/$username.tsx) to expand profile stats/UI.

Suggested labels

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


Poem

🐰 Hop, hop, hooray! The views now gleam,
Insights dash like a creator's dream—
Host shortcuts zip through keys so swift,
Play streaks glow (a temporal gift),
And topics bulk-delete with flair,
This PR's magic fills the air! ✨

✨ 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-08

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 d93ec63 into main May 6, 2026
4 of 5 checks passed
@mehdiasadli mehdiasadli deleted the v26-05-08 branch May 6, 2026 10:19
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