Allowed ladder URL to point to specific rank
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"REACT_APP_GA_TRACKING_ID": "",
|
||||||
|
"REACT_APP_GA_DEBUG": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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:
|
||||||
|
|
||||||
|
|||||||
@@ -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,16 +8,22 @@ 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) {
|
||||||
|
if (JSON.stringify(this.state) !== JSON.stringify(prevState)) {
|
||||||
this.state.fetch();
|
this.state.fetch();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let ButtonHeader = this.buttonHeader.bind(this);
|
let ButtonHeader = this.buttonHeader.bind(this);
|
||||||
@@ -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);
|
||||||
@@ -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() {
|
||||||
|
|||||||
Reference in New Issue
Block a user