Skip to content

Commit

Permalink
added deploy and updated homepage to be TopFans app
Browse files Browse the repository at this point in the history
  • Loading branch information
kwelch-eb committed Nov 1, 2018
1 parent c7a62fd commit 8b4a981
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 158 deletions.
4 changes: 4 additions & 0 deletions now.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"files": ["./build/"],
"public": true
}
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"dependencies": {
"eventbrite": "^1.0.2",
"eventbrite_design_system": "http://packages.evbops.com:8889/package/eventbrite_design_system/66.13.0",
"lodash": "^4.17.11",
"query-string": "^6.2.0",
"react": "^16.6.0",
"react-dom": "^16.6.0",
"react-router-dom": "^4.3.1",
Expand All @@ -14,7 +16,8 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"deploy": "now ./build/ --public"
},
"eslintConfig": {
"extends": "react-app"
Expand All @@ -24,5 +27,8 @@
"not dead",
"not ie <= 11",
"not op_mini all"
]
],
"devDependencies": {
"now": "^11.4.6"
}
}
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import { HashRouter as Router, Route } from 'react-router-dom';
import { RegisterPage, HomePage } from './pages';

export default class App extends Component {
Expand Down
151 changes: 147 additions & 4 deletions src/pages/HomePage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,148 @@
import React from 'react';
import React, { Component } from 'react';
import queryString from 'query-string';
import _ from 'lodash';
import 'eventbrite_design_system/css/eds.css';
import DataTable from 'eventbrite_design_system/dataTable/DataTable';
import Button from 'eventbrite_design_system/button/Button';

export default () => (
<h1>Hello HomePage!</h1>
);
const CLIENT_ID = process.env.CLIENT_ID;

export default class SomeOtherPage extends Component {
constructor(props) {
super(props);
this.state = {
access_token: '',
token_type: '',
user: {
name: '',
},
attendees: [],
organizers: [],
events: [],
all: false,
};
}

handleClick = () => {
window.location.href = 'https://www.eventbrite.com/oauth/authorize?response_type=token&client_id='+CLIENT_ID;
}

componentDidMount() {
const parsedHash = queryString.parse(window.location.hash);
this.setState({
...parsedHash
});

if (parsedHash.access_token) {
setTimeout(() => {
Promise.all(this.state.events.map((event, key) => {
return this.fetchEventAttendees(event.id, key);
}))
.then(() => {
this.props.eb.FrameAPI.init();
this.setState({
all: true
});
});
}, 0);
}
}

fetchEventAttendees(event_id, key) {
return fetch(`https://www.eventbriteapi.com/v3/events/${event_id}/attendees/?token=${this.state.access_token}`)
.then((response) => (response.json()))
.then((s) => {
let {
events
} = this.state;
events[key].attendees = s.attendees;

this.setState({
events,
});
});
}

getAllAttendees() {
let { events } = this.state;
let attendees = {};

events.forEach((event) => {
if (event.attendees) {
event.attendees.forEach((att) => {
if (!attendees[att.profile.email]) {
attendees[att.profile.email] = 1;
} else {
attendees[att.profile.email]++;
}
});
}
});

return _.sortBy(Object.keys(attendees).map((key) => {
return {
name: key,
visits: attendees[key]
};
}), (obj) => obj.visits * -1);
}

renderDataTable(attendees) {
if (Object.keys(attendees).length === 0) {
return;
}

return (
<DataTable
items={attendees}
columns={[
{
fieldName: 'name',
fieldLabel: 'E-mail',
isEditable: false,
isSortable: true,
},
{
fieldName: 'visits',
fieldLabel: 'Visits',
isEditable: false,
isSortable: true,
}
]}
/>
);
}

render() {
let {
access_token
} = this.state;

let button = (!access_token) ? (
<div>
<Button style="fill" onClick={this.handleClick}>
Authenticate
</Button>
</div>
): null;

let attendees = this.getAllAttendees();
let table = this.renderDataTable(attendees)

return (
<div className="eds-g-grid">
<div className="eds-g-cell eds-g-cell-12-12">
<div className="eds-align--center">
<section className="eds-l-pad-all-4">
<h2 className="eds-text-hl eds-text--center eds-l-pad-all-2">
Top Fans
</h2>
{button}
</section>
</div>
{table}
</div>
</div>
);
}
}
150 changes: 0 additions & 150 deletions src/pages/SomeOtherPage.js

This file was deleted.

1 change: 0 additions & 1 deletion src/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { default as HomePage } from './HomePage';
export { default as RegisterPage } from './RegisterPage';
// export {default as SomeOtherPage} from './SomeOtherPage'
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5754,6 +5754,10 @@ [email protected]:
dependencies:
lodash "^4.11.2"

now@^11.4.6:
version "11.4.6"
resolved "https://registry.npmjs.org/now/-/now-11.4.6.tgz#611729c3de4c1108be72f9f9a4b3851dece29380"

npm-bundled@^1.0.1:
version "1.0.5"
resolved "https://registry.yarnpkg.com/npm-bundled/-/npm-bundled-1.0.5.tgz#3c1732b7ba936b3a10325aef616467c0ccbcc979"
Expand Down Expand Up @@ -6932,6 +6936,13 @@ [email protected], qs@~6.5.2:
version "6.5.2"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"

query-string@^6.2.0:
version "6.2.0"
resolved "https://registry.npmjs.org/query-string/-/query-string-6.2.0.tgz#468edeb542b7e0538f9f9b1aeb26f034f19c86e1"
dependencies:
decode-uri-component "^0.2.0"
strict-uri-encode "^2.0.0"

querystring-es3@^0.2.0:
version "0.2.1"
resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73"
Expand Down Expand Up @@ -8143,6 +8154,10 @@ stream-shift@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.0.tgz#d5c752825e5367e786f78e18e445ea223a155952"

strict-uri-encode@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546"

string-length@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/string-length/-/string-length-2.0.0.tgz#d40dbb686a3ace960c1cffca562bf2c45f8363ed"
Expand Down

0 comments on commit 8b4a981

Please sign in to comment.