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.
This commit is contained in:
JP Hastings-Spital 2025-01-28 16:00:53 +00:00
parent 5172730f34
commit 3b7353b1f0
2 changed files with 6 additions and 5 deletions

View file

@ -55,7 +55,7 @@ const performClap = (e) => {
const clapKey = (action) => `clap:${(new URL(action)).pathname}`; 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) => { const setClapCount = (btn, clapCount) => {
if (clapCount === 0) { if (clapCount === 0) {
@ -91,10 +91,10 @@ document.addEventListener("DOMContentLoaded", () => {
btn.parentElement.classList.add('clapped') btn.parentElement.classList.add('clapped')
setClapCount(btn, lastClappedTo) 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' }) }) fetch(action, { method: 'GET', headers: new Headers({ 'Accept': 'application/json' }) })
.then(res => { .then(res => {
if (res.status !== 200) { if (res.status !== 200) {

View file

@ -11,8 +11,9 @@
{{- errorf "%s" . -}} {{- errorf "%s" . -}}
{{- else -}} {{- else -}}
{{- $data := .Content | transform.Unmarshal -}} {{- $data := .Content | transform.Unmarshal -}}
{{- $clapCount := add $interactionCount ((index $data $relperma) | default 0) -}} {{- $clapCount := (index $data $relperma) | default 0 -}}
{{- with $clapCount }}<span>{{ . }}</span>{{ end -}} {{- $totalCount := add (int $interactionCount) (int $clapCount) -}}
{{- with $totalCount }}<span>{{ . }}</span>{{ end -}}
{{- end -}} {{- end -}}
{{- else -}} {{- else -}}
{{- errorf "Unable to get all clap counts" -}} {{- errorf "Unable to get all clap counts" -}}