diff --git a/ts/components/session/LeftPaneContactSection.tsx b/ts/components/session/LeftPaneContactSection.tsx index 8ff7e85fc..b605fac98 100644 --- a/ts/components/session/LeftPaneContactSection.tsx +++ b/ts/components/session/LeftPaneContactSection.tsx @@ -40,7 +40,6 @@ export interface Props { interface State { showAddContactView: boolean; - selectedTab: number; addContactRecipientID: string; pubKeyPasted: string; } @@ -52,27 +51,23 @@ export class LeftPaneContactSection extends React.Component { super(props); this.state = { showAddContactView: false, - selectedTab: 0, addContactRecipientID: '', pubKeyPasted: '', }; this.debouncedSearch = debounce(this.search.bind(this), 20); - this.handleTabSelected = this.handleTabSelected.bind(this); this.handleToggleOverlay = this.handleToggleOverlay.bind(this); this.handleOnAddContact = this.handleOnAddContact.bind(this); this.handleRecipientSessionIDChanged = this.handleRecipientSessionIDChanged.bind( this ); + this.closeOverlay = this.closeOverlay.bind(this); } public componentWillUnmount() { this.updateSearch(''); this.setState({ addContactRecipientID: '' }); - } - - public handleTabSelected(tabType: number) { - this.setState({ selectedTab: tabType, showAddContactView: false }); + window.Whisper.events.off('calculatingPoW', this.closeOverlay); } public renderHeader(): JSX.Element | undefined { @@ -80,7 +75,7 @@ export class LeftPaneContactSection extends React.Component { return LeftPane.RENDER_HEADER( labels, - this.handleTabSelected, + null, undefined, undefined, undefined, @@ -90,6 +85,8 @@ export class LeftPaneContactSection extends React.Component { public componentDidMount() { MainViewController.renderMessageView(); + + window.Whisper.events.on('calculatingPoW', this.closeOverlay); } public componentDidUpdate() { @@ -182,6 +179,12 @@ export class LeftPaneContactSection extends React.Component { ); } + private closeOverlay({ pubKey }: { pubKey: string }) { + if (this.state.addContactRecipientID === pubKey) { + this.setState({ showAddContactView: false, addContactRecipientID: '' }); + } + } + private handleToggleOverlay() { this.setState((prevState: { showAddContactView: boolean }) => ({ showAddContactView: !prevState.showAddContactView, @@ -217,7 +220,6 @@ export class LeftPaneContactSection extends React.Component { } private renderBottomButtons(): JSX.Element { - const { selectedTab } = this.state; const addContact = window.i18n('addContact'); return ( diff --git a/ts/components/session/LeftPaneMessageSection.tsx b/ts/components/session/LeftPaneMessageSection.tsx index 0e1c1f746..7685e92dc 100644 --- a/ts/components/session/LeftPaneMessageSection.tsx +++ b/ts/components/session/LeftPaneMessageSection.tsx @@ -93,10 +93,12 @@ export class LeftPaneMessageSection extends React.Component { this.renderClosableOverlay = this.renderClosableOverlay.bind(this); this.debouncedSearch = debounce(this.search.bind(this), 20); + this.closeOverlay = this.closeOverlay.bind(this); } public componentWillUnmount() { this.updateSearch(''); + window.Whisper.events.off('calculatingPoW', this.closeOverlay); } public renderRow = ({ @@ -178,12 +180,19 @@ export class LeftPaneMessageSection extends React.Component { public componentDidMount() { MainViewController.renderMessageView(); + window.Whisper.events.on('calculatingPoW', this.closeOverlay); } public componentDidUpdate() { MainViewController.renderMessageView(); } + public closeOverlay({ pubKey }: { pubKey: string }) { + if (this.state.valuePasted === pubKey) { + this.setState({ overlay: false, valuePasted: '' }); + } + } + public renderHeader(): JSX.Element { const labels = [window.i18n('messagesHeader')];