Skip to content

Commit

Permalink
feat: video player
Browse files Browse the repository at this point in the history
  • Loading branch information
karlhadwen committed Jul 8, 2020
1 parent cdfba78 commit 39135cd
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 52 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"react/prefer-stateless-function": 0,
"react/forbid-prop-types": 0,
"react/no-unescaped-entities": 0,
"jsx-a11y/media-has-caption": 0,
"jsx-a11y/accessible-emoji": 0,
"react/require-default-props": 0,
"react/jsx-props-no-spreading": 0,
Expand Down
Binary file added public/videos/bunny.mp4
Binary file not shown.
14 changes: 3 additions & 11 deletions src/components/card/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useState, useContext, createContext } from 'react';
import CancelIcon from '@material-ui/icons/Cancel';
import PlayArrowIcon from '@material-ui/icons/PlayArrow';

import {
Container,
Expand All @@ -17,7 +16,6 @@ import {
Entities,
Item,
Image,
PlayButton,
} from './styles/card';

export const FeatureContext = createContext();
Expand Down Expand Up @@ -77,11 +75,7 @@ Card.Image = function CardImage({ ...restProps }) {
return <Image {...restProps} />;
};

Card.PlayButton = function CardPlayButton({ children, ...restProps }) {
return <PlayButton>{children}</PlayButton>;
};

Card.Feature = function CardFeature({ category, ...restProps }) {
Card.Feature = function CardFeature({ children, category, ...restProps }) {
const { showFeature, itemFeature, setShowFeature } = useContext(FeatureContext);

return showFeature ? (
Expand All @@ -97,10 +91,8 @@ Card.Feature = function CardFeature({ category, ...restProps }) {
{itemFeature.genre.charAt(0).toUpperCase() + itemFeature.genre.slice(1)}
</FeatureText>
</Group>
<PlayButton>
<PlayArrowIcon className="play" />
Play
</PlayButton>

{children}
</Content>
</Feature>
) : null;
Expand Down
26 changes: 0 additions & 26 deletions src/components/card/styles/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,32 +134,6 @@ export const Content = styled.div`
}
`;

export const PlayButton = styled.button`
background-color: #e50914;
border-color: #ff0a16;
width: 115px;
height: 45px;
text-transform: uppercase;
font-weight: bold;
color: white;
font-size: 18px;
height: 45px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
padding-left: 0;
&:hover {
transform: scale(1.05);
background-color: #ff0a16;
}
svg.play {
margin-right: 5px;
}
`;

export const Maturity = styled.div`
background-color: ${({ rating }) => (rating >= 15 ? 'red' : 'green')};
border-radius: 15px;
Expand Down
4 changes: 2 additions & 2 deletions src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ Header.Feature = function HeaderFeature({ children, ...restProps }) {
return <Feature>{children}</Feature>;
};

Header.Picture = function HeaderPicture({ ...restProps }) {
return <Picture {...restProps} />;
Header.Picture = function HeaderPicture({ src, ...restProps }) {
return <Picture {...restProps} src={`/images/users/${src}.png`} />;
};

Header.Dropdown = function HeaderDropdown({ children, ...restProps }) {
Expand Down
14 changes: 13 additions & 1 deletion src/components/header/styles/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,20 @@ export const Dropdown = styled.div`
top: 32px;
right: 10px;
${Group}:last-of-type ${Link} {
cursor: pointer;
}
${Group} {
margin-bottom: 10px;
&:last-of-type {
margin-bottom: 0;
}
${Link}, ${Picture} {
cursor: default;
}
}
button {
Expand All @@ -121,14 +129,18 @@ export const Profile = styled.div`
display: flex;
align-items: center;
margin-left: 20px;
cursor: pointer;
position: relative;
svg {
color: white;
margin-left: 5px;
}
button,
svg {
cursor: pointer;
}
&:hover > ${Dropdown} {
display: flex;
flex-direction: column;
Expand Down
1 change: 1 addition & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export { default as Profiles } from './profiles';
export { default as Footer } from './footer';
export { default as Header } from './header';
export { default as Loading } from './loading';
export { default as Player } from './player';
2 changes: 1 addition & 1 deletion src/components/loading/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function Loading({ src, ...restProps }) {
return (
<Spinner {...restProps}>
<LockBody />
<Picture src={src} />
<Picture src={`/images/users/${src}.png`} />
</Spinner>
);
}
Expand Down
44 changes: 44 additions & 0 deletions src/components/player/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { useState, useEffect, useContext, createRef, createContext } from 'react';
import PlayArrowIcon from '@material-ui/icons/PlayArrow';
import ReactDOM from 'react-dom';
import { Container, Button, Overlay, Inner } from './styles/player';

export const PlayerContext = createContext();

export default function Player({ children, ...restProps }) {
const [showPlayer, setShowPlayer] = useState(false);

return (
<PlayerContext.Provider value={{ showPlayer, setShowPlayer }}>
<Container {...restProps}>{children}</Container>
</PlayerContext.Provider>
);
}

Player.Video = function PlayerVideo({ ...restProps }) {
const { showPlayer, setShowPlayer } = useContext(PlayerContext);

return showPlayer
? ReactDOM.createPortal(
<Overlay onClick={() => setShowPlayer(false)}>
<Inner>
<video id="netflix-player" controls>
<source src="/videos/bunny.mp4" type="video/mp4" />
</video>
</Inner>
</Overlay>,
document.body
)
: null;
};

Player.Button = function PlayerButton({ ...restProps }) {
const { showPlayer, setShowPlayer } = useContext(PlayerContext);

return (
<Button onClick={() => setShowPlayer(!showPlayer)}>
<PlayArrowIcon className="play" />
Play
</Button>
);
};
88 changes: 88 additions & 0 deletions src/components/player/styles/player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import styled from 'styled-components/macro';

export const Container = styled.div``;

export const Overlay = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
margin: 0 20px;
`;

export const Inner = styled.div`
position: relative;
width: 100%;
max-width: 900px;
margin: auto;
video {
height: 100%;
width: 100%;
}
`;

export const Close = styled.button`
position: absolute;
right: 15px;
top: 15px;
width: 22px;
height: 22px;
opacity: 0.3;
background-color: transparent;
border: 0;
cursor: pointer;
&:hover {
opacity: 1;
}
&:before,
&:after {
position: absolute;
left: 10px;
top: 0;
content: ' ';
height: 22px;
width: 2px;
background-color: #333;
}
&:before {
transform: rotate(45deg);
}
&:after {
transform: rotate(-45deg);
}
`;

export const Button = styled.button`
background-color: #e50914;
border-color: #ff0a16;
width: 115px;
height: 45px;
text-transform: uppercase;
font-weight: bold;
color: white;
font-size: 18px;
height: 45px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
padding-left: 0;
&:hover {
transform: scale(1.05);
background-color: #ff0a16;
}
svg.play {
margin-right: 5px;
}
`;
2 changes: 1 addition & 1 deletion src/components/profiles/styles/profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const Picture = styled.img`
max-width: 150px;
height: auto;
border: 3px solid black;
cursor: pointer;
`;

export const Item = styled.li`
Expand All @@ -48,7 +49,6 @@ export const Item = styled.li`
list-style-type: none;
text-align: center;
margin-right: 30px;
cursor: pointer;
&:hover > ${Picture} {
border: 3px solid white;
Expand Down
18 changes: 10 additions & 8 deletions src/containers/browse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect, useContext } from 'react';
import Fuse from 'fuse.js';
import { Card, Header, Loading } from '../components';
import { Card, Header, Loading, Player } from '../components';
import * as ROUTES from '../constants/routes';
import logo from '../logo.svg';
import { FirebaseContext } from '../context/firebase';
Expand Down Expand Up @@ -40,7 +40,7 @@ export function BrowseContainer({ slides }) {

return profile.displayName ? (
<>
{loading ? <Loading src={`/images/users/${user.photoURL}.png`} /> : <Loading.ReleaseBody />}
{loading ? <Loading src={user.photoURL} /> : <Loading.ReleaseBody />}

<Header src="joker1">
<Header.Frame>
Expand All @@ -56,15 +56,12 @@ export function BrowseContainer({ slides }) {
<Header.Group>
<Header.Search searchTerm={searchTerm} setSearchTerm={setSearchTerm} />
<Header.Profile>
<Header.Picture src={`/images/users/${user.photoURL}.png`} />
<Header.Picture src={user.photoURL} />
<Header.Dropdown>
<Header.Group>
<Header.Picture src={`/images/users/${user.photoURL}.png`} />
<Header.Picture src={user.photoURL} />
<Header.TextLink>{user.displayName}</Header.TextLink>
</Header.Group>
<Header.Group>
<Header.TextLink onClick={() => console.log('favourites')}>Favourites</Header.TextLink>
</Header.Group>
<Header.Group>
<Header.TextLink onClick={() => firebase.auth().signOut()}>Sign out</Header.TextLink>
</Header.Group>
Expand Down Expand Up @@ -99,7 +96,12 @@ export function BrowseContainer({ slides }) {
</Card.Item>
))}
</Card.Entities>
<Card.Feature category={category} />
<Card.Feature category={category}>
<Player>
<Player.Button />
<Player.Video />
</Player>
</Card.Feature>
</Card>
))}
</Card.Group>
Expand Down
2 changes: 0 additions & 2 deletions src/hooks/use-content.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { useEffect, useState, useContext } from 'react';
import { FirebaseContext } from '../context/firebase';

// with the profile id updating, this is going to get called again and again,
// need to figure out how to stop that
export default function useContent(target) {
const [content, setContent] = useState([]);
const { firebase } = useContext(FirebaseContext);
Expand Down

0 comments on commit 39135cd

Please sign in to comment.