From 485029f01bc3dfee7db8521933b0782d4321aa95 Mon Sep 17 00:00:00 2001 From: PawiX25 Date: Wed, 11 Dec 2024 20:00:05 +0100 Subject: [PATCH] Add program modal and filter for 'Ending Soon' programs --- index.html | 21 ++++++++++ script.js | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++--- styles.css | 94 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 227 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 87f0f57..a77f71b 100644 --- a/index.html +++ b/index.html @@ -24,12 +24,33 @@
+
+ + diff --git a/script.js b/script.js index 78b11a2..b161485 100644 --- a/script.js +++ b/script.js @@ -10,7 +10,19 @@ async function loadPrograms() { } } -function formatDeadline(deadlineStr) { +function formatDeadline(deadlineStr, opensStr) { + if (opensStr) { + const opensDate = new Date(opensStr); + const now = new Date(); + if (now < opensDate) { + return `Opens ${opensDate.toLocaleDateString('en-US', { + month: 'long', + day: 'numeric', + year: opensDate.getFullYear() !== new Date().getFullYear() ? 'numeric' : undefined + })}`; + } + } + if (!deadlineStr) return ''; const deadline = new Date(deadlineStr); @@ -48,17 +60,21 @@ function getDeadlineClass(deadlineStr) { } function createProgramCard(program) { - const deadlineText = formatDeadline(program.deadline); + const deadlineText = formatDeadline(program.deadline, program.opens); const deadlineClass = getDeadlineClass(program.deadline); + const opensClass = program.opens && new Date() < new Date(program.opens) ? 'opens-soon' : ''; + + const encodedProgram = encodeURIComponent(JSON.stringify(program)); + return ` -
+

${program.name}

${program.status}

${program.description}

- ${program.deadline ? `
${deadlineText}
` : ''} +
${deadlineText}