|
|
import { Controller } from "@hotwired/stimulus"
|
|
|
|
|
|
// Thumbs up / down on the results screen. Fire-and-forget: the button state
|
|
|
// flips immediately and the POST is not awaited, so a slow network never makes
|
|
|
// the tap feel dead. One rating per player -- tapping the other thumb just
|
|
|
// overwrites the previous one server-side.
|
|
|
export default class extends Controller {
|
|
|
static targets = ["button"]
|
|
|
static values = { url: String }
|
|
|
|
|
|
rate(event) {
|
|
|
const button = event.currentTarget
|
|
|
const direction = button.dataset.direction
|
|
|
|
|
|
this.buttonTargets.forEach((b) => b.classList.toggle("is-selected", b === button))
|
|
|
|
|
|
const body = new FormData()
|
|
|
body.append("direction", direction)
|
|
|
|
|
|
fetch(this.urlValue, {
|
|
|
method: "POST",
|
|
|
body,
|
|
|
headers: { "X-CSRF-Token": this.csrfToken },
|
|
|
credentials: "same-origin"
|
|
|
}).catch(() => {})
|
|
|
}
|
|
|
|
|
|
get csrfToken() {
|
|
|
return document.querySelector("meta[name='csrf-token']")?.content || ""
|
|
|
}
|
|
|
}
|