interface: basic new contact-store support

This commit is contained in:
Logan Allen 2021-01-19 13:56:17 -06:00
parent cdb91291ed
commit 6d95cc76a4
3 changed files with 44 additions and 44 deletions

View File

@ -5,32 +5,33 @@ import { ContactUpdate } from '~/types/contact-update';
type ContactState = Pick<StoreState, 'contacts'>; type ContactState = Pick<StoreState, 'contacts'>;
export default class ContactReducer<S extends ContactState> { export const ContactReducer = (json, state) => {
reduce(json: Cage, state: S) {
const data = _.get(json, 'contact-update', false); const data = _.get(json, 'contact-update', false);
if (data) { if (data) {
this.initial(data, state); console.log(data);
this.add(data, state); initial(data, state);
this.remove(data, state); add(data, state);
this.edit(data, state); remove(data, state);
} edit(data, state);
console.log(state);
} }
};
initial(json: ContactUpdate, state: S) { const initial = (json: ContactUpdate, state: S) => {
const data = _.get(json, 'initial', false); const data = _.get(json, 'initial', false);
if (data) { if (data) {
state.contacts = data; state.contacts = data;
} }
} };
add(json: ContactUpdate, state: S) { const add = (json: ContactUpdate, state: S) => {
const data = _.get(json, 'add', false); const data = _.get(json, 'add', false);
if (data) { if (data) {
state.contacts[data.ship] = data.contact; state.contacts[data.ship] = data.contact;
} }
} };
remove(json: ContactUpdate, state: S) { const remove = (json: ContactUpdate, state: S) => {
const data = _.get(json, 'remove', false); const data = _.get(json, 'remove', false);
if ( if (
data && data &&
@ -38,9 +39,9 @@ export default class ContactReducer<S extends ContactState> {
) { ) {
delete state.contacts[data.ship]; delete state.contacts[data.ship];
} }
} };
edit(json: ContactUpdate, state: S) { const edit = (json: ContactUpdate, state: S) => {
const data = _.get(json, 'edit', false); const data = _.get(json, 'edit', false);
if ( if (
data && data &&
@ -52,5 +53,4 @@ export default class ContactReducer<S extends ContactState> {
} }
state.contacts[data.ship][edit[0]] = data['edit-field'][edit[0]]; state.contacts[data.ship][edit[0]] = data['edit-field'][edit[0]];
} }
} };
}

View File

@ -6,10 +6,10 @@ import LocalReducer from '../reducers/local';
import { StoreState } from './type'; import { StoreState } from './type';
import { Timebox } from '~/types'; import { Timebox } from '~/types';
import { Cage } from '~/types/cage'; import { Cage } from '~/types/cage';
import ContactReducer from '../reducers/contact-update';
import S3Reducer from '../reducers/s3-update'; import S3Reducer from '../reducers/s3-update';
import { GraphReducer } from '../reducers/graph-update'; import { GraphReducer } from '../reducers/graph-update';
import { HarkReducer } from '../reducers/hark-update'; import { HarkReducer } from '../reducers/hark-update';
import { ContactReducer } from '../reducers/contact-update';
import GroupReducer from '../reducers/group-update'; import GroupReducer from '../reducers/group-update';
import LaunchReducer from '../reducers/launch-update'; import LaunchReducer from '../reducers/launch-update';
import ConnectionReducer from '../reducers/connection'; import ConnectionReducer from '../reducers/connection';
@ -34,7 +34,6 @@ export default class GlobalStore extends BaseStore<StoreState> {
inviteReducer = new InviteReducer(); inviteReducer = new InviteReducer();
metadataReducer = new MetadataReducer(); metadataReducer = new MetadataReducer();
localReducer = new LocalReducer(); localReducer = new LocalReducer();
contactReducer = new ContactReducer();
s3Reducer = new S3Reducer(); s3Reducer = new S3Reducer();
groupReducer = new GroupReducer(); groupReducer = new GroupReducer();
launchReducer = new LaunchReducer(); launchReducer = new LaunchReducer();
@ -54,7 +53,7 @@ export default class GlobalStore extends BaseStore<StoreState> {
baseHash: null, baseHash: null,
invites: {}, invites: {},
associations: { associations: {
contacts: {}, groups: {},
graph: {}, graph: {},
}, },
groups: {}, groups: {},
@ -97,12 +96,12 @@ export default class GlobalStore extends BaseStore<StoreState> {
this.inviteReducer.reduce(data, this.state); this.inviteReducer.reduce(data, this.state);
this.metadataReducer.reduce(data, this.state); this.metadataReducer.reduce(data, this.state);
this.localReducer.reduce(data, this.state); this.localReducer.reduce(data, this.state);
this.contactReducer.reduce(data, this.state);
this.s3Reducer.reduce(data, this.state); this.s3Reducer.reduce(data, this.state);
this.groupReducer.reduce(data, this.state); this.groupReducer.reduce(data, this.state);
this.launchReducer.reduce(data, this.state); this.launchReducer.reduce(data, this.state);
this.connReducer.reduce(data, this.state); this.connReducer.reduce(data, this.state);
GraphReducer(data, this.state); GraphReducer(data, this.state);
HarkReducer(data, this.state); HarkReducer(data, this.state);
ContactReducer(data, this.state);
} }
} }

View File

@ -36,7 +36,8 @@ export default class GlobalSubscription extends BaseSubscription<StoreState> {
this.subscribe('/groups', 'group-store'); this.subscribe('/groups', 'group-store');
this.clearQueue(); this.clearQueue();
this.subscribe('/updates', 'contact-store'); // TODO: update to get /updates
this.subscribe('/all', 'contact-store');
this.subscribe('/all', 's3-store'); this.subscribe('/all', 's3-store');
this.subscribe('/keys', 'graph-store'); this.subscribe('/keys', 'graph-store');
this.subscribe('/updates', 'hark-store'); this.subscribe('/updates', 'hark-store');