From 358afc73aa13450fce04ac65c319dafd90c78fe3 Mon Sep 17 00:00:00 2001
From: Quincy Morgan <2046746+quincylvania@users.noreply.github.com>
Date: Thu, 18 Jan 2024 18:13:26 -0500
Subject: [PATCH] Add notification system for events, e.g. mapping usa
---
_includes/scripts.html | 1 +
_includes/scripts/realtime_updater.js | 90 +++++++++++++++++++++
_includes/scripts/smooth_anchor_scroller.js | 7 +-
_includes/scripts/time_localizer.js | 24 +-----
_includes/site_meta.html | 28 +++++++
_sass/dogwood/_layout.scss | 40 +++++++--
6 files changed, 156 insertions(+), 34 deletions(-)
create mode 100644 _includes/scripts/realtime_updater.js
diff --git a/_includes/scripts.html b/_includes/scripts.html
index 636f67e..1c5198d 100644
--- a/_includes/scripts.html
+++ b/_includes/scripts.html
@@ -2,4 +2,5 @@
{% include scripts/icon_loader.js %}
{% include scripts/time_localizer.js %}
{% include scripts/smooth_anchor_scroller.js %}
+ {% include scripts/realtime_updater.js %}
\ No newline at end of file
diff --git a/_includes/scripts/realtime_updater.js b/_includes/scripts/realtime_updater.js
new file mode 100644
index 0000000..d139929
--- /dev/null
+++ b/_includes/scripts/realtime_updater.js
@@ -0,0 +1,90 @@
+document.addEventListener("DOMContentLoaded", function() {
+
+ var scheduleRowsToCheck = document.querySelectorAll('table.schedule tr[start][end]');
+
+ if (scheduleRowsToCheck.length > 0) {
+ setInterval(checkScheduleRows, 1000);
+ checkScheduleRows();
+ }
+
+ function checkScheduleRows() {
+ var now = new Date();
+ scheduleRowsToCheck.forEach(function(el) {
+ var start = new Date(parseInt(el.getAttribute('start') + '000'));
+ var end = new Date(parseInt(el.getAttribute('end') + '000'));
+ if (now >= start && now < end) {
+ if (!el.classList.contains('ongoing')) {
+ el.classList.add('ongoing');
+ }
+ } else if (el.classList.contains('ongoing')) {
+ el.classList.remove('ongoing');
+ }
+ });
+ }
+
+ var homepageUrl = document.querySelector('meta[name="homepage"]').getAttribute('content');
+ var nextEventEl = document.querySelector('meta[name="dogwood-next-event"]');
+ if (nextEventEl) createRealtimeMessage();
+
+ function createRealtimeMessage() {
+
+ var title = nextEventEl.getAttribute('content');
+
+ var noticeInfo = JSON.parse(localStorage.getItem('notice-info')) || null;
+ if (noticeInfo && noticeInfo.title !== title) {
+ localStorage.removeItem('notice-info');
+ noticeInfo = null;
+ }
+
+ var end = new Date(parseInt(nextEventEl.getAttribute('end') + '000'));
+ var now = new Date();
+
+ // don't show something that's over
+ if (now > end) return;
+
+ var link = nextEventEl.getAttribute('href');
+
+ // don't show if we're already on the promoted part of the site
+ if (window.location.href.startsWith(link) ||
+ // or if we're on the homepage since content is already promoted there
+ window.location.href === homepageUrl + '/') return;
+
+ var start = new Date(parseInt(nextEventEl.getAttribute('start') + '000'));
+
+ if (now < start &&
+ noticeInfo &&
+ now.getTime() < noticeInfo.clicked + 172800000
+ ) {
+ // don't notify again if event hasn't started yet and it's been under two days since last notified
+ return;
+ }
+
+ var tagline = nextEventEl.getAttribute('tagline');
+ var logo = nextEventEl.getAttribute('logo');
+
+ var notice = document.createElement('a');
+ notice.setAttribute('href', link);
+ notice.setAttribute('id', 'notice-overlay');
+ notice.classList.add(nextEventEl.getAttribute('noticeclass'));
+ var html = '';
+
+ if (logo) {
+ html += '';
+ }
+ html += '
';
+ var status = start > now ? 'Upcoming' : 'Happening Now';
+ html += '