Basic redux integration for thread component (#141)
This commit is contained in:
committed by
Aleksei Gurianov
parent
b6cda91dd9
commit
a02b1502a6
@@ -0,0 +1,28 @@
|
||||
import { siteId, url } from 'common/settings';
|
||||
import { THREAD_SET_COLLAPSE } from './thread.actions';
|
||||
import getCollapsedComments from './getCollapsedComments';
|
||||
import saveCollapsedComments from './saveCollapsedComments';
|
||||
|
||||
const collapsedCommentsMiddleware = ({ getState }) => next => action => {
|
||||
if (action.type === THREAD_SET_COLLAPSE) {
|
||||
const state = getState();
|
||||
const currentCollapsed = state[action.comment.id];
|
||||
|
||||
if (action.collapsed !== currentCollapsed) {
|
||||
const lsCollapsedID = `${siteId}_${url}_${action.comment.id}`;
|
||||
let collapsedComments = getCollapsedComments();
|
||||
|
||||
if (action.collapsed) {
|
||||
collapsedComments = [...new Set(collapsedComments.concat(lsCollapsedID))];
|
||||
} else {
|
||||
collapsedComments = collapsedComments.filter(id => id !== lsCollapsedID);
|
||||
}
|
||||
|
||||
saveCollapsedComments(collapsedComments);
|
||||
}
|
||||
}
|
||||
|
||||
next(action);
|
||||
};
|
||||
|
||||
export default collapsedCommentsMiddleware;
|
||||
Reference in New Issue
Block a user