-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
69 lines (58 loc) · 1.6 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict'
const { nasaApiKey } = require('./nasa-api-key');
exports.decorateConfig = (config) => {
const { overlayColor = '#000', overlayOpacity = .5 } = config.hypernasa || {};
return Object.assign({}, config, {
backgroundColor: 'transparent',
css: `
${config.css}
.hyper_main {
background-color: ${overlayColor};
background-size: cover;
background-position: center;
}
.hyper_main:before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: ${overlayColor};
opacity: ${overlayOpacity};
}
.tab_tab {
background-color: transparent !important;
}
`
});
}
exports.decorateHyper = (Hyper, { React }) =>
class extends React.Component {
constructor (props, context) {
super(props, context);
this._fetchImage();
this._startUpdater();
}
_fetchImage () {
fetch(`https://api.nasa.gov/planetary/apod?api_key=${nasaApiKey}`)
.then((response) => response.json())
.then(({ hdurl, url }) => this.setState({ image: hdurl || url }));
}
_startUpdater () {
const second = 1000
const minute = 60 * second
const hour = 60 * minute
setInterval(this._fetchImage.bind(this), hour)
}
render () {
return React.createElement(Hyper, Object.assign({}, this.props, {
customCSS: `
${this.props.customCSS}
.hyper_main {
background-image: url("${this.state && this.state.image}");
}
`
}));
}
};