Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip events that ended in the past #17

Open
wants to merge 4 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tasks": {
"launch": "npx http-server"
}
}
27 changes: 22 additions & 5 deletions map.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ async function initialize() {
console.log('Loading Events...');
window.events.load()
.then(events => {
const now = new Date();
events.forEach(event => {
if (!event.title) return; // skip empty events just in case
if (!event.geometry) console.error('Event Geometry Missing', { event });
if (new Date(event.end_time) < now) return; // skip events that have ended
event.marker = new google.maps.marker.AdvancedMarkerElement({
map: window.map,
position: event.geometry,
Expand Down Expand Up @@ -111,6 +111,8 @@ window.filter = function (filters = {}) {
if (options.category) {
categories = options.category.split(',')
}

const now = new Date();

// Filter events
let count = window.events.get().filter(event => {
Expand All @@ -126,11 +128,17 @@ window.filter = function (filters = {}) {
)
event.visible = false;
}

// check category
if (categories.length && !event.categories.some(category => categories.includes(category))) {
event.visible = false;
}

// check if event has ended
if (new Date(event.end_time) < now) {
event.visible = false;
}

// if (event.visible) {
// event.marker.content.classList.add('drop')
// } else {
Expand Down Expand Up @@ -258,7 +266,7 @@ class Events {

this.cache = window.localStorage.getItem('events');

if (this.cache)
if (this.cache && typeof this.cache === 'string')
this.cache = JSON.parse(this.cache);

return this.cache;
Expand All @@ -271,14 +279,23 @@ class Events {
* @returns {object[]} events
*/
set(events) {
const now = new Date()
// if (!event.title) return; // skip empty events just in case
// if (!event.geometry) console.error('Event Geometry Missing', { event });
// if (new Date(event.end_time) < new Date()) return; // skip events that have ended
const data = events.filter(event =>
event.title &&
event.geometry &&
(!event.end_time || new Date(event.end_time) > now)
);
try {
// Known to throw QuotaExceededException on Safari
window.localStorage.setItem('events', JSON.stringify(events));
window.localStorage.setItem('events', JSON.stringify(data));
window.localStorage.setItem('events_age', Date.now());
} catch (e) {
console.error(e)
}
this.cache = events;
this.cache = data;
return this.cache;
}

Expand Down