/** @jsx h */ import { h, Component } from 'preact'; import Dropdown, { DropdownItem } from 'components/dropdown'; import Button from 'components/button'; import { PROVIDER_NAMES, IS_STORAGE_AVAILABLE, IS_THIRD_PARTY } from 'common/constants'; import { requestDeletion } from 'utils/email'; import { getHandleClickProps } from 'common/accessibility'; import UserId from './__user-id'; export default class AuthPanel extends Component { constructor(props) { super(props); this.toggleBlockedVisibility = this.toggleBlockedVisibility.bind(this); this.toggleCommentsAvailability = this.toggleCommentsAvailability.bind(this); this.onSortChange = this.onSortChange.bind(this); } onSortChange(e) { if (this.props.onSortChange) { this.props.onSortChange(e.target.value); } } 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 }); } toggleCommentsAvailability() { if (this.props.isCommentsDisabled) { if (this.props.onCommentsEnable) { this.props.onCommentsEnable(); } } else { if (this.props.onCommentsDisable) { this.props.onCommentsDisable(); } } } getUserTitle() { const { user } = this.props; return {user.name}; } render(props, { isBlockedVisible }) { const { user, providers = [], sort, isCommentsDisabled } = props; const sortArray = getSortArray(sort); let loggedIn = !!user.id; return (
{loggedIn && (
You signed in as{' '} {' '}
)} {IS_STORAGE_AVAILABLE && !loggedIn && (
Sign in to comment using{' '} {providers.map((provider, i) => { const comma = i === 0 ? '' : i === providers.length - 1 ? ' or ' : ', '; return ( {comma} props.onSignIn(provider))} role="link" > {PROVIDER_NAMES[provider]} ); })} {'.'}
)} {!IS_STORAGE_AVAILABLE && IS_THIRD_PARTY && (
Disable third-party cookies blocking to sign in or open comments in{' '} new page
)} {!IS_STORAGE_AVAILABLE && !IS_THIRD_PARTY && (
Allow cookies to sign in and comment
)}
{user.admin && ( {isBlockedVisible ? 'Hide' : 'Show'} blocked users )} {user.admin && ' • '} {user.admin && ( {isCommentsDisabled ? 'Enable' : 'Disable'} comments )} {user.admin && ' • '} Sort by{' '} {sortArray.find(x => x.selected).label}
); } } function getSortArray(currentSort) { const sortArray = [ { value: '-score', label: 'Best', }, { value: '+score', label: 'Worst', }, { value: '-time', label: 'Newest', }, { value: '+time', label: 'Oldest', }, { value: '-active', label: 'Recently updated', }, { value: '+active', label: 'Least recently updated', }, { value: '-controversy', label: 'Most controversial', }, { value: '+controversy', label: 'Least controversial', }, ]; return sortArray.map(sort => { if (sort.value === currentSort) { sort.selected = true; } return sort; }); }