mirror of
https://github.com/urbit/shrub.git
synced 2025-01-03 10:02:32 +03:00
Merge pull request #4960 from urbit/mp/contacts/optimistic-type-mismatch
interface: catch contact-update type mismatch
This commit is contained in:
commit
653a3e9f8f
@ -3,27 +3,6 @@ import _ from 'lodash';
|
||||
import { reduceState } from '../state/base';
|
||||
import useContactState, { ContactState } from '../state/contact';
|
||||
|
||||
export const ContactReducer = (json) => {
|
||||
const data: ContactUpdate = _.get(json, 'contact-update', false);
|
||||
if (data) {
|
||||
reduceState<ContactState, ContactUpdate>(useContactState, data, [
|
||||
initial,
|
||||
add,
|
||||
remove,
|
||||
edit,
|
||||
setPublic
|
||||
]);
|
||||
}
|
||||
|
||||
// TODO: better isolation
|
||||
const res = _.get(json, 'resource', false);
|
||||
if (res) {
|
||||
useContactState.setState({
|
||||
nackedContacts: useContactState.getState().nackedContacts.add(`~${res.ship}`)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const initial = (json: ContactUpdate, state: ContactState): ContactState => {
|
||||
const data = _.get(json, 'initial', false);
|
||||
if (data) {
|
||||
@ -65,12 +44,20 @@ export const edit = (json: ContactUpdate, state: ContactState): ContactState =>
|
||||
}
|
||||
|
||||
const value = data['edit-field'][field];
|
||||
|
||||
if(field === 'add-group') {
|
||||
state.contacts[ship].groups.push(value);
|
||||
if (typeof value !== 'string') {
|
||||
state.contacts[ship].groups.push(`/ship/${Object.values(value).join('/')}`);
|
||||
} else if (!(state.contacts[ship].groups.includes(value))) {
|
||||
state.contacts[ship].groups.push(value);
|
||||
}
|
||||
} else if (field === 'remove-group') {
|
||||
if (typeof value !== 'string') {
|
||||
state.contacts[ship].groups =
|
||||
state.contacts[ship].groups.filter(g => g !== `/ship/${Object.values(value).join('/')}`);
|
||||
} else {
|
||||
state.contacts[ship].groups =
|
||||
state.contacts[ship].groups.filter(g => g !== value);
|
||||
}
|
||||
} else {
|
||||
state.contacts[ship][field] = value;
|
||||
}
|
||||
@ -84,3 +71,23 @@ const setPublic = (json: ContactUpdate, state: ContactState): ContactState => {
|
||||
return state;
|
||||
};
|
||||
|
||||
export const ContactReducer = (json) => {
|
||||
const data: ContactUpdate = _.get(json, 'contact-update', false);
|
||||
if (data) {
|
||||
reduceState<ContactState, ContactUpdate>(useContactState, data, [
|
||||
initial,
|
||||
add,
|
||||
remove,
|
||||
edit,
|
||||
setPublic
|
||||
]);
|
||||
}
|
||||
|
||||
// TODO: better isolation
|
||||
const res = _.get(json, 'resource', false);
|
||||
if (res) {
|
||||
useContactState.setState({
|
||||
nackedContacts: useContactState.getState().nackedContacts.add(`~${res.ship}`)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -56,9 +56,10 @@ export function ViewProfile(props: any): ReactElement {
|
||||
<Col gapY={3} mb={3} mt={6} alignItems='flex-start'>
|
||||
<Text gray>Pinned Groups</Text>
|
||||
<Col>
|
||||
{contact?.groups.slice().sort(lengthOrder).map(g => (
|
||||
{contact?.groups.slice().sort(lengthOrder).map((g, i) => (
|
||||
<GroupLink
|
||||
api={api}
|
||||
key={i}
|
||||
resource={g}
|
||||
measure={() => {}}
|
||||
/>
|
||||
|
Loading…
Reference in New Issue
Block a user