mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-12 15:01:38 +03:00
contacts-js: handle remove of contact correctly
the remove functionality in contact-card.js incorrectly assumed that we are always removing ourselves from the group. Fixes #2816
This commit is contained in:
parent
3196179fbd
commit
774f7f53f0
@ -17,6 +17,7 @@ class UrbitApi {
|
||||
this.contactView = {
|
||||
create: this.contactCreate.bind(this),
|
||||
delete: this.contactDelete.bind(this),
|
||||
remove: this.contactRemove.bind(this),
|
||||
share: this.contactShare.bind(this)
|
||||
};
|
||||
|
||||
@ -103,6 +104,10 @@ class UrbitApi {
|
||||
return this.contactViewAction({ delete: { path }});
|
||||
}
|
||||
|
||||
contactRemove(path, ship) {
|
||||
return this.contactViewAction({ remove: { path, ship } });
|
||||
}
|
||||
|
||||
contactHookAction(data) {
|
||||
return this.action("contact-hook", "contact-action", data);
|
||||
}
|
||||
|
@ -32,7 +32,8 @@ export class ContactCard extends Component {
|
||||
this.notesToSet = this.notesToSet.bind(this);
|
||||
this.setField = this.setField.bind(this);
|
||||
this.shareWithGroup = this.shareWithGroup.bind(this);
|
||||
this.removeFromGroup = this.removeFromGroup.bind(this);
|
||||
this.removeSelfFromGroup = this.removeSelfFromGroup.bind(this);
|
||||
this.removeOtherFromGroup = this.removeOtherFromGroup.bind(this);
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
@ -335,7 +336,7 @@ export class ContactCard extends Component {
|
||||
}));
|
||||
}
|
||||
|
||||
removeFromGroup() {
|
||||
removeSelfFromGroup() {
|
||||
const { props } = this;
|
||||
// share empty contact so that we can remove ourselves from group
|
||||
// if we haven't shared yet
|
||||
@ -355,10 +356,19 @@ export class ContactCard extends Component {
|
||||
|
||||
this.setState({ awaiting: true, type: 'Removing from group' }, (() => {
|
||||
api.contactView.delete(props.path).then(() => {
|
||||
const destination = (props.ship === window.ship)
|
||||
? '' : props.path;
|
||||
this.setState({ awaiting: false });
|
||||
props.history.push(`/~groups${destination}`);
|
||||
props.history.push(`/~groups`);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
removeOtherFromGroup() {
|
||||
const { props } = this;
|
||||
|
||||
this.setState({ awaiting: true, type: 'Removing from group' }, (() => {
|
||||
api.contactView.remove(props.path, `~${props.ship}`).then(() => {
|
||||
this.setState({ awaiting: false });
|
||||
props.history.push(`/~groups${props.path}`);
|
||||
});
|
||||
}));
|
||||
}
|
||||
@ -638,7 +648,7 @@ export class ContactCard extends Component {
|
||||
className={
|
||||
'bg-gray0-d mv4 mh3 pa1 f9 red2 pointer flex-shrink-0 ' + adminOpt
|
||||
}
|
||||
onClick={this.removeFromGroup}
|
||||
onClick={props.ship === window.ship ? this.removeSelfFromGroup : this.removeOtherFromGroup}
|
||||
>
|
||||
{props.ship === window.ship
|
||||
? 'Leave Group'
|
||||
|
Loading…
Reference in New Issue
Block a user