Added badge selection

This commit is contained in:
2019-06-08 10:20:10 +10:00
parent d8a7dd4933
commit 2a27572562
21 changed files with 396 additions and 15 deletions
+1
View File
@@ -71,6 +71,7 @@ export default class App extends React.Component {
<LazyRoute path='/ladder' component={() => import('./pages/ladder.jsx')} />
<LazyRoute path='/combatlog' component={() => import('./pages/combat_log.jsx')} />
<LazyRoute path='/spyinglog' component={() => import('./pages/spying_log.jsx')} />
<LazyRoute path='/badges' component={() => import('./pages/badge_select.jsx')} />
<LazyRoute path='/tasklist' component={() => import('./pages/task_list.jsx')} />
<LazyRoute path='/patronlist' component={() => import('./pages/patron_list.jsx')} />
+51
View File
@@ -0,0 +1,51 @@
import React from 'react';
//panels
import CommonLinks from '../panels/common_links.jsx';
import BadgeSelectPanel from '../panels/badge_select.jsx';
class BadgeSelect extends React.Component {
constructor(props) {
super(props);
this.state = {
warning: '', //TODO: unified warning?
fetch: null
};
}
componentDidUpdate(prevProps, prevState, snapshot) {
this.state.fetch();
}
render() {
let warningStyle = {
display: this.state.warning.length > 0 ? 'flex' : 'none'
};
return (
<div className='page'>
<div className='sidePanelPage'>
<div className='sidePanel'>
<CommonLinks />
</div>
<div className='mainPanel'>
<div className='warning' style={warningStyle}>
<p>{this.state.warning}</p>
</div>
<h1 className='centered'>Badge Select</h1>
<p className='centered'>Click on your favourite badge!</p>
<BadgeSelectPanel setWarning={this.setWarning.bind(this)} getFetch={ (fn) => this.setState({ fetch: fn }) } />
</div>
</div>
</div>
);
}
setWarning(s) {
this.setState({ warning: s });
}
};
export default BadgeSelect;
+27
View File
@@ -0,0 +1,27 @@
import React from 'react';
class Badge extends React.Component {
constructor(props) {
super(props);
this.state = {
//
};
}
render() {
let realSize = typeof(this.props.size) === 'number' ? this.props.number : this.parseSize(this.props.size);
return (
<img {...this.props} src={`/img/badges/${this.props.filename}`} alt={this.props.name} width={realSize} height={realSize} />
);
}
parseSize(sizeString) {
if (sizeString === 'small') return 12;
if (sizeString === 'medium') return 20;
return 100;
}
};
export default Badge;
+110
View File
@@ -0,0 +1,110 @@
import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import Badge from './badge.jsx';
class BadgeSelect extends React.Component {
constructor(props) {
super(props);
this.state = {
data: {}
};
if (props.getFetch) {
props.getFetch(() => this.sendRequest('/badgesownedrequest'));
}
}
render() {
if (!this.state.data.owned) {
return (
<p className='panel'>Loading badges...</p>
);
}
//are none selected?
let anySelected = Object.keys(this.state.data.owned).reduce((accumulator, name) => accumulator || this.state.data.owned[name].active, false);
return (
<div className='panel table'>
<div key={name}>
<div className={`panel row${!anySelected ? ' highlight' : ''}`} style={{padding: 10, minHeight: 120}} onClick={ () => this.sendRequest('/badgeselectactiverequest', { name: null }) }>
<p className={'col centered'} style={{alignSelf: 'center'}}>No Badge</p>
</div>
<div className='row'>
<hr className='col mobile show' />
</div>
</div>
{Object.keys(this.state.data.owned).map((name) =>
<div key={name}>
<div className={`panel row${this.state.data.owned[name].active ? ' highlight' : ''}`} style={{padding: 10}} onClick={ () => this.sendRequest('/badgeselectactiverequest', { name: name }) }>
<div className={'col centered'} style={{ minWidth: 110 }}>
<Badge name={name} filename={this.state.data.statistics[name].filename} />
</div>
<p className={'col'} style={{flex: 4, alignSelf: 'center'}}>{this.state.data.statistics[name].description}</p>
</div>
<div className='row'>
<hr className='col mobile show' />
</div>
</div>
)}
</div>
);
}
//gameplay functions
sendRequest(url, args = {}) { //send a unified request, using my credentials
//build the XHR
let xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
let json = JSON.parse(xhr.responseText);
//on success
this.setState({ data: Object.assign({}, this.state.data, json) });
}
else if (xhr.status === 400 && this.props.setWarning) {
this.props.setWarning(xhr.responseText);
}
}
};
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.send(JSON.stringify({
id: this.props.id,
token: this.props.token,
...args
}));
}
};
BadgeSelect.propTypes = {
id: PropTypes.number.isRequired,
token: PropTypes.number.isRequired,
setWarning: PropTypes.func,
getFetch: PropTypes.func
};
const mapStoreToProps = (store) => {
return {
id: store.account.id,
token: store.account.token
};
};
const mapDispatchToProps = (dispatch) => {
return {
//
};
};
BadgeSelect = connect(mapStoreToProps, mapDispatchToProps)(BadgeSelect);
export default BadgeSelect;
+1 -1
View File
@@ -13,7 +13,7 @@ class CombatLogRecord extends React.Component {
render() {
return (
<div className='table noCollapse'>
<div className='panel table noCollapse'>
<hr />
<div className='break' />
<div className='row'>
+2
View File
@@ -30,6 +30,7 @@ class CommonLinks extends React.Component {
<div className='panel'>
<p className='mobile centered'><Link to='/profile' onClick={this.props.onClickProfile}>Your Kingdom</Link></p>
<p className='mobile centered'><Link to='/equipment' onClick={this.props.onClickEquipment}>Your Equipment</Link></p>
<p className='mobile centered'><Link to='/badges' onClick={this.props.onClickBadges}>Your Badges</Link></p>
<p className='mobile centered'><Link to='/ladder' onClick={this.props.onClickLadder}>Attack (Game Ladder)</Link></p>
<p className='mobile centered'><Link to='/combatlog' onClick={this.props.onClickCombatLog}>Combat Log</Link></p>
<p className='mobile centered'><Link to='/spyinglog' onClick={this.props.onClickSpyingLog}>Espionage Log</Link></p>
@@ -72,6 +73,7 @@ CommonLinks.propTypes = {
onClickPasswordRecover: PropTypes.func,
onClickProfile: PropTypes.func,
onClickEquipment: PropTypes.func,
onClickBadges: PropTypes.func,
onClickLadder: PropTypes.func,
onClickCombatLog: PropTypes.func,
onClickSpyingLog: PropTypes.func,
+1 -1
View File
@@ -13,7 +13,7 @@ class SpyingLogRecord extends React.Component {
render() {
return (
<div className='table noCollapse'>
<div className='panel table noCollapse'>
<hr />
<div className='break' />
<div className='row'>