Skip to content

Commit

Permalink
feat(project): add playlist grid
Browse files Browse the repository at this point in the history
  • Loading branch information
demmyhonore committed Apr 29, 2021
1 parent 24fdf83 commit 672d96d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 6 deletions.
22 changes: 22 additions & 0 deletions src/containers/Playlist/Playlist.module.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
.playlist {
color: var(--primary-color);
font-family: var(--body-alt-font-family);
margin-left: 56px;
margin-right: 56px;
text-align: center;

@media screen and (max-width: 992px) {
margin-left: 12px;
margin-right: 12px;
}
}

.playlistHeader {
display: flex;
align-items: center;

> * + * {
margin-left: 24px;
}
}

.playlistGrid {
display: grid;
grid-gap: 8px;
}
40 changes: 37 additions & 3 deletions src/containers/Playlist/Playlist.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,53 @@
import React from 'react';

import usePlaylist from '../../hooks/usePlaylist';
import useBreakpoint from '../../hooks/useBreakpoint';
import Card from '../../components/Card/Card'

import styles from './Playlist.module.scss';

type PlaylistContainerProps = {
playlistId: string;
};

type PlaylistMapArguments = {
mediaid: string;
title: string;
duration: number;
image: string;
};

const cols = { "xs": 2, "sm": 3, "md": 4, "lg": 5, "xl": 6 } // temp data, till config arrives

function Playlist({ playlistId }: PlaylistContainerProps): JSX.Element {

const { isLoading, error, data } = usePlaylist(playlistId)
const breakpoint = useBreakpoint();

if (isLoading) return <p>Loading...</p>

if (error) return <p>No playlist found...</p>

const { title, playlist } = data;

return (
<div className={styles.playlist}>
<header className={styles.playlistHeader}>
<h2 className={styles.playlistTitle}>All films</h2>
<div className={styles.playlistCategory} />
<h2 className={styles.playlistTitle}>{title}</h2>
<div className={styles.playlistCategory}>
<select name="categories">
<option value="">All</option>
<option value="some">Some</option>
</select>
</div>
</header>
<main className={styles.playlistGrid} />
<main
className={styles.playlistGrid}
style={{ gridTemplateColumns: `repeat(${cols[breakpoint]}, minmax(0,1fr))` }}
>
{playlist.map(({ mediaid: mediaId, title, duration, image }: PlaylistMapArguments) =>
<Card key={mediaId} title={title} duration={duration} posterSource={image} onClick={(() => '')} />)}
</main>
</div>
);
}
Expand Down
12 changes: 9 additions & 3 deletions src/hooks/useBreakpoint.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { useState, useEffect } from 'react';
import throttle from 'lodash.throttle';

const getDeviceConfig = (width: number) => {
type Breakpoints = 'xs' | 'sm' | 'md' | 'lg' | 'xl'

const THROTTLE_WAIT = 500;

const getDeviceConfig = (width: number): Breakpoints => {
if (width < 320) {
return 'xs';
} else if (width >= 320 && width < 720) {
return 'sm';
} else if (width >= 720 && width < 1024) {
return 'md';
} else if (width >= 1024) {
} else if (width >= 1024 && width < 1440) {
return 'lg';
} else {
return 'xl';
}
};

Expand All @@ -19,7 +25,7 @@ const useBreakpoint = () => {
useEffect(() => {
const calcInnerWidth = throttle(function () {
setBreakpoint(getDeviceConfig(window.innerWidth))
}, 200);
}, THROTTLE_WAIT);
window.addEventListener('resize', calcInnerWidth);
return () => window.removeEventListener('resize', calcInnerWidth);
}, []);
Expand Down

0 comments on commit 672d96d

Please sign in to comment.