fix unblocking after page refresh stalled (#384)
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user