From 8b4a981ab8ce90c427f0636d8175b3701c54911e Mon Sep 17 00:00:00 2001 From: Kyle Welch Date: Thu, 1 Nov 2018 13:32:51 -0500 Subject: [PATCH] added deploy and updated homepage to be TopFans app --- now.json | 4 + package.json | 10 ++- src/App.js | 2 +- src/pages/HomePage.js | 151 ++++++++++++++++++++++++++++++++++++- src/pages/SomeOtherPage.js | 150 ------------------------------------ src/pages/index.js | 1 - yarn.lock | 15 ++++ 7 files changed, 175 insertions(+), 158 deletions(-) create mode 100644 now.json delete mode 100644 src/pages/SomeOtherPage.js diff --git a/now.json b/now.json new file mode 100644 index 0000000..fb4e89e --- /dev/null +++ b/now.json @@ -0,0 +1,4 @@ +{ + "files": ["./build/"], + "public": true +} diff --git a/package.json b/package.json index c7ad675..9c1689d 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" @@ -24,5 +27,8 @@ "not dead", "not ie <= 11", "not op_mini all" - ] + ], + "devDependencies": { + "now": "^11.4.6" + } } diff --git a/src/App.js b/src/App.js index fe8e339..240d7ca 100644 --- a/src/App.js +++ b/src/App.js @@ -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 { diff --git a/src/pages/HomePage.js b/src/pages/HomePage.js index 1127f16..d2f5b86 100644 --- a/src/pages/HomePage.js +++ b/src/pages/HomePage.js @@ -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 () => ( -

Hello HomePage!

-); \ No newline at end of file +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 ( + + ); + } + + render() { + let { + access_token + } = this.state; + + let button = (!access_token) ? ( +
+ +
+ ): null; + + let attendees = this.getAllAttendees(); + let table = this.renderDataTable(attendees) + + return ( +
+
+
+
+

+ Top Fans +

+ {button} +
+
+ {table} +
+
+ ); + } +} \ No newline at end of file diff --git a/src/pages/SomeOtherPage.js b/src/pages/SomeOtherPage.js deleted file mode 100644 index d9cc68c..0000000 --- a/src/pages/SomeOtherPage.js +++ /dev/null @@ -1,150 +0,0 @@ -import React, { Component } from 'react'; -import queryString from 'query-string'; -import _ from 'underscore'; -import './App.css'; -import 'eventbrite_design_system/css/eds.css'; -import EVENTS from './events'; -import DataTable from 'eventbrite_design_system/dataTable/DataTable'; -import Button from 'eventbrite_design_system/button/Button'; - -import { TOKEN } from './config'; - -export default class SomeOtherPage extends Component { - constructor(props) { - super(props); - this.state = { - access_token: '', - token_type: '', - user: { - name: '', - }, - attendees: [], - organizers: [], - events: EVENTS, - all: false, - }; - } - - handleClick = () => { - window.location.href = 'https://www.eventbrite.com/oauth/authorize?response_type=token&client_id='+TOKEN; - } - - componentDidMount() { - const parsedHash = queryString.parse(window.location.hash); - this.setState({ - ...parsedHash - }); - - if (parsedHash.access_token) { - setTimeout(() => { - Promise.all(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 ( - - ); - } - - render() { - let { - access_token - } = this.state; - - let button = (!access_token) ? ( -
- -
- ): null; - - let attendees = this.getAllAttendees(); - let table = this.renderDataTable(attendees) - - return ( -
-
-
-
-

- Top Fans -

- {button} -
-
- {table} -
-
- ); - } -} \ No newline at end of file diff --git a/src/pages/index.js b/src/pages/index.js index c014fcc..93657c7 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -1,3 +1,2 @@ export { default as HomePage } from './HomePage'; export { default as RegisterPage } from './RegisterPage'; -// export {default as SomeOtherPage} from './SomeOtherPage' diff --git a/yarn.lock b/yarn.lock index 787e355..a816016 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5754,6 +5754,10 @@ normalizr@2.2.1: 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" @@ -6932,6 +6936,13 @@ qs@6.5.2, 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" @@ -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"