contacts: working on remove from group behavior

This commit is contained in:
Logan Allen 2020-01-29 10:42:33 -08:00
parent e7035ebc4c
commit 77f702b38c
10 changed files with 83575 additions and 82 deletions

View File

@ -105,34 +105,27 @@
++ poke-contact-action
|= act=contact-action
^- (quip card _state)
~& src+src.bol
~& act+act
|^
:_ state
?+ -.act !!
%edit (process-action path.act ship.act act)
%add (process-action path.act ship.act act)
%edit (handle-contact-action path.act ship.act act)
%add (handle-contact-action path.act ship.act act)
%remove (handle-contact-action path.act ship.act act)
==
::
++ process-action
++ handle-contact-action
|= [=path =ship act=contact-action]
^- (quip card _state)
^- (list card)
:: local
:_ state
?: (team:title our.bol src.bol)
~& 'local'
=/ shp (~(got by synced) path)
=/ shp ?:(=(path /~/default) our.bol (~(got by synced) path))
=/ appl ?:(=(shp our.bol) %contact-store %contact-hook)
~& shp+shp
~& appl+appl
[%pass / %agent [shp appl] %poke %contact-action !>(act)]~
~& 'foreign'
:: foreign
=/ shp (~(got by synced) path)
~& shp+shp
?. |(=(shp our.bol) =(src.bol ship)) ~
:: scry group to check if ship is a member
=/ =group (need (group-scry path))
~& group+group
?. (~(has in group) shp) ~
[%pass / %agent [our.bol %contact-store] %poke %contact-action !>(act)]~
--
@ -230,41 +223,41 @@
|= [wir=wire fact=contact-update]
^- (quip card _state)
|^
:_ state
?: (team:title our.bol src.bol)
~& update-local+fact
(local fact)
~& update-foreign+fact
(foreign fact)
::
++ local
|= fact=contact-update
^- (quip card _state)
?+ -.fact [~ state]
%add
[(give-fact path.fact [%add path.fact ship.fact contact.fact]) state]
::
%remove
:_ state
:- [%give %kick ~[[%contacts path.fact]] `ship.fact]
(give-fact path.fact [%remove path.fact ship.fact])
::
%edit
[(give-fact path.fact [%edit path.fact ship.fact edit-field.fact]) state]
==
::
++ give-fact
|= [=path update=contact-update]
^- (list card)
[%give %fact ~[[%contacts path]] %contact-update !>(update)]~
::
++ local
|= fact=contact-update
^- (list card)
?+ -.fact ~
%add
(give-fact path.fact [%add path.fact ship.fact contact.fact])
::
%edit
(give-fact path.fact [%edit path.fact ship.fact edit-field.fact])
::
%remove
%+ welp
(give-fact path.fact [%remove path.fact ship.fact])
[%give %kick ~[[%contacts path.fact]] `ship.fact]~
==
::
++ foreign
|= fact=contact-update
^- (quip card _state)
?+ -.fact [~ state]
^- (list card)
?+ -.fact ~
%contacts
=/ owner (~(got by synced) path.fact)
?> =(owner src.bol)
:_ state
%+ weld
:~ (contact-poke [%delete path.fact])
(contact-poke [%create path.fact])
@ -276,17 +269,22 @@
%add
=/ owner (~(got by synced) path.fact)
?> |(=(owner src.bol) =(src.bol ship.fact))
[~[(contact-poke [%add path.fact ship.fact contact.fact])] state]
~[(contact-poke [%add path.fact ship.fact contact.fact])]
::
%remove
=/ owner (~(got by synced) path.fact)
?> |(=(owner src.bol) =(src.bol ship.fact))
[~[(contact-poke [%remove path.fact ship.fact])] state]
%+ welp
:~ (group-poke [%remove [ship.fact ~ ~] path.fact])
(contact-poke [%remove path.fact ship.fact])
==
?. =(ship.fact our.bol) ~
~[(group-poke [%unbundle path.fact])]
::
%edit
=/ owner (~(got by synced) path.fact)
?> |(=(owner src.bol) =(src.bol ship.fact))
[~[(contact-poke [%edit path.fact ship.fact edit-field.fact])] state]
~[(contact-poke [%edit path.fact ship.fact edit-field.fact])]
==
--
::
@ -311,9 +309,8 @@
|= [members=group =path]
^- (quip card _state)
:: if pax is synced, remove member from contacts and kick their sub
?. (~(has by synced) path)
[~ state]
:_ state
?. (~(has by synced) path) ~
%- zing
%+ turn ~(tap in members)
|= =ship
@ -351,6 +348,11 @@
^- card
[%pass / %agent [our.bol %contact-store] %poke %contact-action !>(act)]
::
++ group-poke
|= act=group-action
^- card
[%pass / %agent [our.bol %group-store] %poke %group-action !>(act)]
::
++ contacts-scry
|= pax=path
^- (unit contacts)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -11,14 +11,14 @@ class UrbitApi {
this.bindPaths = [];
this.contactHook = {
edit: this.contactEdit.bind(this)
edit: this.contactEdit.bind(this),
remove: this.contactRemove.bind(this)
};
this.contactView = {
create: this.contactCreate.bind(this),
delete: this.contactDelete.bind(this),
add: this.contactAdd.bind(this),
remove: this.contactRemove.bind(this),
share: this.contactShare.bind(this)
};
@ -85,8 +85,12 @@ class UrbitApi {
this.contactViewAction({ delete: { path }});
}
contactHookAction(data) {
this.action("contact-hook", "contact-action", data);
}
contactRemove(path, ship) {
this.contactViewAction({
this.contactHookAction({
remove: {
path, ship
}
@ -104,7 +108,7 @@ class UrbitApi {
{avatar: null}
{avatar: {p: length, q: bytestream}}
*/
this.action("contact-hook", "contact-action", {
this.contactHookAction({
edit: {
path, ship, 'edit-field': editField
}

View File

@ -27,6 +27,7 @@ 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);
}
componentDidUpdate(prevProps) {
@ -181,31 +182,26 @@ export class ContactCard extends Component {
case "removeEmail": {
this.setState({ emailToSet: "" });
api.contactEdit(props.path, ship, { email: "" });
this.refs.email.value = "";
break;
}
case "removeNickname": {
this.setState({ nicknameToSet: "" });
api.contactEdit(props.path, ship, { nickname: "" });
this.refs.nickname.value = "";
break;
}
case "removePhone": {
this.setState({ phoneToSet: "" });
api.contactEdit(props.path, ship, { phone: "" });
this.refs.phone.value = "";
break;
}
case "removeWebsite": {
this.setState({ websiteToSet: "" });
api.contactEdit(props.path, ship, { website: "" });
this.refs.website.value = "";
break;
}
case "removeNotes": {
this.setState({ notesToSet: "" });
api.contactEdit(props.path, ship, { notes: "" });
this.refs.notes.value = "";
break;
}
}
@ -226,7 +222,7 @@ export class ContactCard extends Component {
phone: props.rootIdentity.phone,
website: props.rootIdentity.website,
notes: props.rootIdentity.notes,
color: props.rootIdentity.color
color: uxToHex(props.rootIdentity.color)
} : {
nickname: props.contact.nickname,
email: props.contact.email,
@ -252,6 +248,12 @@ export class ContactCard extends Component {
this.editToggle();
}
removeFromGroup() {
const { props } = this;
api.contactHook.remove(props.path, `~${props.ship}`);
props.history.push(`/~contacts${props.path}`);
}
renderEditCard() {
const { props, state } = this;
// if this is our first edit in a new group, propagate from root identity
@ -464,7 +466,7 @@ export class ContactCard extends Component {
((props.ship === window.ship) && (props.path === "/~/default"))
? "dib" : "dn";
let adminOpt =
(props.path.includes(window.ship) && (props.ship !== window.ship))
(props.path.includes(window.ship) || (props.ship === window.ship))
? "dib" : "dn";
let card = state.edit ? this.renderEditCard() : this.renderCard();
@ -492,8 +494,8 @@ export class ContactCard extends Component {
Share Contact Info
</button>
<button
className={`ml3 mt2 mb2 f9 pa1 ba red2 br2 b--red2 ` + adminOpt}
onClick={this.removeContact}>
className={`ml3 mt2 mb2 f9 pa1 ba red2 br2 b--red2 pointer ` + adminOpt}
onClick={this.removeFromGroup}>
Remove from Group
</button>
</div>

View File

@ -45,7 +45,12 @@ export class GroupSidebar extends Component {
.map((uid) => {
let invite = props.invites[uid];
return (
<SidebarInvite key={uid} api={api} invite={invite} uid={uid} />
<SidebarInvite
key={uid}
api={api}
invite={invite}
uid={uid}
history={props.history} />
);
});

View File

@ -5,7 +5,9 @@ import _ from 'lodash';
export class SidebarInvite extends Component {
onAccept() {
this.props.api.invite.accept(this.props.uid);
const { props } = this;
props.api.invite.accept(props.uid);
props.history.push(`/~contacts${props.invite.path}`);
}
onDecline() {

View File

@ -18,7 +18,6 @@ export class NewScreen extends Component {
this.groupNameChange = this.groupNameChange.bind(this);
this.invChange = this.invChange.bind(this);
// this.colorChange = this.colorChange.bind(this);
}
groupNameChange(event) {
@ -33,12 +32,6 @@ export class NewScreen extends Component {
});
}
// colorChange(event) {
// this.setState({
// color: event.target.value
// });
// }
onClickCreate() {
const { props, state } = this;
if (!state.groupName) {
@ -82,11 +75,11 @@ export class NewScreen extends Component {
}, () => {
props.setSpinner(true);
props.api.contactView.create(group, aud);
props.history.push(`/~contacts${group}`);
});
}
render() {
let groupNameErrElem = (<span />);
if (this.state.groupNameError) {
groupNameErrElem = (
@ -105,23 +98,6 @@ export class NewScreen extends Component {
);
}
/*
{<h2 className="f8 pl3 pt6">Group Avatar</h2>
<p className="f9 pl3 gray2 lh-copy">
Select a color to represent your group
</p>
<textarea
className="f7 ba b--gray3 w-50 w-25-xl pa3 ml3 mt2"
rows={1}
placeholder="#000000"
style={{
resize: "none",
height: 48,
paddingTop: 14
}}
/>}
*/
return (
<div className="h-100 w-100 flex flex-column overflow-y-scroll">
<div className="w-100 dn-m dn-l dn-xl inter pt1 pb6 pl3 pt3 f8">

View File

@ -47,6 +47,7 @@ export class Root extends Component {
return (
<Skeleton
activeDrawer="groups"
history={props.history}
api={api}
contacts={contacts}
groups={groups}
@ -60,12 +61,16 @@ export class Root extends Component {
return (
<Skeleton
spinner={state.spinner}
history={props.history}
api={api}
contacts={contacts}
groups={groups}
invites={invites}
activeDrawer="rightPanel">
<NewScreen setSpinner={this.setSpinner} api={api} />
<NewScreen
history={props.history}
setSpinner={this.setSpinner}
api={api} />
</Skeleton>
);
}} />
@ -79,6 +84,7 @@ export class Root extends Component {
return (
<Skeleton
spinner={state.spinner}
history={props.history}
api={api}
contacts={contacts}
invites={invites}
@ -106,6 +112,7 @@ export class Root extends Component {
return (
<Skeleton
spinner={state.spinner}
history={props.history}
api={api}
contacts={contacts}
groups={groups}
@ -138,11 +145,15 @@ export class Root extends Component {
let contact =
(window.ship in groupContacts) ?
groupContacts[window.ship] : {};
if (window.ship in groupContacts) {
props.history.push(`/~contacts/view${groupPath}/${window.ship}`);
}
let group = groups[groupPath] || new Set([]);
return (
<Skeleton
spinner={state.spinner}
history={props.history}
api={api}
contacts={contacts}
groups={groups}
@ -157,6 +168,7 @@ export class Root extends Component {
path={groupPath}
selectedContact={shipPath} />
<ContactCard
history={props.history}
contact={contact}
path={groupPath}
ship={window.ship}
@ -185,6 +197,7 @@ export class Root extends Component {
return (
<Skeleton
spinner={state.spinner}
history={props.history}
api={api}
contacts={contacts}
groups={groups}
@ -199,6 +212,7 @@ export class Root extends Component {
path={groupPath}
selectedContact={shipPath} />
<ContactCard
history={props.history}
contact={contact}
path={groupPath}
ship={props.match.params.contact}
@ -214,13 +228,15 @@ export class Root extends Component {
return (
<Skeleton
spinner={state.spinner}
history={props.history}
api={api}
contacts={contacts}
groups={groups}
invites={invites}
activeDrawer="rightPanel"
selected="me">
<ContactCard
<ContactCard
history={props.history}
path="/~/default"
contact={me}
ship={window.ship} />

View File

@ -20,6 +20,7 @@ export class Skeleton extends Component {
invites={props.invites}
activeDrawer={props.activeDrawer}
selected={props.selected}
history={props.history}
api={api}
/>
<div