/*** @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 (