Skip to content

Add per-section clap button#13

Open
GrzywN wants to merge 7 commits intomainfrom
@grzywn/clapping
Open

Add per-section clap button#13
GrzywN wants to merge 7 commits intomainfrom
@grzywn/clapping

Conversation

@GrzywN
Copy link
Copy Markdown
Collaborator

@GrzywN GrzywN commented Apr 2, 2026

Adds a clapping feature to the guide — readers can express appreciation for individual sections, not just whole articles.

What's included

ClapButton Astro component (src/components/ClapButton.astro)

  • Fetches current clap count on page load via GET /claps?slug=
  • Accumulates clicks locally, sends them in a single sendBeacon on page leave (pagehide)
  • Shows a conic-gradient progress ring reflecting how many claps the user has given (across all sessions, via user_claps from the API)
  • Graceful degradation: if PUBLIC_API_URL is not set, renders silently without errors
  • Runtime validation of the API response via Zod (astro/zod)

Technical decisions worth noting:

  • State split into local (session claps, sent flag) and remote (server response) for clarity
  • remote.count++ on click is an intentional optimistic update — keeps displayed count in sync without a round-trip

Placed after every ## section across all 17 articles (60 sections total), each with a unique slug matching the article path + section heading.

.env.example updated with PUBLIC_API_URL.

API

The component talks to a separate self-hosted API (agentic-engineering-applause-feature repo). Set PUBLIC_API_URL in .env to point at it.

GET /claps?slug={slug} → { count, max_claps, user_claps }
POST /claps?slug={slug} body: { claps: number }

@GrzywN GrzywN requested a review from mkaput April 2, 2026 09:59
@GrzywN GrzywN force-pushed the @grzywn/clapping branch from 718e0cb to b5acfc0 Compare April 8, 2026 07:46
@GrzywN GrzywN force-pushed the @grzywn/clapping branch from 5e0b871 to 18aa9e1 Compare April 8, 2026 08:52
@GrzywN GrzywN force-pushed the @grzywn/clapping branch from 583394c to 3d6535c Compare April 8, 2026 09:52
@GrzywN
Copy link
Copy Markdown
Collaborator Author

GrzywN commented Apr 8, 2026

@mkaput Ready for re-review. Implemented network logging using console and added clap buttons based on Markdown AST.

@GrzywN GrzywN requested a review from mkaput April 8, 2026 10:01
@mkaput
Copy link
Copy Markdown
Member

mkaput commented Apr 8, 2026

@codex please review? (testing if this works)

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 32fe872805

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

navigator.sendBeacon(clapsUrl, body);
}

window.addEventListener("pagehide", sendClaps);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Flush pending claps on visibility change

The component only hooks sendClaps to pagehide, which is not reliably fired in common mobile/background termination flows, so local.claps can be lost without ever being sent and your clap totals/analytics drift downward. Add a visibilitychange handler that sends when document.visibilityState === "hidden" (keeping pagehide as fallback) so pending claps are flushed in lifecycle paths where pagehide never runs.

Useful? React with 👍 / 👎.

Comment on lines +69 to +71
remote = parsing.data;

render();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve optimistic count when fetch completes

If a user clicks before the initial GET /claps finishes, the click handler increments remote.count optimistically, but then remote = parsing.data replaces it with the stale server value and render() rolls the visible count backward until unload. This creates inconsistent feedback exactly on slow networks; merge the fetched payload with unsent local.claps (or reapply the local delta after assignment) before rendering.

Useful? React with 👍 / 👎.

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.

2 participants