[Glitch] Revamp post filtering system
Port front-end changes from 02851848e9 to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
@@ -1,10 +1,34 @@
|
||||
import { FILTERS_FETCH_SUCCESS } from '../actions/filters';
|
||||
import { List as ImmutableList, fromJS } from 'immutable';
|
||||
import { FILTERS_IMPORT } from '../actions/importer';
|
||||
import { Map as ImmutableMap, is, fromJS } from 'immutable';
|
||||
|
||||
export default function filters(state = ImmutableList(), action) {
|
||||
const normalizeFilter = (state, filter) => {
|
||||
const normalizedFilter = fromJS({
|
||||
id: filter.id,
|
||||
title: filter.title,
|
||||
context: filter.context,
|
||||
filter_action: filter.filter_action,
|
||||
expires_at: filter.expires_at ? Date.parse(filter.expires_at) : null,
|
||||
});
|
||||
|
||||
if (is(state.get(filter.id), normalizedFilter)) {
|
||||
return state;
|
||||
} else {
|
||||
return state.set(filter.id, normalizedFilter);
|
||||
}
|
||||
};
|
||||
|
||||
const normalizeFilters = (state, filters) => {
|
||||
filters.forEach(filter => {
|
||||
state = normalizeFilter(state, filter);
|
||||
});
|
||||
|
||||
return state;
|
||||
};
|
||||
|
||||
export default function filters(state = ImmutableMap(), action) {
|
||||
switch(action.type) {
|
||||
case FILTERS_FETCH_SUCCESS:
|
||||
return fromJS(action.filters);
|
||||
case FILTERS_IMPORT:
|
||||
return normalizeFilters(state, action.filters);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user