/*** @jsx React.DOM */ var valid_versions = Object.keys(window.rivals); var pagenav = new History(valid_versions); var rivals_view = createReactClass({ getInitialState: function(props) { var profiles = Object.keys(window.rivals); var version = pagenav.getInitialState(profiles[profiles.length - 1]); return { rivals: window.rivals, players: window.players, profiles: profiles, version: version, term: "", results: {}, searching: false, offset: 0, limit: 5, }; }, componentDidMount: function() { pagenav.onChange(function(version) { this.setState({version: version, offset: 0}); }.bind(this)); this.refreshRivals(); }, refreshRivals: function() { AJAX.get( Link.get('refresh'), function(response) { this.setState({ rivals: response.rivals, players: response.players, }); setTimeout(this.refreshRivals, 5000); }.bind(this) ); }, searchForPlayers: function(event) { this.setState({searching: true}); AJAX.post( Link.get('search'), { version: this.state.version, term: this.state.term, }, function(response) { this.setState({ results: response.results, searching: false, }); }.bind(this) ); event.preventDefault(); }, addRival: function(event, userid) { AJAX.post( Link.get('addrival'), { version: this.state.version, userid: userid, }, function(response) { this.setState({ rivals: response.rivals, players: response.players, }); }.bind(this) ); event.preventDefault(); }, removeRival: function(event, userid, pos) { AJAX.post( Link.get('removerival'), { version: this.state.version, userid: userid, position: pos, }, function(response) { this.setState({ rivals: response.rivals, players: response.players, }); }.bind(this) ); event.preventDefault(); }, setActiveRival: function(event, userid, pos) { AJAX.post( Link.get('setactiverival'), { version: this.state.version, userid: userid, position: pos, }, function(response) { this.setState({ rivals: response.rivals, players: response.players, }); }.bind(this) ); event.preventDefault(); }, setInactiveRival: function(event, userid, pos) { AJAX.post( Link.get('setinactiverival'), { version: this.state.version, userid: userid, position: pos, }, function(response) { this.setState({ rivals: response.rivals, players: response.players, }); }.bind(this) ); event.preventDefault(); }, addRivals: function(userid) { if (userid == window.userid) { return null; } var avail = (this.state.rivals[this.state.version].length < 10); var current_rivals = this.state.rivals[this.state.version]; for (var i = 0; i < current_rivals.length; i++) { if (current_rivals[i].userid == userid) { avail = false; break; } } return ( <> {avail ? : null } ); }, render: function() { if (this.state.rivals[this.state.version]) { var rivals = []; var active = 0; this.state.rivals[this.state.version].map(function(rival) { rivals[rival.position] = rival; if (rivals[rival.position].active) { active++; } }.bind(this)); var resultlength = 0; Object.keys(this.state.results).map(function(userid) { var player = this.state.results[userid][this.state.version]; if (player) { resultlength++; } }.bind(this)); return (

Rivals

{this.state.profiles.map(function(version) { return (

{ this.state.searching ? : null }
{resultlength > 0 ? { Object.keys(this.state.results).map(function(userid, index) { if (index < this.state.offset || index >= this.state.offset + this.state.limit) { return null; } var player = this.state.results[userid][this.state.version]; if (!player) { return null; } return ( ); }.bind(this)) }
Name DDR ID
{ player.extid } {this.addRivals(userid)}
{ this.state.offset > 0 ? : null } { (this.state.offset + this.state.limit) < resultlength ? = resultlength) { return; } this.setState({offset: page}); }.bind(this)}/> : null }
:
No players match the specified search.
}

Rivals

{[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(function(rivalno) { if (!rivals[rivalno]) { return ( ); } var rival = rivals[rivalno]; var player = this.state.players[rival.userid][this.state.version]; return ( ); }.bind(this))}
Name DDR ID
no rival in this slot
{ rival.active ?
active
: null }
{ player.extid } { rival.active ? : (active < window.max_active_rivals[this.state.version] ? : null ) }
); } else { return (
You have no profile for {window.versions[this.state.version]}!
{this.state.profiles.map(function(version) { return (
); } }, }); ReactDOM.render( React.createElement(rivals_view, null), document.getElementById('content') );