import React from 'react'; import { withRouter, Link } from 'react-router-dom'; import { connect } from 'react-redux'; import queryString from 'query-string'; //actions import { storeProfile, clearProfile } from '../../actions/profile.js'; //panels import CommonLinks from '../panels/common_links.jsx'; import AttackButton from '../panels/attack_button.jsx'; import Markdown from '../panels/markdown.jsx'; class Profile extends React.Component { constructor(props) { super(props); this.state = { params: queryString.parse(props.location.search), warning: '', //TODO: unified warning? }; this.sendRequest('/profilerequest', {username: this.state.params.username ? this.state.params.username : this.props.account.username}); } componentWillUnmount() { this.props.clearProfile(); } render() { let warningStyle = { display: this.state.warning.length > 0 ? 'flex' : 'none' }; //side panel stuff let SidePanel; if (this.props.account.id) { if (this.props.account.username === this.props.profile.username) { SidePanel = this.MyProfileSidePanel.bind(this); } else { SidePanel = this.NotMyProfileSidePanel.bind(this); } } else { //logged out SidePanel = this.LoggedOutSidePanel.bind(this); } //main panel let MainPanel; if (this.props.account.id) { //logged in if (this.props.account.username === this.props.profile.username) { MainPanel = this.MyProfileMainPanel.bind(this); } else { if (this.props.profile.username) { MainPanel = this.NotMyProfileMainPanel.bind(this); } else { MainPanel = this.ProfileNotFoundMainPanel.bind(this); } } } else { //not logged in if (this.props.profile.username) { MainPanel = this.LoggedOutMainPanel.bind(this); } else { MainPanel = this.ProfileNotFoundMainPanel.bind(this); } } //finally return (
{this.state.warning}
Username:
{this.props.profile.username}
Gold:
{this.props.profile.gold}
(+1 gold for each recruit every half hour)
Recruits:
{this.props.profile.recruits}
Soldiers:
{this.props.profile.soldiers}
Scientists:
{this.props.profile.scientists}
Spies:
{this.props.profile.spies}
Username:
{this.props.profile.username}
Gold:
{this.props.profile.gold}
Recruits:
{this.props.profile.recruits}
Soldiers:
{this.props.profile.soldiers}
Scientists:
{this.props.profile.scientists}
Spies:
{this.props.profile.spies}
Username:
{this.props.profile.username}
Gold:
{this.props.profile.gold}
Recruits:
{this.props.profile.recruits}
Soldiers:
{this.props.profile.soldiers}
Scientists:
{this.props.profile.scientists}
Spies:
{this.props.profile.spies}
Profile Not Found!