Wrote a badge list page

This commit is contained in:
2019-06-08 17:10:33 +10:00
parent 9a42ef54f3
commit 562fae3871
12 changed files with 152 additions and 16 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ class Badge extends React.Component {
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} />
<img {...this.props} src={`/img/badges/${this.props.filename}`} alt={this.props.name} width={realSize} height={realSize} style={{ minWidth: realSize, minHeight: realSize }} />
);
}
+81
View File
@@ -0,0 +1,81 @@
import React from 'react';
import PropTypes from 'prop-types';
import Badge from './badge.jsx';
class BadgeList extends React.Component {
constructor(props) {
super(props);
this.state = {
data: {}
};
if (props.getFetch) {
props.getFetch(() => this.sendRequest('/badgeslistrequest'));
}
}
render() {
if (!this.state.data.statistics) {
return (
<p className='panel'>Loading badges...</p>
);
}
return (
<div className='panel table'>
{Object.keys(this.state.data.statistics).map((name) =>
<div key={name}>
<div className={'panel row'} style={{padding: 10}}>
<div className={'col centered'} style={{ minWidth: 110 }}>
<Badge name={name} filename={this.state.data.statistics[name].filename} />
</div>
<div className={'col'} style={{flex: 4, display: 'flex', flexDirection: 'column', justifyContent: 'center'}}>
<h2>{name}</h2>
<p>{this.state.data.statistics[name].description}</p>
<p>Unlockable: {this.state.data.statistics[name].unlockable ? <span style={{color: 'lightgreen'}}>Yes</span> : this.state.data.statistics[name].unlockable === null ? <span style={{color: 'yellow'}}>Coding Incomplete</span> : <span style={{color: 'red'}}>No</span>}</p>
</div>
</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({
...args
}));
}
};
BadgeList.propTypes = {
setWarning: PropTypes.func,
getFetch: PropTypes.func
};
export default BadgeList;
+1 -1
View File
@@ -50,7 +50,7 @@ class BadgeSelect extends React.Component {
<hr className='col mobile show' />
</div>
</div>
)}
).reverse()}
</div>
);
}
+2 -2
View File
@@ -22,9 +22,9 @@ class BadgeText extends React.Component {
let style = this.props.centered ? centerStyle : leftStyle;
return (
<div {...this.props} style={{...style, paddingBottom: '0.5em'}}>
<div className={this.props.className} style={{...style, paddingBottom: '0.5em'}}>
<Badge name={this.props.name} filename={this.props.filename} size={this.props.size} />
<p style={{paddingBottom: 0}}>{this.props.children}</p>
<p style={{paddingBottom: 0, ...this.props.style}}>{this.props.children}</p>
</div>
);
}