Skip to content

Commit

Permalink
chore: enhance videos selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
AXeL-dev committed Oct 15, 2022
1 parent 36c491d commit e823934
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/store/selectors/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export const selectHasExtraVideoAction = (action: ExtraVideoAction) =>
);

export const selectVideosSeniority = (view: HomeView) =>
createSelector(
selectSettings,
(settings) => settings.viewOptions[view].videosSeniority,
);
createSelector(selectSettings, (settings) => {
if (settings.viewOptions[view].videosSeniority === undefined) {
return defaultSettings.viewOptions[view].videosSeniority;
}
return settings.viewOptions[view].videosSeniority;
});
10 changes: 5 additions & 5 deletions src/store/selectors/videos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
selectVideosSeniority,
selectViewFilters,
} from './settings';
import { elapsedDays, getDateBefore } from 'helpers/utils';
import { elapsedDays } from 'helpers/utils';

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

Expand Down Expand Up @@ -120,7 +120,7 @@ export const selectWatchLaterVideos = (channel?: Channel) =>
(!channel || channel.id === video.channelId) &&
filterVideoByFlags(video, filters) &&
(videosSeniority === VideosSeniority.Any ||
video.publishedAt >= getDateBefore(videosSeniority).getTime()),
elapsedDays(video.publishedAt) <= videosSeniority),
)
.sort((a, b) => b.publishedAt - a.publishedAt),
);
Expand All @@ -138,7 +138,7 @@ export const selectBookmarkedVideos = (channel?: Channel) =>
(!channel || channel.id === video.channelId) &&
filterVideoByFlags(video, filters) &&
(videosSeniority === VideosSeniority.Any ||
video.publishedAt >= getDateBefore(videosSeniority).getTime()),
elapsedDays(video.publishedAt) <= videosSeniority),
)
.sort((a, b) => b.publishedAt - a.publishedAt),
);
Expand All @@ -156,7 +156,7 @@ export const selectBookmarkedVideosCount = createSelector(
activeChannelsIds.includes(video.channelId) &&
filterVideoByFlags(video, filters) &&
(videosSeniority === VideosSeniority.Any ||
video.publishedAt >= getDateBefore(videosSeniority).getTime()),
elapsedDays(video.publishedAt) <= videosSeniority),
).length;
},
);
Expand All @@ -174,7 +174,7 @@ export const selectWatchLaterVideosCount = createSelector(
activeChannelsIds.includes(video.channelId) &&
filterVideoByFlags(video, filters) &&
(videosSeniority === VideosSeniority.Any ||
video.publishedAt >= getDateBefore(videosSeniority).getTime()),
elapsedDays(video.publishedAt) <= videosSeniority),
).length;
},
);
Expand Down

0 comments on commit e823934

Please sign in to comment.