contacts-js: update to global store

This commit is contained in:
Liam Fitzgerald 2020-06-22 16:04:21 +10:00
parent 3a3a6ab254
commit 85aa12a5a9
10 changed files with 60 additions and 73 deletions

View File

@ -24,17 +24,17 @@ export default class ContactsApi extends BaseApi<StoreState> {
});
}
contactDelete(path: Path) {
delete(path: Path) {
return this.viewAction({ delete: { path } });
}
contactRemove(path: Path, ship: Patp) {
remove(path: Path, ship: Patp) {
return this.viewAction({ remove: { path, ship } });
}
contactEdit(path: Path, ship: Patp, editField: ContactEdit) {
edit(path: Path, ship: Patp, editField: ContactEdit) {
/* editField can be...
{nickname: ''}
{email: ''}

View File

@ -10,6 +10,7 @@ import ContactsApi from './contacts';
import GroupsApi from './groups';
import LaunchApi from './launch';
import LinksApi from './links';
import PublishApi from './publish';
export default class GlobalApi extends BaseApi<StoreState> {
chat = new ChatApi(this.ship, this.channel, this.store);

View File

@ -17,9 +17,6 @@ import GroupDetail from './components/lib/group-detail';
export default class GroupsApp extends Component {
constructor(props) {
super(props);
this.store = new GroupsStore();
this.state = this.store.state;
this.resetControllers();
}
componentDidMount() {
@ -27,41 +24,30 @@ export default class GroupsApp extends Component {
// preload spinner asset
new Image().src = '/~landscape/img/Spinner.png';
this.store.setStateHandler(this.setState.bind(this));
const channel = new this.props.channel();
this.api = new GroupsApi(this.props.ship, channel, this.store);
this.subscription = new GroupsSubscription(this.store, this.api, channel);
this.subscription.start();
this.props.subscription.startApp('groups')
}
componentWillUnmount() {
this.subscription.delete();
this.store.clear();
this.store.setStateHandler(() => {});
this.resetControllers();
this.props.subscription.stopApp('groups')
}
resetControllers() {
this.api = null;
this.subscription = null;
}
render() {
const { state, props } = this;
const { props } = this;
const contacts = state.contacts ? state.contacts : {};
const contacts = props.contacts || {};
const defaultContacts =
(Boolean(state.contacts) && '/~/default' in state.contacts) ?
state.contacts['/~/default'] : {};
const groups = state.groups ? state.groups : {};
(Boolean(props.contacts) && '/~/default' in props.contacts) ?
props.contacts['/~/default'] : {};
const groups = props.groups ? props.groups : {};
const invites =
(Boolean(state.invites) && '/contacts' in state.invites) ?
state.invites['/contacts'] : {};
const associations = state.associations ? state.associations : {};
(Boolean(props.invites) && '/contacts' in props.invites) ?
props.invites['/contacts'] : {};
const associations = props.associations ? props.associations : {};
const selectedGroups = props.selectedGroups ? props.selectedGroups : [];
const s3 = state.s3 ? state.s3 : {};
const s3 = props.s3 ? props.s3 : {};
const { api } = props;
return (
<Switch>
@ -72,7 +58,7 @@ export default class GroupsApp extends Component {
activeDrawer="groups"
selectedGroups={selectedGroups}
history={props.history}
api={this.api}
api={api}
contacts={contacts}
groups={groups}
invites={invites}
@ -95,7 +81,7 @@ export default class GroupsApp extends Component {
<Skeleton
history={props.history}
selectedGroups={selectedGroups}
api={this.api}
api={api}
contacts={contacts}
groups={groups}
invites={invites}
@ -106,7 +92,7 @@ export default class GroupsApp extends Component {
history={props.history}
groups={groups}
contacts={contacts}
api={this.api}
api={api}
/>
</Skeleton>
);
@ -129,7 +115,7 @@ export default class GroupsApp extends Component {
<Skeleton
history={props.history}
selectedGroups={selectedGroups}
api={this.api}
api={api}
contacts={contacts}
invites={invites}
groups={groups}
@ -142,7 +128,7 @@ export default class GroupsApp extends Component {
defaultContacts={defaultContacts}
group={group}
activeDrawer={(detail || settings) ? 'detail' : 'contacts'}
api={this.api}
api={api}
path={groupPath}
{...props}
/>
@ -153,7 +139,7 @@ export default class GroupsApp extends Component {
activeDrawer={(detail || settings) ? 'detail' : 'contacts'}
settings={settings}
associations={associations}
api={this.api}
api={api}
{...props}
/>
</Skeleton>
@ -171,7 +157,7 @@ export default class GroupsApp extends Component {
<Skeleton
history={props.history}
selectedGroups={selectedGroups}
api={this.api}
api={api}
contacts={contacts}
groups={groups}
invites={invites}
@ -185,11 +171,11 @@ export default class GroupsApp extends Component {
group={group}
activeDrawer="rightPanel"
path={groupPath}
api={this.api}
api={api}
{...props}
/>
<AddScreen
api={this.api}
api={api}
groups={groups}
path={groupPath}
history={props.history}
@ -215,7 +201,7 @@ export default class GroupsApp extends Component {
return (
<Skeleton
history={props.history}
api={this.api}
api={api}
selectedGroups={selectedGroups}
contacts={contacts}
groups={groups}
@ -230,12 +216,12 @@ export default class GroupsApp extends Component {
defaultContacts={defaultContacts}
group={group}
path={groupPath}
api={this.api}
api={api}
selectedContact={shipPath}
{...props}
/>
<ContactCard
api={this.api}
api={api}
history={props.history}
contact={contact}
path={groupPath}
@ -268,7 +254,7 @@ export default class GroupsApp extends Component {
return (
<Skeleton
history={props.history}
api={this.api}
api={api}
selectedGroups={selectedGroups}
contacts={contacts}
groups={groups}
@ -283,12 +269,12 @@ export default class GroupsApp extends Component {
defaultContacts={defaultContacts}
group={group}
path={groupPath}
api={this.api}
api={api}
selectedContact={shipPath}
{...props}
/>
<ContactCard
api={this.api}
api={api}
history={props.history}
contact={contact}
path={groupPath}
@ -307,7 +293,7 @@ export default class GroupsApp extends Component {
return (
<Skeleton
history={props.history}
api={this.api}
api={api}
selectedGroups={selectedGroups}
contacts={contacts}
groups={groups}
@ -317,7 +303,7 @@ export default class GroupsApp extends Component {
associations={associations}
>
<ContactCard
api={this.api}
api={api}
history={props.history}
path="/~/default"
contact={me}

View File

@ -42,7 +42,7 @@ export class AddScreen extends Component {
},
awaiting: true
}, () => {
const submit = props.api.group.add(props.path, aud);
const submit = props.api.groups.add(props.path, aud);
submit.then(() => {
this.setState({ awaiting: false });
props.history.push('/~groups' + props.path);

View File

@ -141,7 +141,7 @@ export class ContactCard extends Component {
type: 'Saving to group'
},
() => {
props.api.contactHook.edit(props.path, ship, {
props.api.contacts.edit(props.path, ship, {
avatar: {
url: state.avatarToSet
}})
@ -161,7 +161,7 @@ export class ContactCard extends Component {
if (hexTest && hexTest[1] !== currentColor && !props.share) {
this.setState({ awaiting: true, type: 'Saving to group' }, () => {
props.api.contactHook.edit(
props.api.contacts.edit(
props.path, `~${props.ship}`, { color: hexTest[1] })
.then(() => {
this.setState({ awaiting: false });
@ -180,7 +180,7 @@ export class ContactCard extends Component {
const emailTestResult = emailTest.exec(state.emailToSet);
if (emailTestResult) {
this.setState({ awaiting: true, type: 'Saving to group' }, () => {
props.api.contactHook.edit(
props.api.contacts.edit(
props.path, ship, { email: state.emailToSet })
.then(() => {
this.setState({ awaiting: false });
@ -197,7 +197,7 @@ export class ContactCard extends Component {
return false;
}
this.setState({ awaiting: true, type: 'Saving to group' }, () => {
props.api.contactHook.edit(
props.api.contacts.edit(
props.path, ship, { nickname: state.nickNameToSet })
.then(() => {
this.setState({ awaiting: false });
@ -214,7 +214,7 @@ export class ContactCard extends Component {
return false;
}
this.setState({ awaiting: true, type: 'Saving to group' }, () => {
props.api.contactHook.edit(
props.api.contacts.edit(
props.path, ship, { notes: state.notesToSet })
.then(() => {
this.setState({ awaiting: false });
@ -232,7 +232,7 @@ export class ContactCard extends Component {
const phoneTestResult = phoneTest.exec(state.phoneToSet);
if (phoneTestResult) {
this.setState({ awaiting: true, type: 'Saving to group' }, () => {
props.api.contactHook.edit(
props.api.contacts.edit(
props.path, ship, { phone: state.phoneToSet })
.then(() => {
this.setState({ awaiting: false });
@ -251,7 +251,7 @@ export class ContactCard extends Component {
const websiteTestResult = websiteTest.exec(state.websiteToSet);
if (websiteTestResult) {
this.setState({ awaiting: true, type: 'Saving to group' }, () => {
props.api.contactHook.edit(
props.api.contacts.edit(
props.path, ship, { website: state.websiteToSet })
.then(() => {
this.setState({ awaiting: false });
@ -264,7 +264,7 @@ export class ContactCard extends Component {
this.setState(
{ emailToSet: '', awaiting: true, type: 'Removing from group' },
() => {
props.api.contactHook.edit(props.path, ship, { email: '' })
props.api.contacts.edit(props.path, ship, { email: '' })
.then(() => {
this.setState({ awaiting: false });
});
@ -276,7 +276,7 @@ export class ContactCard extends Component {
this.setState(
{ nicknameToSet: '', awaiting: true, type: 'Removing from group' },
() => {
props.api.contactHook.edit(props.path, ship, { nickname: '' })
props.api.contacts.edit(props.path, ship, { nickname: '' })
.then(() => {
this.setState({ awaiting: false });
});
@ -288,7 +288,7 @@ export class ContactCard extends Component {
this.setState(
{ phoneToSet: '', awaiting: true, type: 'Removing from group' },
() => {
props.api.contactHook.edit(props.path, ship, { phone: '' }).then(() => {
props.api.contacts.edit(props.path, ship, { phone: '' }).then(() => {
this.setState({ awaiting: false });
});
}
@ -299,7 +299,7 @@ export class ContactCard extends Component {
this.setState(
{ websiteToSet: '', awaiting: true, type: 'Removing from group' },
() => {
props.api.contactHook.edit(props.path, ship, { website: '' }).then(() => {
props.api.contacts.edit(props.path, ship, { website: '' }).then(() => {
this.setState({ awaiting: false });
});
}
@ -314,7 +314,7 @@ export class ContactCard extends Component {
type: 'Removing from group'
},
() => {
props.api.contactHook.edit(props.path, ship, { avatar: null }).then(() => {
props.api.contacts.edit(props.path, ship, { avatar: null }).then(() => {
this.setState({ awaiting: false });
});
}
@ -325,7 +325,7 @@ export class ContactCard extends Component {
this.setState(
{ notesToSet: '', awaiting: true, type: 'Removing from group' },
() => {
props.api.contactHook.edit(props.path, ship, { notes: '' }).then(() => {
props.api.contacts.edit(props.path, ship, { notes: '' }).then(() => {
this.setState({ awaiting: false });
});
}
@ -380,7 +380,7 @@ export class ContactCard extends Component {
};
this.setState({ awaiting: true, type: 'Sharing with group' }, () => {
props.api.contactView
props.api.contacts
.share(`~${props.ship}`, props.path, `~${window.ship}`, contact)
.then(() => {
props.history.push(`/~groups/view${props.path}/${window.ship}`);
@ -402,7 +402,7 @@ export class ContactCard extends Component {
avatar: null
};
props.api.contactView.share(
props.api.contacts.share(
`~${props.ship}`,
props.path,
`~${window.ship}`,
@ -410,7 +410,7 @@ export class ContactCard extends Component {
);
this.setState({ awaiting: true, type: 'Removing from group' }, () => {
props.api.contactView.delete(props.path).then(() => {
props.api.contacts.delete(props.path).then(() => {
this.setState({ awaiting: false });
props.history.push('/~groups');
});
@ -421,7 +421,7 @@ export class ContactCard extends Component {
const { props } = this;
this.setState({ awaiting: true, type: 'Removing from group' }, () => {
props.api.contactView.remove(props.path, `~${props.ship}`).then(() => {
props.api.contacts.remove(props.path, `~${props.ship}`).then(() => {
this.setState({ awaiting: false });
props.history.push(`/~groups${props.path}`);
});

View File

@ -99,7 +99,7 @@ export class ContactSidebar extends Component {
style={{ paddingTop: 6 }}
onClick={() => {
this.setState({ awaiting: true }, (() => {
props.api.group.remove(props.path, [`~${member}`])
props.api.groups.remove(props.path, [`~${member}`])
.then(() => {
this.setState({ awaiting: false });
});

View File

@ -198,7 +198,8 @@ export class GroupDetail extends Component {
onBlur={() => {
if (groupOwner) {
this.setState({ awaiting: true }, (() => {
props.api.metadata.add(
props.api.metadata.metadataAdd(
'contacts',
association['app-path'],
association['group-path'],
this.state.title,
@ -227,7 +228,8 @@ export class GroupDetail extends Component {
onBlur={() => {
if (groupOwner) {
this.setState({ awaiting: true }, (() => {
props.api.metadata.add(
props.api.metadata.metadataAdd(
'contacts',
association['app-path'],
association['group-path'],
association.metadata.title,
@ -250,7 +252,7 @@ export class GroupDetail extends Component {
onClick={() => {
if (groupOwner) {
this.setState({ awaiting: true, type: 'Deleting' }, (() => {
props.api.contactView.delete(props.path).then(() => {
props.api.contacts.delete(props.path).then(() => {
props.history.push('/~groups');
});
}));

View File

@ -3,12 +3,12 @@ import React, { Component } from 'react';
export class SidebarInvite extends Component {
onAccept() {
const { props } = this;
props.api.invite.accept(props.uid);
props.api.invite.accept('/contacts', props.uid);
props.history.push(`/~groups${props.invite.path}`);
}
onDecline() {
this.props.api.invite.decline(this.props.uid);
this.props.api.invite.decline('/contacts', this.props.uid);
}
render() {

View File

@ -67,7 +67,7 @@ export class NewScreen extends Component {
invites: '',
awaiting: true
}, () => {
props.api.contactView.create(
props.api.contacts.create(
group,
aud,
this.state.title,

View File

@ -44,8 +44,6 @@ export default class GlobalSubscription extends BaseSubscription<StoreState> {
groups: []
};
start() {
this.subscribe('/all', 'invite-store');
this.subscribe('/app-name/contacts', 'metadata-store');
this.subscribe('/all', 'invite-store');
this.subscribe('/all', 'permission-store');
this.subscribe('/primary', 'contact-view');