-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
executable file
·82 lines (76 loc) · 1.94 KB
/
App.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
70
71
72
73
74
75
76
77
78
79
80
81
82
import React, { Component } from "react";
import Player from "./components/Player";
import Login from "./components/Login";
export const TRACKS = [
{
title: "Track 1",
artist: "Test 1",
albumArtUrl: "https://picsum.photos/200/300/?random",
audioUrl:
"https://freemusicarchive.org/music/download/b95ecf581f5b7c6d3237bfb91c6652aff29d4cad"
},
{
title: "Track 2",
artist: "Test 2",
albumArtUrl: "https://picsum.photos/200/300/?random",
audioUrl:
"https://freemusicarchive.org/music/download/bccecf494865a85a1878b619249732eff8c69a4d"
}
];
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
tracks: [],
isLoggedIn: false,
loginUrl: "",
userId: "",
token: ""
};
}
componentDidMount() {
console.log("Fetching login");
fetch("http://my-drive-player.herokuapp.com/auth")
.then(response => response.text())
.then(responseJson => {
this.setState({ loginUrl: responseJson });
})
.catch(error => {
console.error(error);
});
}
fetchList(userId, token) {
console.log("Fetching list of tracks");
console.log(userId);
console.log(token);
fetch(
"http://my-drive-player.herokuapp.com/list?userId=" +
userId +
"&token=" +
token
)
.then(response => response.json())
.then(responseJson => {
this.setState({ tracks: responseJson, isLoggedIn: true });
})
.catch(error => {
console.error(error);
});
}
getLoginScreen() {
console.log("rendering login screen");
return (
<Login
onLoginCompletion={this.fetchList.bind(this)}
loginUrl={this.state.loginUrl}
/>
);
}
getPlayer() {
console.log("rendering player");
return <Player tracks={this.state.tracks} />;
}
render() {
return this.state.isLoggedIn ? this.getPlayer() : this.getLoginScreen();
}
}