// @flow // export default ({ id, icon, ...rest }) => import * as React from 'react' import styled from 'styled-components' export type GuildPicProps = { id: string, icon: string, name: string } export type GuildPicState = { src: ?string, ok: boolean } const Fallback = styled.div` display: flex; justify-content: center; align-items: center; background-color: var(--fallback-color); ` export default class DiscordGuildPic extends React.Component { state = { src: this.src, ok: false } get src () { return `https://cdn.discordapp.com/icons/${this.props.id}/${this.props.icon}.png` } renderFallback () { const { name, id, icon, ...rest } = this.props return {name[0]} } onError = () => { // console.log('onError') this.setState({ src: null }) } onLoad = () => { this.setState({ ok: true }) } renderImg () { const { name, id, icon, ...rest } = this.props return } render () { return (this.state.src === null) ? this.renderFallback() : this.renderImg() } }