import React, { ComponentType, MouseEventHandler, useCallback, useState } from 'react'; import clsx from 'clsx'; import { PseudoAvatar } from 'app/components/ui'; import { ComponentLoader } from 'app/components/ui/loader'; import { Account } from 'app/components/accounts/reducer'; import styles from './accountSwitcher.scss'; interface Props { accounts: ReadonlyArray; onAccountClick?: (account: Account) => Promise; } const AccountSwitcher: ComponentType = ({ accounts, onAccountClick }) => { const [selectedAccount, setSelectedAccount] = useState(); const onAccountClickCallback = useCallback( (account: Account): MouseEventHandler => async (event) => { event.stopPropagation(); setSelectedAccount(account.id); try { if (onAccountClick) { await onAccountClick(account); } } finally { setSelectedAccount(undefined); } }, [onAccountClick], ); return (
{accounts.map((account, index) => (
{account.username}
{account.email}
{selectedAccount === account.id ? ( ) : (
)}
))}
); }; export default AccountSwitcher;