Skip to content

Commit

Permalink
Merge pull request #400 from BinaryStudioAcademy/task/OV-399-add-hori…
Browse files Browse the repository at this point in the history
…zontal-scroll-to-the-recent-videos-section

OV-399: Add horizontal scroll to recent videos
  • Loading branch information
nikita-remeslov authored Sep 24, 2024
2 parents fdf29aa + 60e47b5 commit c4390f9
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ import {
Loader,
Overlay,
} from '~/bundles/common/components/components.js';
import { useCollapse } from '~/bundles/common/components/sidebar/hooks/use-collapse.hook.js';
import { DataStatus } from '~/bundles/common/enums/enums.js';
import {
useAppDispatch,
useAppSelector,
useEffect,
} from '~/bundles/common/hooks/hooks.js';
import { VideoGallery } from '~/bundles/home/enums/video-gallery.js';
import { actions as homeActions } from '~/bundles/home/store/home.js';

import { VideoSection } from '../components.js';
import styles from './styles.module.css';

const MainContent: React.FC = () => {
const dispatch = useAppDispatch();
const { isCollapsed } = useCollapse();

const { videos, dataStatus } = useAppSelector(({ home }) => home);

Expand All @@ -26,13 +29,16 @@ const MainContent: React.FC = () => {
}, [dispatch]);

return (
<Box className={styles['main-content']}>
<Box
className={styles['main-content']}
w={isCollapsed ? 'calc(100vw - 60px)' : 'calc(100vw - 270px)'}
>
<Overlay isOpen={dataStatus === DataStatus.PENDING}>
<Loader />
</Overlay>

<VideoSection videos={videos} title="Recent videos" />
<VideoSection videos={videos} title="Videos" />
<VideoSection videos={videos} title={VideoGallery.RECENT_VIDEOS} />
<VideoSection videos={videos} title={VideoGallery.VIDEOS} />
</Box>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.horizontal {
display: flex;
overflow-x: auto;
scrollbar-width: thin;
scrollbar-color: #c1c1c1 #f1f1f1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
} from '~/bundles/common/components/components.js';
import { type VideoGetAllItemResponseDto } from '~/bundles/home/types/types.js';

import { VideoGallery } from '../../enums/video-gallery.js';
import { VideoCard } from '../components.js';
import styles from './styles.module.css';

type Properties = {
videos: Array<VideoGetAllItemResponseDto> | [];
Expand All @@ -33,11 +35,29 @@ const VideoSection: React.FC<Properties> = ({ videos, title }) => {
</Flex>

{videos.length > 0 ? (
<SimpleGrid columns={{ sm: 2, md: 3, lg: 4 }} spacing="20px">
{videos.map(({ id, ...video }) => (
<VideoCard key={id} id={id} {...video} />
))}
</SimpleGrid>
title === VideoGallery.RECENT_VIDEOS ? (
<Box className={styles['horizontal']}>
{videos.map(({ id, ...video }) => (
<Box
key={id}
flex="0 0 auto"
marginRight="20px"
width="250px"
>
<VideoCard id={id} {...video} />
</Box>
))}
</Box>
) : (
<SimpleGrid
columns={{ sm: 2, md: 3, lg: 4 }}
spacing="20px"
>
{videos.map(({ id, ...video }) => (
<VideoCard key={id} id={id} {...video} />
))}
</SimpleGrid>
)
) : (
<Text color="typography.600" variant="body1">
You have no videos right now.
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/bundles/home/enums/video-gallery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const VideoGallery = {
VIDEOS: 'Videos',
RECENT_VIDEOS: 'Recent videos',
} as const;

export { VideoGallery };
2 changes: 1 addition & 1 deletion frontend/src/bundles/home/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { MainContent } from '../components/components.js';

const Home: React.FC = () => {
return (
<Box bg="background.900" minHeight="100vh" overflow="auto">
<Box bg="background.900" minHeight="100vh">
<Header />
<Sidebar>
<MainContent />
Expand Down

0 comments on commit c4390f9

Please sign in to comment.