2020-07-15 15:50:08 +02:00
|
|
|
// @flow
|
|
|
|
import * as ACTIONS from 'constants/action_types';
|
|
|
|
import { handleActions } from 'util/redux-utils';
|
|
|
|
|
|
|
|
const defaultState: BlocklistState = {
|
|
|
|
blockedChannels: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
export default handleActions(
|
|
|
|
{
|
|
|
|
[ACTIONS.TOGGLE_BLOCK_CHANNEL]: (state: BlocklistState, action: BlocklistAction): BlocklistState => {
|
|
|
|
const { blockedChannels } = state;
|
|
|
|
const { uri } = action.data;
|
|
|
|
let newBlockedChannels = blockedChannels.slice();
|
|
|
|
|
|
|
|
if (newBlockedChannels.includes(uri)) {
|
2021-03-03 19:50:16 +01:00
|
|
|
newBlockedChannels = newBlockedChannels.filter((id) => id !== uri);
|
2020-07-15 15:50:08 +02:00
|
|
|
} else {
|
2021-03-03 19:50:16 +01:00
|
|
|
newBlockedChannels.unshift(uri);
|
2020-07-15 15:50:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
blockedChannels: newBlockedChannels,
|
|
|
|
};
|
|
|
|
},
|
2022-01-06 21:30:24 +01:00
|
|
|
[ACTIONS.SYNC_STATE_POPULATE]: (state: BlocklistState, action: { data: { blocked: ?Array<string> } }) => {
|
2020-07-15 15:50:08 +02:00
|
|
|
const { blocked } = action.data;
|
2021-03-03 19:50:16 +01:00
|
|
|
const sanitizedBlocked = blocked && blocked.filter((e) => typeof e === 'string');
|
2020-07-15 15:50:08 +02:00
|
|
|
return {
|
|
|
|
...state,
|
2020-08-24 19:56:26 +02:00
|
|
|
blockedChannels: sanitizedBlocked && sanitizedBlocked.length ? sanitizedBlocked : state.blockedChannels,
|
2020-07-15 15:50:08 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
defaultState
|
|
|
|
);
|