Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OV-425: Recent videos should appear order by createdAt #435

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
useAppSelector,
useContext,
useEffect,
useMemo,
} from '~/bundles/common/hooks/hooks.js';
import { notificationService } from '~/bundles/common/services/services.js';
import {
Expand All @@ -23,6 +24,7 @@ import {
} from '~/bundles/home/enums/enums.js';
import { VideoGallery } from '~/bundles/home/enums/video-gallery.js';
import { actions as homeActions } from '~/bundles/home/store/home.js';
import { type VideoGetAllItemResponseDto } from '~/bundles/home/types/types.js';

import { VideoSection } from '../components.js';
import styles from './styles.module.css';
Expand Down Expand Up @@ -75,6 +77,20 @@ const MainContent: React.FC = () => {
};
}, [dispatch, socket]);

const recentVideos = useMemo(() => {
return [...videos].sort(
(
firstVideo: VideoGetAllItemResponseDto,
secondVideo: VideoGetAllItemResponseDto,
) => {
return (
new Date(secondVideo.createdAt).getTime() -
new Date(firstVideo.createdAt).getTime()
);
},
);
}, [videos]);

return (
<Box
className={styles['main-content']}
Expand All @@ -84,7 +100,10 @@ const MainContent: React.FC = () => {
<Loader />
</Overlay>

<VideoSection videos={videos} title={VideoGallery.RECENT_VIDEOS} />
<VideoSection
videos={recentVideos}
title={VideoGallery.RECENT_VIDEOS}
/>
<VideoSection videos={videos} title={VideoGallery.VIDEOS} />
</Box>
);
Expand Down
Loading