Disabled unignore button when unignoring in process
Signed-off-by: Agusti Bau <agustibau@gmail.com>
This commit is contained in:
parent
47708ca127
commit
08bac716d5
1 changed files with 32 additions and 12 deletions
|
@ -31,6 +31,7 @@ export class IgnoredUser extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
userId: PropTypes.string.isRequired,
|
userId: PropTypes.string.isRequired,
|
||||||
onUnignored: PropTypes.func.isRequired,
|
onUnignored: PropTypes.func.isRequired,
|
||||||
|
inProgress: PropTypes.bool.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
_onUnignoreClicked = (e) => {
|
_onUnignoreClicked = (e) => {
|
||||||
|
@ -41,7 +42,7 @@ export class IgnoredUser extends React.Component {
|
||||||
const id = `mx_SecurityUserSettingsTab_ignoredUser_${this.props.userId}`;
|
const id = `mx_SecurityUserSettingsTab_ignoredUser_${this.props.userId}`;
|
||||||
return (
|
return (
|
||||||
<div className='mx_SecurityUserSettingsTab_ignoredUser'>
|
<div className='mx_SecurityUserSettingsTab_ignoredUser'>
|
||||||
<AccessibleButton onClick={this._onUnignoreClicked} kind='primary_sm' aria-describedby={id}>
|
<AccessibleButton onClick={this._onUnignoreClicked} kind='primary_sm' aria-describedby={id} disabled={this.props.inProgress}>
|
||||||
{ _t('Unignore') }
|
{ _t('Unignore') }
|
||||||
</AccessibleButton>
|
</AccessibleButton>
|
||||||
<span id={id}>{ this.props.userId }</span>
|
<span id={id}>{ this.props.userId }</span>
|
||||||
|
@ -59,6 +60,7 @@ export default class SecurityUserSettingsTab extends React.Component {
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
ignoredUserIds: MatrixClientPeg.get().getIgnoredUsers(),
|
ignoredUserIds: MatrixClientPeg.get().getIgnoredUsers(),
|
||||||
|
waitingUnignored: [],
|
||||||
managingInvites: false,
|
managingInvites: false,
|
||||||
invitedRoomAmt: invitedRooms.length,
|
invitedRoomAmt: invitedRooms.length,
|
||||||
};
|
};
|
||||||
|
@ -69,7 +71,13 @@ export default class SecurityUserSettingsTab extends React.Component {
|
||||||
_onAction({action}) {
|
_onAction({action}) {
|
||||||
if (action === "ignore_state_changed"){
|
if (action === "ignore_state_changed"){
|
||||||
const ignoredUserIds = MatrixClientPeg.get().getIgnoredUsers();
|
const ignoredUserIds = MatrixClientPeg.get().getIgnoredUsers();
|
||||||
this.setState({ignoredUserIds})
|
const newWaitingUnignored = this.state.waitingUnignored.filter(e=> ignoredUserIds.includes(e))
|
||||||
|
console.log("-------------")
|
||||||
|
console.log("Got new ignored users", ignoredUserIds)
|
||||||
|
console.log("We were waiting for", this.state.waitingUnignored)
|
||||||
|
console.log("Now we wait for", newWaitingUnignored)
|
||||||
|
console.log("-------------")
|
||||||
|
this.setState({ignoredUserIds, waitingUnignored: newWaitingUnignored})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,14 +112,20 @@ export default class SecurityUserSettingsTab extends React.Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
_onUserUnignored = async (userId) => {
|
_onUserUnignored = async (userId) => {
|
||||||
// Don't use this.state to get the ignored user list as it might be
|
|
||||||
// ever so slightly outdated. Instead, prefer to get a fresh list and
|
const {ignoredUserIds, waitingUnignored} = this.state
|
||||||
// update that.
|
console.log("--------GO IGNORE---")
|
||||||
const ignoredUserIds = this.state.ignoredUserIds;
|
console.log("ignored:", ignoredUserIds)
|
||||||
const index = ignoredUserIds.indexOf(userId);
|
console.log("waiting for:", waitingUnignored)
|
||||||
|
const currentlyIgnoredUserIds = ignoredUserIds.filter(e=> !waitingUnignored.includes(e));
|
||||||
|
console.log("currentlyIgnored:", currentlyIgnoredUserIds)
|
||||||
|
|
||||||
|
const index = currentlyIgnoredUserIds.indexOf(userId);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
ignoredUserIds.splice(index, 1);
|
currentlyIgnoredUserIds.splice(index, 1);
|
||||||
MatrixClientPeg.get().setIgnoredUsers(ignoredUserIds);
|
this.setState(({waitingUnignored})=>({waitingUnignored:[...waitingUnignored, userId]}))
|
||||||
|
console.log("Sending to server", currentlyIgnoredUserIds)
|
||||||
|
MatrixClientPeg.get().setIgnoredUsers(currentlyIgnoredUserIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -219,10 +233,16 @@ export default class SecurityUserSettingsTab extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
_renderIgnoredUsers() {
|
_renderIgnoredUsers() {
|
||||||
if (!this.state.ignoredUserIds || this.state.ignoredUserIds.length === 0) return null;
|
const {waitingUnignored, ignoredUserIds} = this.state;
|
||||||
|
|
||||||
const userIds = this.state.ignoredUserIds
|
if (!ignoredUserIds || ignoredUserIds.length === 0) return null;
|
||||||
.map((u) => <IgnoredUser userId={u} onUnignored={this._onUserUnignored} key={u} />);
|
|
||||||
|
|
||||||
|
console.log("Rendering, waiting", waitingUnignored)
|
||||||
|
console.log("Rendering, ignored", ignoredUserIds)
|
||||||
|
|
||||||
|
const userIds = ignoredUserIds
|
||||||
|
.map((u) => <IgnoredUser userId={u} onUnignored={this._onUserUnignored} key={u} inProgress={waitingUnignored.includes(u)} />);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='mx_SettingsTab_section'>
|
<div className='mx_SettingsTab_section'>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue