Skip to content

Conversation

@pranjal29092005
Copy link

@pranjal29092005 pranjal29092005 commented Dec 13, 2025

02161ad3-b35c-4282-8454-d6efb814aac6.mp4

Problem

Fixes #53
The article pages lacked social sharing functionality, making it difficult for readers to share content on social media platforms. This reduced content discoverability and user engagement.

Solution

Added social share buttons to individual article pages with the following features:

Share Platforms

  • Twitter/X: Shares article title and URL
  • LinkedIn: Shares article URL, title, and summary
  • Facebook: Shares article URL with title as quote
  • Copy Link: Copies article URL to clipboard with visual feedback

Implementation Details

  • Positioned below author/date metadata, above article content
  • Uses existing gradient color scheme matching the site's design system
  • Responsive layout with flex-wrap for mobile devices
  • Proper aria-label attributes for accessibility
  • No new dependencies added
  • Minimal diff approach (only modified BlogPostClient.tsx)

Technical Approach

  • Uses window.open() for social media share dialogs
  • Uses navigator.clipboard.writeText() for copy functionality
  • Provides temporary "Copied!" feedback for copy action
  • All share URLs include article metadata for better sharing experience

Changes Made

  • Modified: app/a/[slug]/BlogPostClient.tsx (+95 lines, -6 lines)

Testing

✅ Dev server runs without errors
✅ All four share buttons display correctly
✅ Buttons maintain consistent styling across devices
✅ Responsive layout works on mobile and desktop
✅ No regressions in existing functionality

Screenshots

See attached screenshots in the PR showing:

  • Desktop view of share buttons
  • All platforms pre-filling share content with article information
Screenshot 2025-12-14 012506 Screenshot 2025-12-14 012530

Summary by CodeRabbit

  • New Features

    • Added social share buttons (Twitter/X, LinkedIn, Facebook) and a Copy Link button with temporary “Copied!” feedback.
  • Accessibility

    • Added screen-reader-only utility and an ARIA announcement for copy feedback.
  • Improvements

    • Simplified hero image handling for more consistent display.
  • Bug Fixes

    • Notifies users when pop-up sharing is blocked.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 13, 2025

Walkthrough

Added client-side social sharing UI to the blog post client: new copied state plus timeout ref and cleanup, simplified hero image src to post.image, share buttons for Twitter/X, LinkedIn, Facebook that open platform share URLs in new windows (with popup-block handling), and a Copy Link button using the Clipboard API with temporary "Copied!" feedback and a screen-reader announcement.

Changes

Cohort / File(s) Summary
Social share & client logic
app/a/[slug]/BlogPostClient.tsx
Added useState, useRef, and useEffect to manage copied state and a timeout ref with cleanup. Simplified image src to post.image. Injected social share UI (Twitter/X, LinkedIn, Facebook) that opens platform-specific share URLs in new windows with popup-block alerts. Added Copy Link button using the Clipboard API with error fallback and a 2s "Copied!" label toggle; added an off-screen screen-reader announcement element.
Accessibility utilities
app/globals.css
Added .sr-only utility class to hide visual content while keeping it available to assistive technologies (standard off-screen/clip technique).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify correct URL encoding for share links and consistent behavior of window.open across browsers.
  • Confirm clipboard API error handling and that the timeout is cleared on unmount (useEffect cleanup and copiedTimeoutRef usage).
  • Check accessibility: aria-labels, the .sr-only element, and that the "Copied!" announcement is reachable by screen readers.
  • Ensure post.image is always a valid src in all post shapes or add fallback if needed.

Suggested reviewers

  • ceilican

Poem

🐰 I nudged the page and made it sing,
Buttons ready—let the sharing spring.
Twitter, LinkedIn, Facebook cheer,
Copy the link — the sky is clear.
A bunny hops and sends your post with a spring 🥕

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR partially addresses the linked issue #53. While it adds social sharing buttons for articles, the issue primarily focuses on /projects page social links and responsive UI issues on that page. The implementation targets article pages rather than the /projects page mentioned in issue #53. Clarify whether this PR is meant to address #53 or if it should be linked to a different issue.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding social share buttons with clickable links and pre-filled content to article pages, matching the changeset.
Out of Scope Changes check ✅ Passed The changes are focused on BlogPostClient.tsx and globals.css for adding social share buttons to article pages, with no unrelated modifications detected.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests 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: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 113d28d and 9664524.

📒 Files selected for processing (1)
  • app/a/[slug]/BlogPostClient.tsx (2 hunks)

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: 2

♻️ Duplicate comments (1)
app/a/[slug]/BlogPostClient.tsx (1)

78-149: (Duplicate) Share endpoints/params may be ignored/brittle—consider validating against current platform docs.
This is the same concern as earlier review notes (LinkedIn share-offsite extra params; Facebook quote; X intent params).

Verify current (Dec 2025) query parameters supported for:
- https://twitter.com/intent/tweet
- https://www.linkedin.com/sharing/share-offsite/
- https://www.facebook.com/sharer/sharer.php
Specifically whether LinkedIn accepts title/summary and whether Facebook accepts quote.
🧹 Nitpick comments (2)
app/a/[slug]/BlogPostClient.tsx (2)

3-13: copied state is fine, but you’ll want a timeout cleanup hook for the later setTimeout.
Right now the timeout is created in the click handler (Line 157); add a ref + cleanup so you don’t fire state updates after unmount / stack multiple timers.


150-182: Harden “Copy Link”: secure-context/feature detect + dedupe/cleanup the timer.
This avoids failures on non-HTTPS contexts, avoids stacking multiple timeouts on repeated clicks, and avoids a timer firing after unmount.

 import { useState } from "react"
+import { useEffect, useRef } from "react"

 export default function BlogPostPage({ post }: { post: BlogPost }) {
   const [copied, setCopied] = useState(false)
+  const copiedTimeoutRef = useRef<number | null>(null)
+
+  useEffect(() => {
+    return () => {
+      if (copiedTimeoutRef.current != null) window.clearTimeout(copiedTimeoutRef.current)
+    }
+  }, [])

   return (
@@
                 <button
                   type="button"
                   onClick={() => {
-                    navigator.clipboard.writeText(window.location.href)
+                    if (!window.isSecureContext || !navigator.clipboard?.writeText) {
+                      alert('Copy is only available on HTTPS. Please copy the URL from the address bar.')
+                      return
+                    }
+                    navigator.clipboard.writeText(window.location.href)
                       .then(() => {
+                        if (copiedTimeoutRef.current != null) window.clearTimeout(copiedTimeoutRef.current)
                         setCopied(true)
-                        setTimeout(() => setCopied(false), 2000)
+                        copiedTimeoutRef.current = window.setTimeout(() => setCopied(false), 2000)
                       })
                       .catch((err) => {
                         console.error('Failed to copy:', err)
                         alert('Failed to copy link. Please copy manually.')
                       })
                   }}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9664524 and 3b5eeaa.

📒 Files selected for processing (1)
  • app/a/[slug]/BlogPostClient.tsx (4 hunks)

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: 0

♻️ Duplicate comments (1)
app/a/[slug]/BlogPostClient.tsx (1)

104-151: LinkedIn/Facebook share params may not do what you expect.
share-offsite often ignores title/summary, and Facebook sharing generally relies on OG tags (the quote param may be ignored). (This was raised in earlier reviews.)

🧹 Nitpick comments (2)
app/a/[slug]/BlogPostClient.tsx (2)

76-151: Share popup implementation is OK; consider a Web Share API fast-path.
On mobile, navigator.share() (when available) is typically a better UX than popups; you can keep window.open as fallback.


153-190: Copy Link flow is robust; tweak secure-context messaging + a11y announcement.

  • Message: “secure context (HTTPS or localhost)” is more accurate than “HTTPS only”.
  • A11y: consider adding a small role="status"/aria-live="polite" region so screen readers get “Copied!” feedback without relying on visual change.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b5eeaa and 0098224.

📒 Files selected for processing (1)
  • app/a/[slug]/BlogPostClient.tsx (4 hunks)
🔇 Additional comments (2)
app/a/[slug]/BlogPostClient.tsx (2)

3-19: Timeout cleanup + state approach looks solid (no obvious leaks / stale timers).
Only nit: consider tightening the cleanup block style (braces/newlines) for readability, but functionally LGTM.


40-48: <Image src={post.image}> simplification is good — less branching, same behavior.
Just double-check post.image is always a value next/image can render in your deployment (relative path vs remote URL expectations).

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: 0

🧹 Nitpick comments (1)
app/globals.css (1)

13-25: Solid .sr-only utility for accessibility feedback.

The screen-reader-only utility follows standard accessibility patterns and is correctly placed in the @layer utilities section. This supports the copy-to-clipboard announcement feature referenced in the PR.

Optional modernization note: The clip: rect(0, 0, 0, 0) property works reliably across browsers, but consider the more explicit modern approach clip-path: inset(50%) if you update accessibility utilities in the future.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0098224 and 20d2465.

📒 Files selected for processing (2)
  • app/a/[slug]/BlogPostClient.tsx (4 hunks)
  • app/globals.css (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/a/[slug]/BlogPostClient.tsx
🔇 Additional comments (1)
app/globals.css (1)

1-107: Note: Missing primary implementation file.

The PR description indicates changes to app/a/[slug]/BlogPostClient.tsx (+95, -6 lines) that implements the social share buttons, but this file is not provided for review. The changes to app/globals.css appear sound, but a comprehensive review of the social share feature (button logic, accessibility, responsive layout, clipboard handling) requires reviewing the main component file.

If you'd like a complete review of the social share feature, please provide the app/a/[slug]/BlogPostClient.tsx file.

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.

Social links on /projects page are not clickable, UI is not responsive. Sharable links not available.

1 participant