record-share-intent.ts

src/utils/record-share-intent.ts
import { state } from '@/state'
// Optimistically bumps shareCounts[slug] by 1, fires the POST, then reconciles
// with the server-returned count. Rolls back on failure.
export function recordShareIntent(slug: string, target: string): void {
const prevCount = state.shareCounts[slug]
state.shareCounts[slug] = (prevCount ?? 0) + 1
fetch('/api/share-count', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ slug, target }),
keepalive: true,
})
.then((res) => res.json())
.then((data) => {
if (typeof data.count === 'number') {
state.shareCounts[slug] = data.count
}
})
.catch(() => {

Showing the first 20 lines.

Get full code

Support

Talk to the developers of this project to learn more

We have been building professional websites for big clients for over 15 years. Gallop templates and blocks is our best foundation for SEO websites and web apps.

© 2026 Web Plant Media, LLC