From 3b7353b1f0803ba70dae7b67c60a93e01f67f97d Mon Sep 17 00:00:00 2001 From: JP Hastings-Spital Date: Tue, 28 Jan 2025 16:00:53 +0000 Subject: [PATCH] Fix clap counter Because of a missing variable, and combining numbers as strings instead of integers, the number of claps was displaying extremely incorrectly! This is now fixed. --- assets/js/main.js | 6 +++--- layouts/partials/claps.html | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/assets/js/main.js b/assets/js/main.js index 8d69fab6..e9f1d0e7 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -55,7 +55,7 @@ const performClap = (e) => { const clapKey = (action) => `clap:${(new URL(action)).pathname}`; -const addInteractions = (btn, claps) => (claps + (btn.dataset.interactions || 0)); +const addInteractions = (btn, claps) => (claps + (Number(btn.dataset.interactions) || 0)) const setClapCount = (btn, clapCount) => { if (clapCount === 0) { @@ -91,10 +91,10 @@ document.addEventListener("DOMContentLoaded", () => { btn.parentElement.classList.add('clapped') setClapCount(btn, lastClappedTo) } - toCheck.push(action) + toCheck.push([action, btn]) }) - toCheck.forEach((action) => { + toCheck.forEach(([action, btn]) => { fetch(action, { method: 'GET', headers: new Headers({ 'Accept': 'application/json' }) }) .then(res => { if (res.status !== 200) { diff --git a/layouts/partials/claps.html b/layouts/partials/claps.html index fd399b00..8b08c022 100644 --- a/layouts/partials/claps.html +++ b/layouts/partials/claps.html @@ -11,8 +11,9 @@ {{- errorf "%s" . -}} {{- else -}} {{- $data := .Content | transform.Unmarshal -}} - {{- $clapCount := add $interactionCount ((index $data $relperma) | default 0) -}} - {{- with $clapCount }}{{ . }}{{ end -}} + {{- $clapCount := (index $data $relperma) | default 0 -}} + {{- $totalCount := add (int $interactionCount) (int $clapCount) -}} + {{- with $totalCount }}{{ . }}{{ end -}} {{- end -}} {{- else -}} {{- errorf "Unable to get all clap counts" -}}