Files
remark42/frontend/app/store/thread/actions.ts
T
Pavel MineevandUmputun 5825a55b69 Update frontend
* change root dit and change way to import modules
* update deps to latest versions
* use latest tools for building bundles
* rewrite webpack config
* use nomodule technique for loading modern bundle
* inject polyfills by babel usebuiltins
* update eslint rules
* rename all style files to CSS
* use postcss preset env for building styles
* proper typescript typing
* put all html files to templates folder
* etc
2021-01-12 13:39:26 -06:00

30 lines
869 B
TypeScript

import { Comment } from 'common/types';
import { siteId, url } from 'common/settings';
import { StoreAction } from '../index';
import { THREAD_SET_COLLAPSE, THREAD_RESTORE_COLLAPSE_ACTION, THREAD_RESTORE_COLLAPSE } from './types';
import { saveCollapsedComments, getCollapsedComments } from './utils';
export const restoreCollapsedThreads = (): THREAD_RESTORE_COLLAPSE_ACTION => ({
type: THREAD_RESTORE_COLLAPSE,
ids: getCollapsedComments(),
});
export const setCollapse = (id: Comment['id'], value: boolean): StoreAction<void> => (dispatch, getState) => {
dispatch({
type: THREAD_SET_COLLAPSE,
id,
collapsed: value,
});
saveCollapsedComments(
siteId!,
url!,
Object.entries(getState().collapsedThreads).reduce((acc: string[], [key, value]) => {
if (value) {
acc.push(key);
}
return acc;
}, [])
);
};