mirror of
https://github.com/urbit/shrub.git
synced 2024-12-03 05:43:18 +03:00
interface: move invite subs to airlock
This commit is contained in:
parent
3066077ca9
commit
8bf990becb
@ -3,6 +3,8 @@ import useHarkState from '~/logic/state/hark';
|
||||
import useMetadataState from '~/logic/state/metadata';
|
||||
import useContactState from '../state/contact';
|
||||
import useGroupState from '../state/group';
|
||||
import useInviteState from '../state/invite';
|
||||
import useLaunchState from '../state/launch';
|
||||
import useSettingsState from '../state/settings';
|
||||
|
||||
const api = new Urbit('', '');
|
||||
@ -21,7 +23,9 @@ export const bootstrapApi = async () => {
|
||||
useMetadataState,
|
||||
useGroupState,
|
||||
useContactState,
|
||||
useSettingsState
|
||||
useSettingsState,
|
||||
useLaunchState,
|
||||
useInviteState
|
||||
].forEach((state) => {
|
||||
state.getState().initialize(api);
|
||||
});
|
||||
|
@ -1,24 +1,9 @@
|
||||
import { InviteUpdate } from '@urbit/api/invite';
|
||||
import _ from 'lodash';
|
||||
import { Cage } from '~/types/cage';
|
||||
import { reduceState } from '../state/base';
|
||||
import useInviteState, { InviteState } from '../state/invite';
|
||||
import { BaseState } from '../state/base';
|
||||
import { InviteState as State } from '../state/invite';
|
||||
|
||||
export default class InviteReducer {
|
||||
reduce(json: Cage) {
|
||||
const data = json['invite-update'];
|
||||
if (data) {
|
||||
reduceState<InviteState, InviteUpdate>(useInviteState, data, [
|
||||
initial,
|
||||
create,
|
||||
deleteInvite,
|
||||
invite,
|
||||
accepted,
|
||||
decline
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
type InviteState = State & BaseState<State>;
|
||||
|
||||
const initial = (json: InviteUpdate, state: InviteState): InviteState => {
|
||||
const data = _.get(json, 'initial', false);
|
||||
@ -67,3 +52,12 @@ const decline = (json: InviteUpdate, state: InviteState): InviteState => {
|
||||
}
|
||||
return state;
|
||||
};
|
||||
|
||||
export const reduce = [
|
||||
initial,
|
||||
create,
|
||||
deleteInvite,
|
||||
invite,
|
||||
accepted,
|
||||
decline
|
||||
];
|
||||
|
@ -1,13 +1,31 @@
|
||||
import { Invites } from '@urbit/api';
|
||||
import { BaseState, createState } from './base';
|
||||
import { reduce } from '../reducers/invite-update';
|
||||
import _ from 'lodash';
|
||||
import {
|
||||
createState,
|
||||
createSubscription,
|
||||
reduceStateN
|
||||
} from './base';
|
||||
|
||||
export interface InviteState extends BaseState<InviteState> {
|
||||
export interface InviteState {
|
||||
invites: Invites;
|
||||
}
|
||||
|
||||
// @ts-ignore investigate zustand types
|
||||
const useInviteState = createState<InviteState>('Invite', {
|
||||
invites: {}
|
||||
});
|
||||
const useInviteState = createState<InviteState>(
|
||||
'Invite',
|
||||
{
|
||||
invites: {}
|
||||
},
|
||||
['invites'],
|
||||
[
|
||||
(set, get) =>
|
||||
createSubscription('invite-store', '/all', (e) => {
|
||||
const d = _.get(e, 'invite-update', false);
|
||||
if (d) {
|
||||
reduceStateN(get(), d, reduce);
|
||||
}
|
||||
})
|
||||
]
|
||||
);
|
||||
|
||||
export default useInviteState;
|
||||
|
Loading…
Reference in New Issue
Block a user