Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Mar 9, 2021. It is now read-only.

Commit 156112d

Browse files
committed
use unfeth instead of axios
1 parent 4212087 commit 156112d

File tree

3 files changed

+126
-116
lines changed

3 files changed

+126
-116
lines changed

package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "xo",
8-
"lint":
9-
"prettier 'utils/**/*.js' 'components/**/*.js' 'pages/**/*.js' 'lib/**/*.js' 'hocs/**/*.js' '*.js' --write --single-quote --print-width='80' --trailing-comma='all' && xo --fix",
8+
"lint": "prettier 'utils/**/*.js' 'components/**/*.js' 'pages/**/*.js' 'lib/**/*.js' 'hocs/**/*.js' '*.js' --write --single-quote --print-width='80' --trailing-comma='all' && xo --fix",
109
"precommit": "lint-staged",
1110
"analyze": "cross-env ANALYZE=1 next build",
1211
"dev": "cross-env NODE_ENV=development next",
@@ -15,15 +14,24 @@
1514
},
1615
"xo": {
1716
"parser": "babel-eslint",
18-
"extends": ["prettier", "prettier/react", "plugin:react/recommended"],
19-
"env": ["browser", "node"],
17+
"extends": [
18+
"prettier",
19+
"prettier/react",
20+
"plugin:react/recommended"
21+
],
22+
"env": [
23+
"browser",
24+
"node"
25+
],
2026
"rules": {
2127
"linebreak-style": 0,
2228
"react/display-name": 0,
2329
"react/prop-types": 0
2430
},
2531
"space:": 2,
26-
"ignores": ["next.config.js"]
32+
"ignores": [
33+
"next.config.js"
34+
]
2735
},
2836
"lint-staged": {
2937
"*.js": [
@@ -36,8 +44,8 @@
3644
"author": "Vinay Puppal <[email protected]> (https://www.vinaypuppal.com/)",
3745
"license": "BSD",
3846
"dependencies": {
39-
"axios": "^0.16.2",
4047
"feathers-rest": "^1.8.0",
48+
"isomorphic-unfetch": "2.0.0",
4149
"moment": "^2.19.1",
4250
"next": "^4.1.0",
4351
"nprogress": "^0.2.0",

pages/events.js

Lines changed: 102 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import axios from 'axios';
2+
import fetch from 'isomorphic-unfetch';
33
import { Card } from 'semantic-ui-react';
44

55
import publicPage from '../hocs/public-page';
@@ -10,100 +10,108 @@ import {
1010
} from '../utils/urls';
1111
import RowEvent from '../components/row-events';
1212

13-
export default publicPage(
14-
class Events extends React.Component {
15-
static async getInitialProps() {
16-
try {
17-
const requestPastEvents = await axios.get(
18-
`${reverseProxyCORS}${pastEventsMeetupURL}`,
19-
);
20-
const requestFutureEvents = await axios.get(
21-
`${reverseProxyCORS}${futureEventsMeetupURL}`,
22-
);
23-
return {
24-
pastEvents: requestPastEvents.data,
25-
futureEvents: requestFutureEvents.data,
26-
};
27-
} catch (err) {
28-
return {
29-
pastEvents: 'err',
30-
futureEvents: 'err',
31-
};
32-
}
13+
class Events extends React.Component {
14+
static async getInitialProps() {
15+
try {
16+
const pastEvents = await fetch(
17+
`${reverseProxyCORS}${pastEventsMeetupURL}`,
18+
).then(res => {
19+
if (res.ok) return res.json();
20+
throw new Error('Failed to Retrieve Events');
21+
});
22+
const futureEvents = await fetch(
23+
`${reverseProxyCORS}${futureEventsMeetupURL}`,
24+
).then(res => {
25+
if (res.ok) return res.json();
26+
throw new Error('Failed to Retrieve Events');
27+
});
28+
return {
29+
pastEvents,
30+
futureEvents,
31+
fetchError: null,
32+
};
33+
} catch (err) {
34+
console.log(err);
35+
return {
36+
pastEvents: null,
37+
futureEvents: null,
38+
fetchError: err.message,
39+
};
3340
}
41+
}
3442

35-
render() {
36-
return (
37-
<div>
38-
<div className="top_banner_root">
39-
<h1 className="top_banner_headline">Events</h1>
40-
<h2>Because you cannot change the world alone</h2>
41-
</div>
42-
<main>
43-
{this.props.pastEvents !== 'err' &&
44-
this.props.futureEvents !== 'err' ? (
43+
render() {
44+
return (
45+
<div>
46+
<div className="top_banner_root">
47+
<h1 className="top_banner_headline">Events</h1>
48+
<h2>Because you cannot change the world alone</h2>
49+
</div>
50+
<main>
51+
{this.props.fetchError ? (
52+
<div>{this.props.fetchError}</div>
53+
) : (
54+
<div>
55+
<h4>Upcoming events</h4>
4556
<div>
46-
<h4>Upcoming events</h4>
47-
<div>
48-
{this.props.futureEvents.map(event => (
49-
<Card.Group key={event.id}>
50-
<RowEvent
51-
name={event.name}
52-
yesCount={event.yes_rsvp_count}
53-
time={event.time}
54-
venue={event.venue}
55-
link={event.link}
56-
/>
57-
</Card.Group>
58-
))}
59-
</div>
60-
<h4>Recent events</h4>
61-
<div>
62-
{this.props.pastEvents.map(event => (
63-
<Card.Group key={event.id}>
64-
<RowEvent
65-
key={event.id}
66-
name={event.name}
67-
yesCount={event.yes_rsvp_count}
68-
time={event.time}
69-
venue={event.venue}
70-
link={event.link}
71-
/>
72-
</Card.Group>
73-
))}
74-
</div>
57+
{this.props.futureEvents.map(event => (
58+
<Card.Group key={event.id}>
59+
<RowEvent
60+
name={event.name}
61+
yesCount={event.yes_rsvp_count}
62+
time={event.time}
63+
venue={event.venue}
64+
link={event.link}
65+
/>
66+
</Card.Group>
67+
))}
7568
</div>
76-
) : (
77-
<div>Failed to Retrieve Events</div>
78-
)}
79-
</main>
80-
<style jsx>{`
81-
main {
82-
background-color: #ffffff;
83-
padding-top: 30px;
84-
padding-bottom: 30px;
85-
padding-left: 30px;
86-
padding-right: 30px;
87-
min-height: calc(100vh - 70px);
88-
display: flex;
89-
justify-content: center;
90-
align-items: center;
91-
flex-direction: column;
92-
}
93-
.top_banner_root {
94-
background-color: #f4f7fb;
95-
min-height: 200px;
96-
text-align: center;
97-
}
98-
.top_banner_headline {
99-
padding-top: 20px;
100-
font-size: 4em;
101-
color: #df1cb5;
102-
font-weight: 900;
103-
}
104-
`}</style>
105-
</div>
106-
);
107-
}
108-
},
109-
);
69+
<h4>Recent events</h4>
70+
<div>
71+
{this.props.pastEvents.map(event => (
72+
<Card.Group key={event.id}>
73+
<RowEvent
74+
key={event.id}
75+
name={event.name}
76+
yesCount={event.yes_rsvp_count}
77+
time={event.time}
78+
venue={event.venue}
79+
link={event.link}
80+
/>
81+
</Card.Group>
82+
))}
83+
</div>
84+
</div>
85+
)}
86+
</main>
87+
<style jsx>{`
88+
main {
89+
background-color: #ffffff;
90+
padding-top: 30px;
91+
padding-bottom: 30px;
92+
padding-left: 30px;
93+
padding-right: 30px;
94+
min-height: calc(100vh - 70px);
95+
display: flex;
96+
justify-content: center;
97+
align-items: center;
98+
flex-direction: column;
99+
}
100+
.top_banner_root {
101+
background-color: #f4f7fb;
102+
min-height: 200px;
103+
text-align: center;
104+
}
105+
.top_banner_headline {
106+
padding-top: 20px;
107+
font-size: 4em;
108+
color: #df1cb5;
109+
font-weight: 900;
110+
}
111+
`}</style>
112+
</div>
113+
);
114+
}
115+
}
116+
117+
export default publicPage(Events);

yarn.lock

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,6 @@ aws4@^1.2.1, aws4@^1.6.0:
347347
version "1.6.0"
348348
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e"
349349

350-
axios@^0.16.2:
351-
version "0.16.2"
352-
resolved "https://registry.yarnpkg.com/axios/-/axios-0.16.2.tgz#ba4f92f17167dfbab40983785454b9ac149c3c6d"
353-
dependencies:
354-
follow-redirects "^1.2.3"
355-
is-buffer "^1.1.5"
356-
357350
babel-code-frame@^6.16.0, babel-code-frame@^6.22.0, babel-code-frame@^6.26.0:
358351
version "6.26.0"
359352
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b"
@@ -1799,7 +1792,7 @@ dateformat@^1.0.11, dateformat@^1.0.12:
17991792
get-stdin "^4.0.1"
18001793
meow "^3.3.0"
18011794

1802-
debug@2, [email protected], debug@^2.1.1, debug@^2.2.0, debug@^2.6.8, debug@^2.6.9:
1795+
debug@2, [email protected], debug@^2.1.1, debug@^2.2.0, debug@^2.6.8:
18031796
version "2.6.9"
18041797
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
18051798
dependencies:
@@ -2713,12 +2706,6 @@ [email protected]:
27132706
debug "^2.2.0"
27142707
stream-consume "^0.1.0"
27152708

2716-
follow-redirects@^1.2.3:
2717-
version "1.2.5"
2718-
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.2.5.tgz#ffd3e14cbdd5eaa72f61b6368c1f68516c2a26cc"
2719-
dependencies:
2720-
debug "^2.6.9"
2721-
27222709
for-in@^1.0.1:
27232710
version "1.0.2"
27242711
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
@@ -3716,6 +3703,13 @@ isomorphic-fetch@^2.1.1:
37163703
node-fetch "^1.0.1"
37173704
whatwg-fetch ">=0.10.0"
37183705

3706+
3707+
version "2.0.0"
3708+
resolved "https://registry.yarnpkg.com/isomorphic-unfetch/-/isomorphic-unfetch-2.0.0.tgz#f50140a4c163d7582b5f37f1591968c4f809a645"
3709+
dependencies:
3710+
node-fetch "^1.7.1"
3711+
unfetch "^3.0.0"
3712+
37193713
isstream@~0.1.2:
37203714
version "0.1.2"
37213715
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
@@ -4461,7 +4455,7 @@ next@^4.1.0:
44614455
write-file-webpack-plugin "4.2.0"
44624456
xss-filters "1.2.7"
44634457

4464-
node-fetch@^1.0.1, node-fetch@^1.6.3:
4458+
node-fetch@^1.0.1, node-fetch@^1.6.3, node-fetch@^1.7.1:
44654459
version "1.7.3"
44664460
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
44674461
dependencies:
@@ -6553,7 +6547,7 @@ underscore.string@~2.2.0rc:
65536547
version "2.2.1"
65546548
resolved "https://registry.yarnpkg.com/underscore.string/-/underscore.string-2.2.1.tgz#d7c0fa2af5d5a1a67f4253daee98132e733f0f19"
65556549

6556-
6550+
[email protected], unfetch@^3.0.0:
65576551
version "3.0.0"
65586552
resolved "https://registry.yarnpkg.com/unfetch/-/unfetch-3.0.0.tgz#8d1e0513a4ecd0e5ff2d41a6ba77771aae8b6482"
65596553

0 commit comments

Comments
 (0)