import { h, Component } from 'preact'; import api from 'common/api' export default class BlockedUsers extends Component { constructor(props) { super(props); this.state = { unblockedUsers: [], } } block(user) { if (confirm('Do you want to block this user?')) { api.blockUser({ id: user.id }).then(() => { this.setState({ unblockedUsers: this.state.unblockedUsers.filter(x => x !== user.id) }); if (this.props.onBlock) this.props.onBlock(user.id); }); } } unblock(user) { if (confirm('Do you want to unblock this user?')) { api.unblockUser({ id: user.id }).then(() => { this.setState({ unblockedUsers: this.state.unblockedUsers.concat([user.id]) }); if (this.props.onUnblock) this.props.onUnblock(user.id); }); } } render(props, { unblockedUsers }) { const { users } = props; return (
{ !users.length && (

There are no blocked users.

) } { !!users.length && (

List of blocked users:

) } { !!users.length && ( ) }
); } }