diff --git a/src/js/components/dates/DateSelector.jsx b/src/js/components/dates/DateSelector.jsx index 453495a..0681adf 100644 --- a/src/js/components/dates/DateSelector.jsx +++ b/src/js/components/dates/DateSelector.jsx @@ -1,5 +1,6 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; +import { formatDate } from '../util'; export default class DateSelector extends Component { constructor(props) { @@ -36,7 +37,7 @@ export default class DateSelector extends Component { value={date} checked={this.state.isChecked} onChange={this.handleChange} - /> {date} + /> {formatDate(date)} ); } diff --git a/src/js/components/parser.js b/src/js/components/parser.js index fb83b2d..32e617f 100644 --- a/src/js/components/parser.js +++ b/src/js/components/parser.js @@ -1,17 +1,17 @@ -import $ from "jquery"; +import $ from 'jquery'; -import Venues from "../../data/venues.json"; -import { getEditDistance } from "./util"; +import Venues from '../../data/venues.json'; +import { getEditDistance, formatDate } from './util'; export default class Parser { constructor() { - this.list = "https://metasyn.pw/s/shows.json"; + this.list = 'https://metasyn.pw/s/shows.json'; } parseData() { return fetch(this.list) .then(r => r.json()) - .then(data => { + .then((data) => { const organized = Parser.sortByDateForReal(data); const dates = Parser.getDates(organized); const geojson = Parser.geojsonify(organized); @@ -23,6 +23,7 @@ export default class Parser { static getDates(organized) { const dates = []; + // eslint-disable-next-line array-callback-return Object.keys(organized).map((x, i) => { dates.push({ id: i, date: $.trim(x), checked: true }); }); @@ -31,7 +32,7 @@ export default class Parser { static sortByDateForReal(data) { const organized = {}; - for (let i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i += 1) { if (!organized[data[i].date]) { organized[data[i].date] = []; } @@ -49,23 +50,23 @@ export default class Parser { // Array is zero indexed but nth-child starts at 1 const index = i + 1; - const $shows = $results.find(`body > li:nth-child(${index})`).find("li"); + const $shows = $results.find(`body > li:nth-child(${index})`).find('li'); for (let si = 0; si < $shows.length; si += 1) { const things = []; $($shows[si]) - .find("a") + .find('a') .each((_, x) => { things.push($.trim(x.text)); }); - const deets = $.trim($shows[si].innerText.split("\n").slice(-3, -2)); + const deets = $.trim($shows[si].innerText.split('\n').slice(-3, -2)); organized[dates[i].date].push({ venue: things.shift(), date: dates[i].date, details: deets, - artists: things + artists: things, }); } } @@ -89,44 +90,43 @@ export default class Parser { if (!Venues[showData.venue]) { try { for (let v = 0; v < venueList.length; v += 1) { - const misspelled = showData.venue.replace(/\W/g, ""); - const spelledCorrect = venueList[v].replace(/\W/g, ""); + const misspelled = showData.venue.replace(/\W/g, ''); + const spelledCorrect = venueList[v].replace(/\W/g, ''); const editDistance = getEditDistance(misspelled, spelledCorrect); if (editDistance <= 3) { - console.log( - `"${showData.venue}" has been replaced with "${venueList[v]}"` - ); + console.log(`'${showData.venue}' has been replaced with '${venueList[v]}'`); showData.venue = venueList[v]; } } } catch (e) { - console.log("Missing Venue?", e); + console.log('Missing Venue?', e); } } - const showString = `${dateKeys[i]} - ${ + const formattedDate = formatDate(dateKeys[i]); + const showString = `${formattedDate} - ${ showData.venue - } | ${showData.artists.join(" | ")} | ${showData.details}`; + } | ${showData.artists.join(' | ')} | ${showData.details}`; const artistsString = showData.artists .map(x => `- ${x}
`) - .join(""); - const showHTML = `

${dateKeys[i]}


${artistsString}
${showData.details}

`; + .join(''); + const showHTML = `

${formattedDate}


${artistsString}
${showData.details}

`; const show = { - type: "Feature", + type: 'Feature', geometry: { - type: "Point", - coordinates: Venues[showData.venue] || [-122.42296, 37.826524] + type: 'Point', + coordinates: Venues[showData.venue] || [-122.42296, 37.826524], // alcatraz }, properties: { sid: `${i}-${j}`, date: dateKeys[i], venue: showData.venue, artists: showData.artists, - details: showData.details.replace(/ ,/g, ""), // fucking commas + details: showData.details.replace(/ ,/g, ''), // fucking commas showString, - showHTML - } + showHTML, + }, }; // add show to features array @@ -136,8 +136,8 @@ export default class Parser { // format for valid geojson const geojson = { - type: "FeatureCollection", - features + type: 'FeatureCollection', + features, }; return geojson; } diff --git a/src/js/components/util.js b/src/js/components/util.js index c6f74d9..6e1ce22 100644 --- a/src/js/components/util.js +++ b/src/js/components/util.js @@ -1,4 +1,5 @@ import _ from 'lodash'; +import {DateTime} from 'luxon'; // Compute the edit distance between the two given strings export function getEditDistance(a, b) { @@ -95,3 +96,21 @@ export function getMinMaxDates(dates) { maxTime, }; } + +export function getWeekDay(date) { + // Create an array containing each day, starting with Sunday. + const weekdays = [ + 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', + ]; + // Use the getDay() method to get the day. + const day = date.getDay(); + // Return the element that corresponds to that index. + return weekdays[day]; +} + +export function formatDate(dateString) { + const date = DateTime.fromISO(dateString); // force pacific timezone + date.setZone('America/Los_Angeles'); + return `${date.weekdayShort}, ${date.month}-${date.day}`; +} +