-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example.js
51 lines (43 loc) · 1.3 KB
/
Example.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
// Dependencies
import React from 'react';
import SpotifyListener from 'spotify-activity-listener';
import MusicIcon from 'react-icons/lib/md/library-music';
// Styles
import styles from './styles';
class Example extends React.Component {
constructor(props) {
super(props);
this.Listener = new SpotifyListener({
username: '...',
key: '...',
trackCount: 1,
pollInterval: 3000,
callback: (res) => this.setState({
track: res[0],
}),
});
this.state = {
track: {},
};
}
componentDidMount() {
this.Listener.startListening();
}
componentWillUnmount() {
this.Listener.stopListening();
}
render() {
return(
<div style={styles.wrap}>
{(this.state.track.art) ? <img style={styles.art} src={this.state.track.art} /> : null }
<div style={styles.infoWrap}>
<MusicIcon size={24} style={{paddingBottom: 5, opacity: (this.state.track.name) ? 1.0 : 0.0}} />
<p style={{ padding: 0, margin: 0 }} className="small">{ this.state.track.name }</p>
<p style={{ padding: 0, margin: 0 }} className="small">{ this.state.track.artist }</p>
<p style={{ padding: 0, margin: 0 }} className="small">{ this.state.track.album }</p>
</div>
</div>
);
}
};
module.exports = Example;