Skip muted list update if no change #7228

Closed
infinite-persistence wants to merge 1 commit from ip/muted.uris into master
3 changed files with 17 additions and 6 deletions

View file

@ -30,6 +30,14 @@ export default handleActions(
) => { ) => {
const { blocked } = action.data; const { blocked } = action.data;
const sanitizedBlocked = blocked && blocked.filter((e) => typeof e === 'string'); const sanitizedBlocked = blocked && blocked.filter((e) => typeof e === 'string');
const next = sanitizedBlocked;
const prev = state.blockedChannels;
if (next && prev && prev.length === next.length && prev.every((value, index) => value === next[index])) {
return state;
}
return { return {
...state, ...state,
blockedChannels: sanitizedBlocked && sanitizedBlocked.length ? sanitizedBlocked : state.blockedChannels, blockedChannels: sanitizedBlocked && sanitizedBlocked.length ? sanitizedBlocked : state.blockedChannels,

View file

@ -2,11 +2,11 @@
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { splitBySeparator } from 'lbry-redux'; import { splitBySeparator } from 'lbry-redux';
const selectState = (state: { blocked: BlocklistState }) => state.blocked || {}; type State = { blocked: BlocklistState };
export const selectMutedChannels = createSelector(selectState, (state: BlocklistState) => { const selectState = (state: State) => state.blocked || {};
return state.blockedChannels.filter((e) => typeof e === 'string');
}); export const selectMutedChannels = (state: State) => selectState(state).blockedChannels;
export const makeSelectChannelIsMuted = (uri: string) => export const makeSelectChannelIsMuted = (uri: string) =>
createSelector(selectMutedChannels, (state: Array<string>) => { createSelector(selectMutedChannels, (state: Array<string>) => {

View file

@ -36,8 +36,11 @@ export const makeSelectPinnedCommentsForUri = (uri: string) =>
} }
); );
export const selectModerationBlockList = createSelector(selectState, (state) => export const selectModerationBlockList = createSelector(
state.moderationBlockList ? state.moderationBlockList.reverse() : [] (state) => selectState(state).moderationBlockList,
(moderationBlockList) => {
return moderationBlockList ? moderationBlockList.reverse() : [];
}
); );
export const selectAdminBlockList = createSelector(selectState, (state) => export const selectAdminBlockList = createSelector(selectState, (state) =>
state.adminBlockList ? state.adminBlockList.reverse() : [] state.adminBlockList ? state.adminBlockList.reverse() : []