From 7c055bd9d10609127c07983d43c076bcadfc734a Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 2 Jun 2017 13:50:42 +0200 Subject: [PATCH] Created a function for deciding what to return based on the object it computes. --- client/app/components/FetchData.js | 39 +++++++++++++++++------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/client/app/components/FetchData.js b/client/app/components/FetchData.js index 8d6f224..9374075 100644 --- a/client/app/components/FetchData.js +++ b/client/app/components/FetchData.js @@ -4,7 +4,7 @@ class FetchData extends React.Component { constructor(props){ super(props) this.state = { - imgUrls: [], + playing: [], hei: '1', intervalId: null, url: '' @@ -16,11 +16,9 @@ class FetchData extends React.Component { fetch("https://apollo.kevinmidboe.com/api/v1/plex/playing").then( function(response){ response.json().then(function(data){ - console.log(data.size); 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() { - console.log('Should not reach') - // Need callback to work - // Should try to clear out old requests to limit mem use + if (this.state.playing.length != 0) { + return this.state.playing.map((playingObj) => { + if (playingObj.type === 'episode') { + console.log('episode') + return ([ + {playingObj.title}, + {playingObj.season}, + {playingObj.episode} + ]) + } else if (playingObj.type === 'movie') { + console.log('movie') + return ([ + {playingObj.title} + ]) + } + }) + } else { + return (Nothing playing) + } } render(){ return( -
- {this.state.imgUrls.map((imgObj) => { - return ([ - {imgObj.title}, - {imgObj.season}, - {imgObj.episode}, - ]); - })} - -
+
{this.getPlaying()}
); }