Add basic deadline to sections index
This commit is contained in:
parent
782355322e
commit
f4106b9fb6
15 changed files with 175 additions and 1 deletions
27
app/javascript/deadline_display.js
Normal file
27
app/javascript/deadline_display.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
export default function initDeadlineDisplay() {
|
||||
document.querySelectorAll('[data-behaviour="deadline_display"]').forEach((span) => {
|
||||
const deadline = new Date(span.dataset.deadline)
|
||||
|
||||
function update() {
|
||||
const remaining = Math.floor((deadline - new Date()) / 1000)
|
||||
const days = Math.floor(remaining / (60 * 60 * 24))
|
||||
const hours = Math.floor((remaining % (60 * 60 * 24)) / (60 * 60))
|
||||
const minutes = Math.floor((remaining % (60 * 60)) / 60)
|
||||
const seconds = remaining % 60
|
||||
let remainingText = ""
|
||||
if (days > 0) {
|
||||
remainingText += `${days} dagen, `
|
||||
}
|
||||
if (days > 0 || hours > 0) {
|
||||
remainingText += `${hours} uren, `
|
||||
}
|
||||
if (days > 0 || hours > 0 || minutes > 0) {
|
||||
remainingText += `${minutes} minuten en `
|
||||
}
|
||||
remainingText += `${seconds} seconden`
|
||||
span.innerText = remainingText
|
||||
}
|
||||
|
||||
setInterval(update, 200)
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue