Use a view helper to remove branching from the bubbles controller

This commit is contained in:
Mike Dalessio
2025-05-16 10:32:28 -04:00
parent 388fe2de73
commit dddb33b483
3 changed files with 14 additions and 10 deletions
@@ -4,8 +4,8 @@ import { signedDifferenceInDays } from "helpers/date_helpers"
const REFRESH_INTERVAL = 3_600_000 // 1 hour (in milliseconds)
export default class extends Controller {
static targets = [ "closingTop", "consideringTop", "days", "bottom" ]
static values = { "closesAt": String, "reminderBefore": Number }
static targets = [ "top", "days", "bottom" ]
static values = { "closesAt": String, "reminderBefore": Number, "entropyAction": String }
#timer
@@ -26,12 +26,7 @@ export default class extends Controller {
return
}
if (this.hasClosingTopTarget) {
this.closingTopTarget.innerHTML = closesInDays < 1 ? "Closes" : "Closes in"
}
if (this.hasConsideringTopTarget) {
this.consideringTopTarget.innerHTML = closesInDays < 1 ? "Falls Back" : "Falls Back in"
}
this.topTarget.innerHTML = closesInDays < 1 ? this.entropyActionValue : `${this.entropyActionValue} in`
this.daysTarget.innerHTML = closesInDays < 1 ? "!" : closesInDays
this.bottomTarget.innerHTML = closesInDays < 1 ? "Today" : (closesInDays === 1 ? "day" : "days")