/*** @jsx React.DOM */ var valid_versions = Object.keys(window.versions); var pagenav = new History(valid_versions); var profile_view = React.createClass({ getInitialState: function(props) { var profiles = Object.keys(window.player); return { player: window.player, profiles: profiles, sp_rival: window.sp_rival, dp_rival: window.dp_rival, version: pagenav.getInitialState(profiles[profiles.length - 1]), updating_rivals: false, }; }, componentDidMount: function() { pagenav.onChange(function(version) { this.setState({version: version}); }.bind(this)); this.refreshProfile(); }, refreshProfile: function(skip_timeout) { AJAX.get( Link.get('refresh'), function(response) { var profiles = Object.keys(response.player); this.setState({ player: response.player, profiles: profiles, sp_rival: response.sp_rival, dp_rival: response.dp_rival, updating_rivals: false, }); if (skip_timeout) { // Don't refresh, we were called from rival code } else { // Refresh every 5 seconds to show live rival updating setTimeout(this.refreshProfile, 5000); } }.bind(this) ); }, addRival: function(event, type) { this.setState({updating_rivals: true}); AJAX.post( Link.get('addrival'), { version: this.state.version, type: type, userid: window.playerid, }, function(response) { this.refreshProfile(true); }.bind(this) ); event.preventDefault(); }, removeRival: function(event, type, userid) { this.setState({updating_rivals: true}); AJAX.post( Link.get('removerival'), { version: this.state.version, type: type, userid: window.playerid, }, function(response) { this.refreshProfile(true); }.bind(this) ); event.preventDefault(); }, render: function() { if (this.state.player[this.state.version]) { var player = this.state.player[this.state.version]; return (

dj {player.name}'s profile

{this.state.profiles.map(function(version) { return (
{player.extid}
{player.sdan}
{player.sdjp} DJ POINT
{player.sp}回
{player.ddan}
{player.ddjp} DJ POINT
{player.dp}回
{ window.own_profile ? view your records : view dj {player.name}'s records } · { window.own_profile ? view all your scores : view all dj {player.name}'s scores }
{ window.own_profile ? null :
{ player.sp_rival ? : } { player.dp_rival ? : } { this.state.updating_rivals ? : null }
}
); } else { return (
{this.state.profiles.map(function(version) { return (
This player has no profile for {window.versions[this.state.version]}!
); } }, }); ReactDOM.render( React.createElement(profile_view, null), document.getElementById('content') );