mirror of
https://github.com/wassname/talk.git
synced 2026-08-06 13:41:02 +08:00
We now check if the IgnoreUser mutation returned an error before updating the apollo store. If the mutation returns an error we keep the store as it is, otherwise the user is added to the ignore list.
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
import IgnoreUserAction from './containers/IgnoreUserAction';
|
|
import IgnoreUserConfirmation from './containers/IgnoreUserConfirmation';
|
|
import IgnoredUserSection from './containers/IgnoredUserSection';
|
|
import translations from './translations.yml';
|
|
import update from 'immutability-helper';
|
|
import get from 'lodash/get';
|
|
|
|
export default {
|
|
slots: {
|
|
authorMenuActions: [IgnoreUserAction],
|
|
ignoreUserConfirmation: [IgnoreUserConfirmation],
|
|
profileSections: [IgnoredUserSection],
|
|
},
|
|
translations,
|
|
mutations: {
|
|
IgnoreUser: ({variables}) => ({
|
|
updateQueries: {
|
|
CoralEmbedStream_Embed: (previousData, {mutationResult: {data: {ignoreUser}}}) => {
|
|
if (get(ignoreUser, 'errors.length')) {
|
|
return previousData;
|
|
}
|
|
|
|
const ignoredUserId = variables.id;
|
|
const updated = update(previousData, {me: {ignoredUsers: {$push: [{
|
|
id: ignoredUserId,
|
|
__typename: 'User',
|
|
}]}}});
|
|
return updated;
|
|
}
|
|
}
|
|
}),
|
|
StopIgnoringUser: ({variables}) => ({
|
|
updateQueries: {
|
|
CoralEmbedStream_Profile: (previousData) => {
|
|
const noLongerIgnoredUserId = variables.id;
|
|
|
|
// remove noLongerIgnoredUserId from ignoredUsers
|
|
const updated = update(previousData, {me: {ignoredUsers: {
|
|
$apply: (ignoredUsers) => {
|
|
return ignoredUsers.filter((u) => u.id !== noLongerIgnoredUserId);
|
|
}
|
|
}}});
|
|
return updated;
|
|
}
|
|
}
|
|
}),
|
|
},
|
|
};
|