import { h, Component } from 'preact'; import { FormattedMessage, IntlShape, useIntl } from 'react-intl'; import b from 'bem-react-helper'; import clsx from 'clsx'; import { User, Theme, PostInfo } from 'common/types'; import { IS_STORAGE_AVAILABLE, IS_THIRD_PARTY } from 'common/constants'; import { postMessageToParent } from 'utils/post-message'; import { getHandleClickProps } from 'common/accessibility'; import { StoreState } from 'store'; import { useTheme } from 'hooks/useTheme'; import { Button } from 'components/button'; import { Auth } from 'components/auth'; import { Avatar } from 'components/avatar'; import { SignOutIcon } from 'components/icons/signout'; import { IconButton } from 'components/icon-button/icon-button'; import { messages } from 'components/auth/auth.messsages'; import styles from './auth-panel.module.css'; interface OwnProps { user: User | null; hiddenUsers: StoreState['hiddenUsers']; isCommentsDisabled: boolean; postInfo: PostInfo; signout(): Promise; onCommentsChangeReadOnlyMode(readOnly: boolean): Promise; onBlockedUsersShow(): void; onBlockedUsersHide(): void; } export interface Props extends OwnProps { intl: IntlShape; theme: Theme; } interface State { isBlockedVisible: boolean; anonymousUsernameInputValue: string; } class AuthPanelComponent extends Component { state = { isBlockedVisible: false, anonymousUsernameInputValue: 'anon', }; 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 = () => { this.props.onCommentsChangeReadOnlyMode(!this.props.isCommentsDisabled); }; renderAuthorized = (user: User) => { return (
{' '}
); }; renderThirdPartyWarning = () => { if (IS_STORAGE_AVAILABLE || !IS_THIRD_PARTY) return null; return (
{' '}
); }; renderCookiesWarning = () => { if (IS_STORAGE_AVAILABLE || IS_THIRD_PARTY) { return null; } return (
); }; renderSettingsLabel = () => { return ( ); }; renderReadOnlySwitch = () => { const { isCommentsDisabled } = this.props; return ( ); }; render({ user, postInfo, theme }: Props, { isBlockedVisible }: State) { const { read_only } = postInfo; const isAdmin = user && user.admin; const isSettingsLabelVisible = Object.keys(this.props.hiddenUsers).length > 0 || isAdmin || isBlockedVisible; return (
{user ? this.renderAuthorized(user) : read_only && }
{this.renderThirdPartyWarning()} {this.renderCookiesWarning()}
{isSettingsLabelVisible && this.renderSettingsLabel()} {isSettingsLabelVisible && ' • '} {isAdmin && this.renderReadOnlySwitch()} {isAdmin && read_only && ' • '} {!isAdmin && read_only && ( )}
); } } export function AuthPanel(props: OwnProps) { const intl = useIntl(); const theme = useTheme(); return ; }