fix unblocking after page refresh stalled (#384)

This commit is contained in:
Misha Vyrtsev
2019-07-23 16:45:52 -05:00
committed by Umputun
parent 4d7699ec5e
commit 5431f80e84
2 changed files with 9 additions and 3 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ export function filterTree(tree: Node[], fn: (node: Node) => boolean): Node[] {
* Traverses through tree and applies function to comment on which function passed.
* Note that function must not mutate comment
*/
function mapTree(tree: Node[], fn: (c: Comment) => Comment): Node[] {
export function mapTree(tree: Node[], fn: (c: Comment) => Comment): Node[] {
return tree.map(node => {
const clone: Node = {
comment: fn(node.comment),
+8 -2
View File
@@ -17,7 +17,7 @@ import {
SETTINGS_VISIBLE_SET,
} from './types';
import { setComments, unsetCommentMode } from '../comments/actions';
import { setUserVerified as uSetUserVerified, filterTree } from '../comments/utils';
import { setUserVerified as uSetUserVerified, filterTree, mapTree } from '../comments/utils';
import { IS_STORAGE_AVAILABLE, LS_HIDDEN_USERS_KEY } from '@app/common/constants';
import { getItem } from '@app/common/local-storage';
import { Dispatch } from 'redux';
@@ -74,12 +74,18 @@ export const blockUser = (
});
};
export const unblockUser = (id: User['id']): StoreAction<Promise<void>> => async dispatch => {
export const unblockUser = (id: User['id']): StoreAction<Promise<void>> => async (dispatch, getState) => {
await api.unblockUser(id);
const comments = mapTree(getState().comments, c => {
if (c.user.id !== id) return c;
if (!c.user.block) return c;
return { ...c, user: { ...c.user, block: false } };
});
dispatch({
type: USER_UNBAN,
id,
});
dispatch(setComments(comments));
};
export const fetchHiddenUsers = (): StoreAction<void> => dispatch => {