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 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) {

View file

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