Created a function for deciding what to return based on the object it computes.
This commit is contained in:
@@ -4,7 +4,7 @@ class FetchData extends React.Component {
|
|||||||
constructor(props){
|
constructor(props){
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
imgUrls: [],
|
playing: [],
|
||||||
hei: '1',
|
hei: '1',
|
||||||
intervalId: null,
|
intervalId: null,
|
||||||
url: ''
|
url: ''
|
||||||
@@ -16,11 +16,9 @@ class FetchData extends React.Component {
|
|||||||
fetch("https://apollo.kevinmidboe.com/api/v1/plex/playing").then(
|
fetch("https://apollo.kevinmidboe.com/api/v1/plex/playing").then(
|
||||||
function(response){
|
function(response){
|
||||||
response.json().then(function(data){
|
response.json().then(function(data){
|
||||||
console.log(data.size);
|
|
||||||
that.setState({
|
that.setState({
|
||||||
imgUrls: that.state.imgUrls.concat(data.video)
|
playing: that.state.playing.concat(data.video)
|
||||||
})
|
})
|
||||||
console.log(data.video.title);
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -32,23 +30,30 @@ class FetchData extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getPlaying() {
|
getPlaying() {
|
||||||
console.log('Should not reach')
|
if (this.state.playing.length != 0) {
|
||||||
// Need callback to work
|
return this.state.playing.map((playingObj) => {
|
||||||
// Should try to clear out old requests to limit mem use
|
if (playingObj.type === 'episode') {
|
||||||
|
console.log('episode')
|
||||||
|
return ([
|
||||||
|
<span>{playingObj.title}</span>,
|
||||||
|
<span>{playingObj.season}</span>,
|
||||||
|
<span>{playingObj.episode}</span>
|
||||||
|
])
|
||||||
|
} else if (playingObj.type === 'movie') {
|
||||||
|
console.log('movie')
|
||||||
|
return ([
|
||||||
|
<span>{playingObj.title}</span>
|
||||||
|
])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return (<span>Nothing playing</span>)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
return(
|
return(
|
||||||
<div className="FetchData">
|
<div className="FetchData">{this.getPlaying()}</div>
|
||||||
{this.state.imgUrls.map((imgObj) => {
|
|
||||||
return ([
|
|
||||||
<span>{imgObj.title}</span>,
|
|
||||||
<span>{imgObj.season}</span>,
|
|
||||||
<span>{imgObj.episode}</span>,
|
|
||||||
]);
|
|
||||||
})}
|
|
||||||
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user