Skip to content

feat: call to action to subscribe on the comments of the week#4353

Open
cemreinanc wants to merge 2 commits intomainfrom
feat/3504-comment-of-the-week-subs
Open

feat: call to action to subscribe on the comments of the week#4353
cemreinanc wants to merge 2 commits intomainfrom
feat/3504-comment-of-the-week-subs

Conversation

@cemreinanc
Copy link
Contributor

@cemreinanc cemreinanc commented Feb 13, 2026

Fixes #3504

Summary by CodeRabbit

  • New Features
    • Added a CTA to subscribe to a weekly "Top Comments" email digest.
    • Subscription flow works for both signed-in and guest users (prompts sign-in and resumes action after login).
    • Multi-language UI strings added (en, es, pt, cs, zh, zh‑TW).
    • Prompt can be dismissed and the dismissal is remembered across sessions.
    • Sign-in/signup now support an optional post-login callback to trigger follow-up actions.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

📝 Walkthrough

Walkthrough

Adds a weekly top-comments subscription CTA and dismissal hook, integrates it into the weekly comments feed, adds localized messages in six languages, and wires an optional onSuccess callback through signin/signup modals to enable subscribing post-authentication.

Changes

Cohort / File(s) Summary
Translation Messages
front_end/messages/cs.json, front_end/messages/en.json, front_end/messages/es.json, front_end/messages/pt.json, front_end/messages/zh-TW.json, front_end/messages/zh.json
Added four localization keys per language: weeklyTopCommentsSubscribeCta, weeklyTopCommentsSubscribeSuccess, weeklyTopCommentsSubscribeSuccessInline, weeklyTopCommentsSubscribeError.
Authentication Flow
front_end/src/components/auth/signin.tsx, front_end/src/components/auth/signup.tsx, front_end/src/contexts/modal_context.tsx, front_end/src/components/global_modals.tsx
Introduced optional `onSuccess?: (authenticatedUser: CurrentUser) => void
Weekly Top Comments UI & Logic
front_end/src/components/weekly_top_comments_feed/components/subscribe_top_comments_cta.tsx, front_end/src/components/weekly_top_comments_feed/hooks/use_top_comments_cta_dismissed.ts
Added SubscribeTopCommentsCta component with subscribe/unsubscribe flows, optimistic updates, localStorage subscribe-intent handling, signin integration, toasts, and useTopCommentsCtaDismissed hook for per-user dismissal state.
Feed Integration
front_end/src/components/weekly_top_comments_feed/components/comments_of_week_content.tsx
Rendered the new SubscribeTopCommentsCta in the weekly comments header.

Sequence Diagram

sequenceDiagram
    participant User
    participant Feed as WeeklyCommentsFeed
    participant CTA as SubscribeTopCommentsCta
    participant Auth as SignIn/SignUp Modal
    participant API as Backend (updateProfileAction)
    participant Storage as localStorage

    User->>Feed: Open comments-of-week page
    Feed->>CTA: Render CTA component
    CTA->>Storage: Read dismissal & SUBSCRIBE_INTENT_KEY
    CTA->>Auth: Check auth state (currentUser)

    alt Not authenticated
        User->>CTA: Click Subscribe
        CTA->>Storage: Set SUBSCRIBE_INTENT_KEY
        CTA->>Auth: Open SignIn modal (with onSuccess)
        User->>Auth: Complete sign-in
        Auth->>CTA: Invoke onSuccess(authenticatedUser)
        CTA->>Storage: Read SUBSCRIBE_INTENT_KEY
        CTA->>API: Call updateProfileAction to subscribe
        API-->>CTA: Success / Error
        CTA->>User: Show success or error message
    else Authenticated
        User->>CTA: Click Subscribe
        CTA->>API: Call updateProfileAction (optimistic UI)
        API-->>CTA: Success / Error
        CTA->>User: Show success or error message
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Login modal refactor #4268: Modifies SignInModal implementation in the same signin file—overlaps with this PR's signin/signup onSuccess wiring.

Suggested reviewers

  • elisescu
  • ncarazon
  • hlbmtc

Poem

🐰 Beneath the weekly-comment light I hop,
A CTA, a click, a subscribe on the hop,
Sign in, persist intent, then cheer—hooray!
Dismiss or join, the inbox blooms each week—hooray! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (12 files):

⚔️ front_end/messages/cs.json (content)
⚔️ front_end/messages/en.json (content)
⚔️ front_end/messages/es.json (content)
⚔️ front_end/messages/pt.json (content)
⚔️ front_end/messages/zh-TW.json (content)
⚔️ front_end/messages/zh.json (content)
⚔️ front_end/src/components/auth/signin.tsx (content)
⚔️ front_end/src/components/auth/signup.tsx (content)
⚔️ front_end/src/components/global_modals.tsx (content)
⚔️ front_end/src/components/weekly_top_comments_feed/components/comments_of_week_content.tsx (content)
⚔️ front_end/src/contexts/modal_context.tsx (content)
⚔️ poetry.lock (content)

These conflicts must be resolved before merging into main.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: adding a call-to-action component for subscribing to weekly top comments, which is the primary feature implemented across the changeset.
Linked Issues check ✅ Passed The PR implementation meets all coding requirements from issue #3504: displays CTA when unsubscribed, handles subscription with optimistic updates, shows success messages, and implements signin flow for logged-out users.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the weekly top comments subscription CTA feature. No unrelated refactoring, dependency updates, or unrelated fixes are present.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/3504-comment-of-the-week-subs
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch feat/3504-comment-of-the-week-subs
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
front_end/src/components/auth/signin.tsx (1)

75-83: ⚠️ Potential issue | 🟠 Major

Guard onSuccess failures so post-login actions always run.

If onSuccess throws, handlePostLoginAction is skipped and the login flow can become inconsistent. Wrap the callback to preserve post-login handling.

Proposed fix
-        await onSuccess?.(state.user);
-        handlePostLoginAction(state.postLoginAction);
+        try {
+          await onSuccess?.(state.user);
+        } catch (err) {
+          console.error("Post-login onSuccess failed", err);
+        } finally {
+          handlePostLoginAction(state.postLoginAction);
+        }
🤖 Fix all issues with AI agents
In `@front_end/src/components/auth/signup.tsx`:
- Around line 123-126: The current sequence awaits onSuccess and then calls
handlePostLoginAction, but if onSuccess throws the post-login action is skipped;
change this by wrapping the onSuccess call in a try/catch (or try/catch/finally)
so that handlePostLoginAction(response?.postLoginAction) always runs—e.g., call
await onSuccess?.(response.user) inside try, handle or log any error in catch,
and invoke handlePostLoginAction in finally (or after the catch) to guarantee
post-login handling regardless of onSuccess failures; update the code around the
onSuccess and handlePostLoginAction calls in the signup component accordingly.

In
`@front_end/src/components/weekly_top_comments_feed/components/subscribe_top_comments_cta.tsx`:
- Around line 57-66: On success in the try block after calling
updateProfileAction (where setIsSuccess(true) and
safeLocalStorage.removeItem(SUBSCRIBE_INTENT_KEY) are executed), fire a success
toast or open a modal containing the full success copy (use the i18n key used
elsewhere, e.g. t("weeklyTopCommentsSubscribeSuccessFull")) and include an
actionable account settings link that navigates to the user's settings page;
ensure this new toast/modal complements the existing short inline state rather
than replacing error handling (leave the catch with
toast.error(t("weeklyTopCommentsSubscribeError")) intact) and reference
updateProfileAction, setIsSuccess, safeLocalStorage, SUBSCRIBE_INTENT_KEY, and
toast in your change so reviewers can locate the insertion point.

In
`@front_end/src/components/weekly_top_comments_feed/hooks/use_top_comments_cta_dismissed.ts`:
- Around line 10-30: When the storage key changes in useTopCommentsCtaDismissed,
reset loading state so the hook doesn't briefly expose the previous key's
dismissal value; update the hook to setReady(false) and setDismissed(true) when
the computed key changes (before the useEffect read), then let the existing
useEffect read safeLocalStorage for that key and setDismissed(...) and
setReady(true); reference the useTopCommentsCtaDismissed hook, the key variable,
the dismissed/ready state variables, and the existing useEffect/useCallback to
locate where to reset state on key change.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 13, 2026

🚀 Preview Environment

Your preview environment is ready!

Resource Details
🌐 Preview URL https://metaculus-pr-4353-feat-3504-comment-of-the-week-preview.mtcl.cc
📦 Docker Image ghcr.io/metaculus/metaculus:feat-3504-comment-of-the-week-subs-f1fef31
🗄️ PostgreSQL NeonDB branch preview/pr-4353-feat-3504-comment-of-the-week
Redis Fly Redis mtc-redis-pr-4353-feat-3504-comment-of-the-week

Details

  • Commit: 717e6eb3ee849f3fbf98dd0be04ce137a6b99edf
  • Branch: feat/3504-comment-of-the-week-subs
  • Fly App: metaculus-pr-4353-feat-3504-comment-of-the-week

ℹ️ Preview Environment Info

Isolation:

  • PostgreSQL and Redis are fully isolated from production
  • Each PR gets its own database branch and Redis instance
  • Changes pushed to this PR will trigger a new deployment

Limitations:

  • Background workers and cron jobs are not deployed in preview environments
  • If you need to test background jobs, use Heroku staging environments

Cleanup:

  • This preview will be automatically destroyed when the PR is closed

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
front_end/src/components/auth/signup.tsx (1)

322-322: ⚠️ Potential issue | 🟡 Minor

onSuccess is not propagated through SocialButtons — social-login users won't auto-subscribe.

If a logged-out user triggers the subscribe CTA, gets this signup modal, and completes registration via a social provider (OAuth redirect), the onSuccess callback is lost. The user would land back on the page without the subscription action firing, requiring them to click "Subscribe" again.

This is likely acceptable given OAuth's redirect-based flow, but worth confirming whether you want to handle this (e.g., by persisting intent in sessionStorage or via a query parameter on the redirect URL).

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.

Call to action when unsubscribed from comment of the week

1 participant