Skip to content

Commit

Permalink
reactifying Upcoming (#779)
Browse files Browse the repository at this point in the history
* reactifying Upcoming

* better name

* removing unused test
  • Loading branch information
gvn authored Sep 22, 2017
1 parent ddb1c76 commit 90ae297
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 53 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"server": "cd network-api && source venv/bin/activate && python app/manage.py runserver",
"start": "npm i && npm run build-uncompressed && run-p server watch:**",
"test:eslint": "eslint --config ./.eslintrc.yaml scripts/**/*.js source/js/**/*.js source/js/components/**/*.jsx",
"test:json": "ajv validate -s source/json/news.schema.json -d source/json/temp/news.json && ajv validate -s source/json/upcoming.schema.json -d source/json/temp/upcoming.json",
"test:pug": "pug-lint source/pug/partials/ source/pug/templates/ source/pug/partials/",
"test:scss": "stylelint \"source/sass/**/*.scss\" \"source/js/components/**/*.scss\" --syntax scss",
"test": "npm run build && run-s test:**",
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-pug.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function buildPage(template, target, extraData, hasExternalTarget = false) {
buildPage(`home`, `/`);
buildPage(`people`, `/people`);
buildPage(`get-involved`, `/get-involved`);
buildPage(`upcoming`, `/programs/upcoming`, JSON.parse((shelljs.cat(`source/json/temp/upcoming.json`).toString())));
buildPage(`upcoming`, `/programs/upcoming`);
buildPage(`projects`, `/projects`, require(`./massage-projects.js`));
buildPage(`about`, `/about`);
buildPage(`news`, `/news`, {news: JSON.parse((shelljs.cat(`source/json/temp/news.json`).toString()))});
Expand Down
1 change: 0 additions & 1 deletion scripts/fetch-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ fetchJSON(`pulse-inclusion`, `https://${environment[`PULSE_API_DOMAIN`]}/api/pul
fetchJSON(`pulse-decentralization`, `https://${environment[`PULSE_API_DOMAIN`]}/api/pulse/entries/?issue=Decentralization&featured=True&ordering=-created`);
fetchJSON(`pulse-literacy`, `https://${environment[`PULSE_API_DOMAIN`]}/api/pulse/entries/?issue=Web%20Literacy&featured=True&ordering=-created`);
fetchJSON(`news`, `https://${environment[`NETWORK_API_DOMAIN`]}/api/news/?format=json&featured=True&page=1`);
fetchJSON(`upcoming`, `https://${environment[`NETWORK_API_DOMAIN`]}/api/milestones`);
111 changes: 111 additions & 0 deletions source/js/components/upcoming/upcoming.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import React from 'react';
import PropTypes from 'prop-types';
import env from '../../../../env.json';
import moment from 'moment';

export default class Upcoming extends React.Component {
constructor(props) {
super(props);

this.state = {
events: []
};
}

componentDidMount() {
let xhr = new XMLHttpRequest();

xhr.addEventListener(`load`, () => {
this.setState({
events: JSON.parse(xhr.response)
});
});

xhr.open(`GET`, `https://${env.NETWORK_API_DOMAIN}/api/milestones`);
xhr.send();
}

render() {
let data = this.state.events;

let futureEvents = data.filter((event) => {
return event.start_date === null || moment(event.start_date).isAfter(Date.now());
});

// Sort chronologically
futureEvents.sort((a, b) => {
return a.start_date > b.start_date;
});

let pastEvents = data.filter((event) => {
return moment(event.start_date).isBefore(Date.now());
});

// Sort reverse-chronologically
pastEvents.sort((a, b) => {
return a.start_date < b.start_date;
});

let buildEvent = (meta, key) => {
let displayDate;

if(moment(meta.start_date).date() === 1 && moment(meta.end_date).date() === moment(meta.end_date).endOf(`month`).date()) {
// Only show Month for events that span entire month
displayDate = moment(meta.start_date).format(`MMMM, YYYY`);
} else if(meta.start_date && meta.end_date && meta.start_date !== meta.end_date) {
// Events that span a few days, but not a whole month
displayDate = `${moment(meta.start_date).format(`MMMM D`)}-${moment(meta.end_date).format(`D, YYYY`)}`;
} else if(meta.start_date) {
// Single day events
displayDate = moment(meta.start_date).format(`MMMM D, YYYY`);
} else {
// Events missing dates
displayDate = `TBD`;
}

return (
<div className="row my-5" key={key}>
<div className="col-sm-4">
{ meta.photo && <img src={meta.photo}/> }
</div>
<div className="col-sm-8">
<p className="h6-gray mt-3 mt-sm-0">{displayDate}</p>
<h2 className="h4-light-black">{meta.headline}</h2>
<p className="body-black">{meta.description}</p>
<a className="cta-link" href={meta.link_url}>{meta.link_label}</a>
</div>
</div>
);
};

futureEvents = futureEvents.map((item, index) => {
return buildEvent(item, `fe-${index}`);
});

pastEvents = pastEvents.map((item, index) => {
return buildEvent(item, `pe-${index}`);
});

return (
<div className="container">
{ futureEvents }
<div className="row">
<div className="col">
<div className="slanty-background">
<h3 className="h2-headings-white">Recent</h3>
</div>
</div>
</div>
{ pastEvents }
</div>
);
}
}

Upcoming.propTypes = {
data: PropTypes.array
};

Upcoming.defaultProps = {
data: []
};
6 changes: 6 additions & 0 deletions source/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import MultipageNav from './components/multipage-nav/multipage-nav.jsx';
import Highlights from './components/highlights/highlights.jsx';
import Leaders from './components/leaders/leaders.jsx';
import HomeNews from './components/home-news/home-news.jsx';
import Upcoming from './components/upcoming/upcoming.jsx';

import env from '../../env.json';

Expand Down Expand Up @@ -195,6 +196,11 @@ let main = {
ReactDOM.render(<Highlights data={data.highlights}/>, document.querySelector(`#home-highlights`));
}
}

// Upcoming
if (document.querySelector(`#upcoming`)) {
ReactDOM.render(<Upcoming/>, document.querySelector(`#upcoming`));
}
}
};

Expand Down
51 changes: 1 addition & 50 deletions source/pug/views/upcoming.pug
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,11 @@ extends ../templates/master.pug
block masterParams
- let pageTitle = `Upcoming`;

mixin event(meta)
.row.my-5
.col-sm-4
- if(meta.photo)
img(src=meta.photo)
.col-sm-8
- if(moment(meta.start_date).date() === 1 && moment(meta.end_date).date() === moment(meta.end_date).endOf(`month`).date())
// Only show Month for events that span entire month
p.h6-gray.mt-3.mt-sm-0=moment(meta.start_date).format(`MMMM, YYYY`)
- else if(meta.start_date && meta.end_date && meta.start_date !== meta.end_date)
// Events that span a few days, but not a whole month
p.h6-gray=`${moment(meta.start_date).format(`MMMM D`)}-${moment(meta.end_date).format(`D, YYYY`)}`
- else if(meta.start_date)
// Single day events
p.h6-gray.mt-3.mt-sm-0=moment(meta.start_date).format(`MMMM D, YYYY`)
- else
// Events missing dates
p.h6-gray TBD
h2.h4-light-black=meta.headline
p.body-black=meta.description
a.cta-link(href=meta.link_url)=meta.link_label

block centerNav
p Upcoming

block heroGuts
+subpageHero(`Upcoming`, `A snapshot of key milestones on the horizon. Many ways to get involved.`)

block content
.container
-
let futureEvents = data.filter((event) => {
return event.start_date === null || moment(event.start_date).isAfter(Date.now());
});
// Sort chronologically
futureEvents.sort((a, b) => {
return a.start_date > b.start_date;
});
let pastEvents = data.filter((event) => {
return moment(event.start_date).isBefore(Date.now());
});
// Sort reverse-chronologically
pastEvents.sort((a, b) => {
return a.start_date < b.start_date;
});
each event in futureEvents
+event(event)
.row
.col
.slanty-background
h3.h2-headings-white Recent
each event in pastEvents
+event(event)
#upcoming

0 comments on commit 90ae297

Please sign in to comment.