import { h, Component } from 'preact'; export default class AuthPanel extends Component { constructor(props) { super(props); this.toggleUserId = this.toggleUserId.bind(this); this.toggleBlockedVisibility = this.toggleBlockedVisibility.bind(this); } toggleUserId() { this.setState({ isUserIdVisible: !this.state.isUserIdVisible }); } toggleBlockedVisibility() { if (!this.state.isBlockedVisible) { if (this.props.onBlockedUsersShow) this.props.onBlockedUsersShow(); } else { if (this.props.onBlockedUsersHide) this.props.onBlockedUsersHide(); } this.setState({ isBlockedVisible: !this.state.isBlockedVisible }); } render(props, { isUserIdVisible, isBlockedVisible }) { const { user, providers = [] } = props; return (
{ !!user.name && (
You signed in as {' '} {user.name} {isUserIdVisible && ({user.id})}. {' '} Sign out?
) } { !user.name && (
Sign in to comment using {' '} { providers.map((provider, i) => { const comma = i === 0 ? '' : ', '; return ( {comma} props.onSignIn(provider)} >{provider} ) }) } {'.'}
) } { user.admin && (
{isBlockedVisible ? 'hide' : 'show'} blocked
) }
); } }