diff --git a/pkg/interface/groups/src/js/api.js b/pkg/interface/groups/src/js/api.js index cd6542224..eeb4bea5b 100644 --- a/pkg/interface/groups/src/js/api.js +++ b/pkg/interface/groups/src/js/api.js @@ -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); } diff --git a/pkg/interface/groups/src/js/components/lib/contact-card.js b/pkg/interface/groups/src/js/components/lib/contact-card.js index 67c9dea2d..3c8ce78b9 100644 --- a/pkg/interface/groups/src/js/components/lib/contact-card.js +++ b/pkg/interface/groups/src/js/components/lib/contact-card.js @@ -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'