lbry-desktop/ui/redux/reducers/blocked.js
infinite-persistence 99f87e95e3
Geo blocklist - reimplement with backend support (#1089)
Ticket: 1079 Support geoblocking channels/videos

## Changes
- Replaced the .env version with iapi version.
- Includes 'videos' blocking and custom messages.
2022-03-14 15:15:30 -04:00

44 lines
1.3 KiB
JavaScript

// @flow
import * as ACTIONS from 'constants/action_types';
import { handleActions } from 'util/redux-utils';
const defaultState: BlocklistState = {
blockedChannels: [],
geoBlockedList: undefined,
};
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)) {
newBlockedChannels = newBlockedChannels.filter((id) => id !== uri);
} else {
newBlockedChannels.unshift(uri);
}
return {
...state,
blockedChannels: newBlockedChannels,
};
},
[ACTIONS.FETCH_GBL_DONE]: (state: BlocklistState, action: any): BlocklistState => {
return {
...state,
geoBlockedList: action.data,
};
},
[ACTIONS.USER_STATE_POPULATE]: (state: BlocklistState, action: { data: { blocked: ?Array<string> } }) => {
const { blocked } = action.data;
const sanitizedBlocked = blocked && blocked.filter((e) => typeof e === 'string');
return {
...state,
blockedChannels: sanitizedBlocked || state.blockedChannels,
};
},
},
defaultState
);