Skip to content

Commit

Permalink
fix: regression introduced in 671c0ab
Browse files Browse the repository at this point in the history
  • Loading branch information
AXeL-dev committed Aug 22, 2022
1 parent 22955f3 commit f8c9254
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
31 changes: 24 additions & 7 deletions src/store/selectors/videos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,30 @@ import { selectViewFilters } from './settings';

export const selectVideos = (state: RootState) => state.videos.list;

export const selectChannelVideos = (channel: Channel, filters?: ViewFilters) =>
export const selectChannelVideos = (channel: Channel) =>
createSelector(selectVideos, (videos) =>
videos.filter(
(video) =>
channel.id === video.channelId &&
(!filters || filterVideoByFlags(video, filters)),
),
videos.filter(({ channelId }) => channel.id === channelId),
);

export const selectRecentChannelVideos = (channel: Channel) =>
createSelector(
selectVideos,
selectViewFilters(HomeView.Recent),
(videos, filters) =>
videos
.filter((video) => channel.id === video.channelId)
.reduce(
(acc, video) => {
const key = filterVideoByFlags(video, filters)
? 'included'
: 'excluded';
return {
...acc,
[key]: [...acc[key], video.id],
};
},
{ excluded: [] as string[], included: [] as string[] },
),
);

export const selectViewedVideos = (channel?: Channel) =>
Expand Down Expand Up @@ -48,7 +65,7 @@ const filter2Flag = (key: ViewFilter): VideoFlag => {
}
};

export const filterVideoByFlags = (video: VideoCache, filters: ViewFilters) => {
const filterVideoByFlags = (video: VideoCache, filters: ViewFilters) => {
const filterKeys = Object.keys(filters) as ViewFilter[];
const hasFlag = (key: ViewFilter) => {
const flag = filter2Flag(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useAppSelector } from 'store';
import { selectSettings } from 'store/selectors/settings';
import { getDateBefore } from 'helpers/utils';
import DefaultRenderer, { DefaultRendererProps } from './DefaultRenderer';
import { selectChannelVideos } from 'store/selectors/videos';
import { selectRecentChannelVideos } from 'store/selectors/videos';
import { isWebExtension } from 'helpers/webext';
import { Video } from 'types';

Expand All @@ -13,12 +13,16 @@ export interface RecentViewRendererProps
function RecentViewRenderer(props: RecentViewRendererProps) {
const { channel } = props;
const settings = useAppSelector(selectSettings);
const videos = useAppSelector(
selectChannelVideos(channel, settings.recentViewFilters),
).map(({ id }) => id);
const videos = useAppSelector(selectRecentChannelVideos(channel));
const filterCallback = useCallback(
(video: Video) => videos.includes(video.id),
[videos],
(video: Video) => {
if (settings.recentViewFilters.uncategorised) {
return !videos.excluded.includes(video.id);
} else {
return videos.included.includes(video.id);
}
},
[settings.recentViewFilters.uncategorised, videos],
);
const publishedAfter = useMemo(
() => getDateBefore(settings.recentVideosSeniority).toISOString(),
Expand Down

0 comments on commit f8c9254

Please sign in to comment.