Skip to content

Commit ec420f5

Browse files
committed
done!
1 parent 30403b4 commit ec420f5

File tree

12 files changed

+226
-7
lines changed

12 files changed

+226
-7
lines changed

nasa-apod/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"jest-watch-typeahead": "0.3.1",
4141
"mini-css-extract-plugin": "0.5.0",
4242
"moment": "^2.24.0",
43+
"node-sass": "^4.12.0",
4344
"open-color": "^1.7.0",
4445
"optimize-css-assets-webpack-plugin": "5.0.3",
4546
"pnp-webpack-plugin": "1.5.0",
@@ -53,12 +54,12 @@
5354
"react-dev-utils": "^9.0.3",
5455
"react-dom": "^16.9.0",
5556
"react-icons": "^3.7.0",
56-
"resolve": "1.12.0",
57+
"resolve": "^1.12.0",
5758
"resolve-url-loader": "3.1.0",
5859
"sass-loader": "7.2.0",
5960
"semver": "6.3.0",
6061
"style-loader": "1.0.0",
61-
"terser-webpack-plugin": "1.4.1",
62+
"terser-webpack-plugin": "^1.4.1",
6263
"ts-pnp": "1.1.2",
6364
"url-loader": "2.1.0",
6465
"webpack": "4.39.1",

nasa-apod/src/App.js

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,71 @@
11
import React from 'react';
2+
import ViewerTemplate from './components/ViewerTemplate';
3+
import SpaceNavigator from './components/SpaceNavigator';
4+
import Viewer from './components/Viewer';
5+
import * as api from './lib/api';
6+
import moment from 'moment';
27

38
class App extends React.Component {
9+
state = {
10+
loading : false,
11+
maxDate : null,
12+
date : null,
13+
url : null,
14+
mediaType : null
15+
};
16+
17+
getAPOD = async (date) => {
18+
19+
if(this.state.loading) return;
20+
21+
this.setState({
22+
loading : true
23+
});
24+
25+
try {
26+
const response = await api.getAPOD(date);
27+
const { date : retrievedDate, url, media_type : mediaType} = response.data;
28+
if(!this.state.maxDate) {
29+
this.setState({
30+
maxData : retrievedDate
31+
});
32+
}
33+
34+
this.setState({
35+
date : retrievedDate,
36+
mediaType,
37+
url
38+
})
39+
}catch (e) {
40+
console.log(e);
41+
}
42+
43+
this.setState({
44+
loading : false
45+
});
46+
}
47+
48+
componentDidMount() {
49+
this.getAPOD();
50+
}
51+
52+
calcDate(number) {
53+
const date = moment(this.state.date).add(number, 'days').format('YYYY-MM-DD');
54+
return date;
55+
}
56+
457
render() {
58+
const {url, mediaType, loading} = this.state;
559
return (
6-
<div>
7-
App
8-
</div>
60+
<ViewerTemplate
61+
spaceNavigator={<SpaceNavigator onNext={this.getAPOD.bind(this, this.calcDate(1))} onPrev={this.getAPOD.bind(this, this.calcDate(-1))}/>}
62+
viewer={(
63+
<Viewer
64+
url={url}
65+
mediaType={mediaType}
66+
loading={loading}/>
67+
)}
68+
/>
969
)
1070
}
1171
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import styles from './SpaceNavigator.scss';
3+
import classNames from 'classnames/bind';
4+
import { MdChevronLeft as LeftIcon, MdChevronRight as RightIcon } from 'react-icons/md';
5+
6+
const cx = classNames.bind(styles);
7+
const SpaceNavigator = ({onPrev, onNext}) => {
8+
return (
9+
<div className={cx('space-navigator')}>
10+
<div className={cx('left', 'end')}>
11+
<div className={cx('circle')} onClick={onPrev}>
12+
<LeftIcon/>
13+
</div>
14+
</div>
15+
<div className={cx('right', 'end')}>
16+
<div className={cx('circle')} onClick={onNext}>
17+
<RightIcon />
18+
</div>
19+
</div>
20+
</div>
21+
);
22+
}
23+
24+
export default SpaceNavigator;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.space-navigator {
2+
.end {
3+
position: absolute;
4+
top : 0;
5+
height: 100%;
6+
display: flex;
7+
align-items: center;
8+
color : #fff;
9+
&.left {
10+
padding : 1rem;
11+
}
12+
&.right {
13+
right : 1rem;
14+
}
15+
.circle {
16+
width:3rem;
17+
height:3rem;
18+
background:transparent;
19+
display: flex;
20+
align-items: center;
21+
justify-content: center;
22+
border-radius:50%;
23+
cursor:pointer;
24+
&:hover {
25+
background : rgba(0, 0, 0, 0.25);
26+
}
27+
&:active {
28+
background : rgba(0,0,0,0.5);
29+
}
30+
svg {
31+
font-size : 2rem;
32+
}
33+
}
34+
}
35+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './SpaceNavigator';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
import styles from './Viewer.scss';
3+
import classNames from 'classnames/bind';
4+
import {
5+
ChasingDots
6+
} from 'better-react-spinkit'
7+
8+
const cx = classNames.bind(styles);
9+
10+
const Viewer = ({mediaType, url, loading}) => {
11+
if(loading) {
12+
return <div className={cx('viewer')}>
13+
<ChasingDots color="white" size={60}/>
14+
</div>
15+
}
16+
17+
if(!url) return null;
18+
return (
19+
<div className={cx('viewer')}>
20+
{
21+
mediaType === 'image' ? (
22+
<img onClick={()=>window.open(url)} src={url} alt={"space"}/>
23+
) : (
24+
<iframe src={url} allowFullScreen autoPlay></iframe>
25+
)
26+
}
27+
</div>
28+
)
29+
}
30+
export default Viewer;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@import "utils";
2+
3+
.viewer {
4+
height : 100%;
5+
width : 100%;
6+
display : flex;
7+
align-items: center;
8+
justify-content: center;
9+
img {
10+
display:block;
11+
width : auto;
12+
max-width : calc(100% - 10rem);
13+
max-height : calc(100% - 10rem);
14+
cursor:pointer;
15+
transition : all 0.3s ease-in;
16+
box-shadow : 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
17+
&:hover {
18+
box-shadow: 0 19px 38px rgba(0,0,0,0.3), 0 15px 12px rgba(0,0,0,0.22);
19+
}
20+
}
21+
iframe {
22+
background: black;
23+
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
24+
width: calc(100% - 10rem);
25+
height: calc(100% - 10rem);
26+
}
27+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './Viewer';

nasa-apod/src/components/ViewerTemplate/ViewerTemplate.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ const cx = classNames.bind(styles);
77
const ViewerTemplate = ({viewer, spaceNavigator}) => {
88
return (
99
<div className={cx('viewer-template')}>
10-
10+
<header>
11+
Astronomy Picture of the Day
12+
</header>
13+
<div className={cx('viewer-wrapper')}>
14+
{viewer}
15+
<div className={cx('space-navigator-wrapper')}>
16+
{spaceNavigator}
17+
</div>
18+
</div>
1119
</div>
1220
)
1321
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@import 'utils';
2+
3+
.viewer-template {
4+
header {
5+
background : $oc-gray-9;
6+
height : 5rem;
7+
color : white;
8+
padding : 1rem;
9+
10+
display: flex;
11+
align-items: center;
12+
13+
font-size : 2rem;
14+
font-weight: 600;
15+
16+
@include media("<tablet") {
17+
font-size : 1.25rem;
18+
}
19+
}
20+
21+
.viewer-wrapper {
22+
position: relative;
23+
width: 100%;
24+
height : calc(100vh - 5rem);
25+
}
26+
}

0 commit comments

Comments
 (0)