Basic redux integration for thread component (#141)

This commit is contained in:
Dmitry Tsepelev
2018-07-10 14:05:39 +04:00
committed by Aleksei Gurianov
parent b6cda91dd9
commit a02b1502a6
13 changed files with 286 additions and 55 deletions
@@ -0,0 +1,22 @@
import { siteId, url } from 'common/settings';
import { THREAD_SET_COLLAPSE } from './thread.actions';
import getCollapsedComments from './getCollapsedComments';
const collapsedCommentIds = getCollapsedComments()
.map(comment => comment.split('_'))
.filter(components => components[0] === siteId && components[1] === url)
.map(component => component[2]);
const initialState = collapsedCommentIds.reduce((acc, id) => ({ ...acc, [id]: true }), {});
export const collapsedThreads = (state = initialState, action) => {
switch (action.type) {
case THREAD_SET_COLLAPSE:
return {
...state,
[action.comment.id]: action.collapsed,
};
default:
return state;
}
};