feat(countdown): redirect to /adhesion at the end

This commit is contained in:
Matthieu Bessat 2023-07-14 11:31:40 +02:00
parent aa822b6f2e
commit 8687dae1ee

View file

@ -69,15 +69,23 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/luxon/3.3.0/luxon.min.js" integrity="sha512-KKbQg5o92MwtJKR9sfm/HkREzfyzNMiKPIQ7i7SZOxwEdiNCm4Svayn2DBq7MKEdrqPJUOSIpy1v6PpFlCQ0YA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/luxon/3.3.0/luxon.min.js" integrity="sha512-KKbQg5o92MwtJKR9sfm/HkREzfyzNMiKPIQ7i7SZOxwEdiNCm4Svayn2DBq7MKEdrqPJUOSIpy1v6PpFlCQ0YA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script> <script>
const components = ['days', 'hours', 'minutes', 'seconds'] const components = ['days', 'hours', 'minutes', 'seconds']
// to test: const target = luxon.DateTime.now().plus(luxon.Duration.fromISO("PT10S"))
const target = luxon.DateTime.utc(2023, 7, 14, 10, 0, 0)
function render() { function render() {
let duration = luxon.DateTime.now().diff(luxon.DateTime.utc(2023, 7, 14, 10, 0, 0), components) let now = luxon.DateTime.now()
console.log(duration.values) let duration = now.diff(target, components)
console.debug(duration.values)
if (target < now) {
console.log("COUNTDOWN: Target reached!")
document.location = document.location.origin + "/adhesion"
}
components.forEach(key => { components.forEach(key => {
document.getElementById(key).innerText = (-duration.values[key]).toString().split(".")[0].padStart(2, "0") document.getElementById(key).innerText = (-duration.values[key]).toString().split(".")[0].padStart(2, "0")
// test with random values // test with random values
// document.getElementById(key).innerText = (Math.floor(Math.random() * 99)).toString().split(".")[0].padStart(2, "0") // document.getElementById(key).innerText = (Math.floor(Math.random() * 99)).toString().split(".")[0].padStart(2, "0")
}) })
@ -87,7 +95,6 @@ render()
setInterval(() => { setInterval(() => {
render() render()
}, 1000) }, 1000)
</script> </script>
{{ end }} {{ end }}