import React from 'react'; import { Contact, MemberList } from './MemberList'; interface Props { modList: Array; chatName: string; onSubmit: any; onClose: any; } declare global { interface Window { i18n: any; } } interface State { modList: Array; } export class RemoveModeratorsDialog extends React.Component { constructor(props: any) { super(props); this.onModClicked = this.onModClicked.bind(this); this.closeDialog = this.closeDialog.bind(this); this.onClickOK = this.onClickOK.bind(this); this.onKeyUp = this.onKeyUp.bind(this); let mods = this.props.modList; mods = mods.map(d => { let name = ''; if (d.getLokiProfile) { const lokiProfile = d.getLokiProfile(); name = lokiProfile ? lokiProfile.displayName : 'Anonymous'; } const authorColor = d.getColor ? d.getColor() : '#000000'; // TODO: should take existing members into account const existingMember = false; return { id: d.id, authorPhoneNumber: d.id, authorProfileName: name, selected: false, authorName: name, authorColor, checkmarked: true, existingMember, }; }); this.state = { modList: mods, }; window.addEventListener('keyup', this.onKeyUp); } public render() { const i18n = window.i18n; const hasMods = this.state.modList.length !== 0; return (

{i18n('removeModerators')} {this.props.chatName}

Existing moderators:

{hasMods ? null : (

{i18n('noModeratorsToRemove')}

)}
); } private onClickOK() { const removedMods = this.state.modList .filter(d => !d.checkmarked) .map(d => d.id); if (removedMods.length > 0) { this.props.onSubmit(removedMods); } this.closeDialog(); } private onKeyUp(event: any) { switch (event.key) { case 'Enter': this.onClickOK(); break; case 'Esc': case 'Escape': this.closeDialog(); break; default: } } private closeDialog() { window.removeEventListener('keyup', this.onKeyUp); this.props.onClose(); } private onModClicked(selected: any) { const updatedFriends = this.state.modList.map(member => { if (member.id === selected.id) { return { ...member, checkmarked: !member.checkmarked }; } else { return member; } }); this.setState(state => { return { ...state, modList: updatedFriends, }; }); } }