Last active
January 9, 2016 18:51
-
-
Save nramirez/f87ecc007a73502e7a4a to your computer and use it in GitHub Desktop.
Wedding playlist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = []; | |
var playlist = React.createClass({ | |
getInitialState: function(){ | |
return { lastSong: 0 } | |
}, | |
componentDidMount: function() { | |
setInterval(this.loadSongs, 5000); | |
}, | |
loadSongs: function() { | |
var lastId = this.state.lastSong; | |
$.get('/api/loadSongs/' + lastId, function(response){ | |
if (response.data.length > 0) { | |
data = data.concat(response.data); | |
this.setState({ | |
lastSong: data[data.length-1] | |
}); | |
}; | |
}); | |
}, | |
render: function(){ | |
var createRow = function(row){ | |
return ( | |
<tr> | |
<td>row.name</td> | |
<td>row.artist</td> | |
<td>row.gender</td> | |
</tr> | |
); | |
} | |
var empty = ( | |
<tr> | |
<td colspan="3"> No hay entradas nuevas</td> | |
</tr> | |
); | |
return ( | |
<table> | |
<thead> | |
<tr> | |
<th>Artist</th> | |
<th>Song</th> | |
<th>Gender</th> | |
</tr> | |
</thead> | |
<tbody> | |
{data.length == 0 ? | |
empty : | |
data.map(createRow) } | |
</tbody> | |
</table> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment