Allowed ladder URL to point to specific rank

This commit is contained in:
2019-05-30 04:00:13 +10:00
parent 873c7d241f
commit bb60fd271b
4 changed files with 38 additions and 13 deletions
+6
View File
@@ -0,0 +1,6 @@
{
"env": {
"REACT_APP_GA_TRACKING_ID": "",
"REACT_APP_GA_DEBUG": true
}
}
+1
View File
@@ -6,6 +6,7 @@ So changes I'm making today:
* Both incoming and outgoing combats are now visible. * Both incoming and outgoing combats are now visible.
* Google analytics implemented. * Google analytics implemented.
* The game ladder can now point to a specific rank with the URL: [https://kingdombattles.net/ladder?rank=0](ladder?rank=0)
Known Bugs: Known Bugs:
+31 -11
View File
@@ -1,4 +1,6 @@
import React from 'react'; import React from 'react';
import queryString from 'query-string';
import { withRouter } from 'react-router-dom';
import CommonLinks from '../panels/common_links.jsx'; import CommonLinks from '../panels/common_links.jsx';
import PagedLadder from '../panels/paged_ladder.jsx'; import PagedLadder from '../panels/paged_ladder.jsx';
@@ -6,15 +8,21 @@ import PagedLadder from '../panels/paged_ladder.jsx';
class Ladder extends React.Component { class Ladder extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
let params = queryString.parse(props.location.search);
this.state = { this.state = {
start: 0, params: params,
start: parseInt(params.rank) || 0,
length: 50, length: 50,
fetch: null fetch: null
}; };
} }
componentDidUpdate() { componentDidUpdate(prevProps, prevState, snapshot) {
this.state.fetch(); if (JSON.stringify(this.state) !== JSON.stringify(prevState)) {
this.state.fetch();
}
} }
render() { render() {
@@ -52,15 +60,20 @@ class Ladder extends React.Component {
} }
increment() { increment() {
this.setState({ let start = this.state.start + this.state.length;
start: this.state.start + this.state.length
}); this.props.history.push(`${this.props.location.pathname}?rank=${start}`);
} }
decrement() { decrement() {
this.setState({ let start = Math.max(0, this.state.start - this.state.length);
start: Math.max(0, this.state.start - this.state.length)
}); //don't decrement too far
if (start === this.state.start) {
return;
}
this.props.history.push(`${this.props.location.pathname}?rank=${start}`);
} }
//bound callbacks //bound callbacks
@@ -70,9 +83,16 @@ class Ladder extends React.Component {
onReceived(data) { onReceived(data) {
if (data.length === 0) { if (data.length === 0) {
this.decrement(); let start = Math.max(0, this.state.start - this.state.length);
//don't decrement too far
if (start === this.state.start) {
return;
}
this.props.history.replace(`${this.props.location.pathname}?rank=${start}`);
} }
} }
} }
export default Ladder; export default withRouter(Ladder);
-2
View File
@@ -12,8 +12,6 @@ class PagedLadder extends React.Component {
if (props.getFetch) { if (props.getFetch) {
props.getFetch(this.fetchLadder.bind(this)); props.getFetch(this.fetchLadder.bind(this));
} }
this.fetchLadder();
} }
render() { render() {