import {React, Strings} from "modules";
const badge =
;
export default class ServerCard extends React.Component {
constructor(props) {
super(props);
if (!this.props.server.iconUrl) this.props.server.iconUrl = this.props.defaultAvatar();
this.state = {
joined: this.props.joined
};
this.join = this.join.bind(this);
this.handleError = this.handleError.bind(this);
}
render() {
const {server} = this.props;
const addedDate = new Date(server.insertDate * 1000); // Convert from unix timestamp
const buttonText = typeof(this.state.joined) == "string" ? `${Strings.PublicServers.joining}...` : this.state.joined ? Strings.PublicServers.joined : Strings.PublicServers.join;
return
{server.pinned && badge}
{server.name}
{this.state.joined &&
{buttonText}
}
{server.description}
{server.members.toLocaleString()} Members
Added {addedDate.toLocaleDateString()}
;
}
handleError() {
this.props.server.iconUrl = this.props.defaultAvatar();
}
async join() {
if (this.state.joined) return this.props.navigateTo(this.props.server.identifier);
this.setState({joined: "joining"});
const didJoin = await this.props.join(this.props.server.identifier, this.props.server.nativejoin);
this.setState({joined: didJoin});
}
}