Render threadables

This commit is contained in:
Jose Farias
2024-10-23 14:12:28 -06:00
parent 35a31e3203
commit 5221807847
18 changed files with 84 additions and 15 deletions
@@ -0,0 +1,33 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = [ "boostEvent" ]
connect() {
this.#summarizeBoosts()
}
#summarizeBoosts() {
const el = document.createElement("span")
el.textContent = this.#boostSumaries.toSentence()
this.element.appendChild(el)
}
get #boostSumaries() {
return Object.entries(this.#boostsByCreator).map(([_creatorId, boostEvents]) => {
return `${boostEvents[0].dataset.creatorName} +${boostEvents.length}`
})
}
get #boostsByCreator() {
return this.boostEventTargets.reduce((acc, target) => {
const creatorId = target.dataset.creatorId
if (!acc[creatorId]) acc[creatorId] = []
acc[creatorId].push(target)
return acc
}, {})
}
}