Skip to content

Commit

Permalink
refactor: watch later videos count selector
Browse files Browse the repository at this point in the history
  • Loading branch information
AXeL-dev committed Jul 10, 2022
1 parent 5e55776 commit 8aa6462
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/store/selectors/videos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ViewFilter,
ViewFilters,
} from 'types';
import { selectChannels, selectHiddenChannels } from './channels';
import { selectActiveChannels } from './channels';
import { selectViewFilters } from './settings';

export const selectVideos = (state: RootState) => state.videos.list;
Expand Down Expand Up @@ -84,32 +84,28 @@ export const selectWatchLaterVideos = (channel?: Channel) =>
export const selectWatchLaterVideosCount = createSelector(
selectVideos,
selectViewFilters(HomeView.WatchLater),
selectChannels,
(videos, filters, channels) => {
const channelsIds = channels.map(({ id }) => id);
const hiddenChannelsIds = channels
.filter(({ isHidden }) => isHidden)
.map(({ id }) => id);
selectActiveChannels,
(videos, filters, activeChannels) => {
const activeChannelsIds = activeChannels.map(({ id }) => id);
return videos.filter(
({ flags, channelId }) =>
flags.toWatchLater &&
channelsIds.includes(channelId) &&
!hiddenChannelsIds.includes(channelId) &&
activeChannelsIds.includes(channelId) &&
filterVideoByFlags(flags, filters)
).length;
}
);

export const selectViewedWatchLaterVideosCount = createSelector(
selectVideos,
selectHiddenChannels,
(videos, hiddenChannels) => {
const hiddenChannelsIds = hiddenChannels.map(({ id }) => id);
selectActiveChannels,
(videos, activeChannels) => {
const activeChannelsIds = activeChannels.map(({ id }) => id);
return videos.filter(
({ flags, channelId }) =>
flags.toWatchLater &&
flags.viewed &&
!hiddenChannelsIds.includes(channelId)
activeChannelsIds.includes(channelId)
).length;
}
);
Expand Down

0 comments on commit 8aa6462

Please sign in to comment.