Skip to content

Commit

Permalink
OV-425: * show recent videos in reverse order by createdAt
Browse files Browse the repository at this point in the history
  • Loading branch information
lfelix3011 committed Sep 25, 2024
1 parent e4aa255 commit 5ed7cd2
Showing 1 changed file with 20 additions and 1 deletion.
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

0 comments on commit 5ed7cd2

Please sign in to comment.