| | import React, { useState, useEffect } from 'react'; |
| | import { Link as ReactRouterLink } from 'react-router-dom'; |
| | import "./styles/header.css"; |
| | import axios from '../../axios'; |
| | import Row from '../row'; |
| | import requests from '../../request'; |
| | import { Background, ButtonLink, Container, PlayButton, Search, SearchIcon, SearchInput, Logo, Dropdown, Profile, Picture, Group, Feature, Text, FeatureCallOut, Link } from './styles/header'; |
| |
|
| | export default function Header({ bg = true, children, ...restProps }) { |
| | return bg ? <Background { ...restProps}>{children}</Background> : children; |
| | } |
| |
|
| |
|
| | Header.Banner = function HeaderBanner({ children, ...restProps }) { |
| | |
| | const [show, handleShow] = useState(false); |
| | const [movie, setMovie] = useState([]); |
| |
|
| | useEffect(() => { |
| | async function fetchData() { |
| | const request = await axios.get(requests.fetchNetflixOriginals); |
| | setMovie ( request.data.results[Math.floor(Math.random() * request.data.results.length - 1)] |
| | ); |
| | return request; |
| | } |
| | fetchData(); |
| | }, []); |
| |
|
| | console.log(movie); |
| |
|
| | function truncate(str, n) { |
| | return str?.length > n ? str.substr(0, n-1) + "..." : str; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | return ( |
| |
|
| | <header className = "banner" |
| | style={{ |
| | backgroundSize: "cover", |
| | backgroundImage: `url("https://image.tmdb.org/t/p/original${movie?.backdrop_path}")`, |
| | backgroundPosition: "center center", |
| | }} |
| | > |
| | <div className = "banner_contents"> |
| | <h1 className="banner_title"> |
| | {movie?.title || movie?.name || movie?.original_name} |
| | </h1> |
| | |
| | <div className="banner_buttons"> |
| | <button className="banner_button">Play</button> |
| | <button className="banner_button">My List</button> |
| | </div> |
| | |
| | <h1 className = "banner_description"> |
| | {truncate(movie?.overview, 150)} |
| | </h1> |
| | </div> |
| | |
| | <div className="banner_fadeBottom" /> |
| | |
| | <div className={`nav ${show && "nav_black"}`}></div> |
| | |
| | |
| | |
| | <div> |
| | <Row title="NETFLIX ORIGINALS" fetchUrl={requests.fetchNetflixOriginals} |
| | isLargeRow |
| | /> |
| | <Row title="Trending Now" fetchUrl={requests.fetchTrending} /> |
| | <Row title="Top Rated" fetchUrl={requests.fetchTopRated} /> |
| | <Row title="Action Movies" fetchUrl={requests.fetchActionMovies} /> |
| | <Row title="Comedy Movies" fetchUrl={requests.fetchComedyMovies} /> |
| | <Row title="Horror Movies" fetchUrl={requests.fetchHorrorMovies} /> |
| | <Row title="Romance Movies" fetchUrl={requests.fetchRomanticMovies} /> |
| | <Row title="Documentaries" fetchUrl={requests.fetchDocumentaries} /> |
| | </div> |
| | |
| | </header> |
| | ); |
| | } |
| |
|
| |
|
| | Header.FeatureCallOut = function HeaderFeatureCallOut({ children, ...restProps }) { |
| | return <FeatureCallOut {...restProps}>{children}</FeatureCallOut>; |
| | }; |
| |
|
| | Header.Feature = function HeaderFeature({ children, ...restProps }) { |
| | return <Feature {...restProps}>{children}</Feature>; |
| | }; |
| |
|
| | Header.Profile = function HeaderProfile({ children, ...restProps }) { |
| | return <Profile {...restProps}>{children}</Profile>; |
| | }; |
| |
|
| | Header.Picture = function HeaderPicture({ src, ...restProps }) { |
| | return <Picture {...restProps} src={`/images/users/${src}.png`} />; |
| | }; |
| |
|
| | Header.Search = function HeaderSearch({ searchTerm, setSearchTerm, ...restProps }) { |
| | const [searchActive, setSearchActive] = useState(false); |
| |
|
| | return ( |
| | <Search {...restProps}> |
| | <SearchIcon onClick={() => setSearchActive(searchActive => !searchActive)}> |
| | <img src="/images/icons/search.png" alt="Search" /> |
| | </SearchIcon> |
| | <SearchInput value={searchTerm} onChange={({ target }) => setSearchTerm(target.value)} |
| | placeholder="Search films and series" |
| | active={searchActive} |
| | /> |
| | </Search> |
| | ); |
| | }; |
| |
|
| | Header.Dropdown = function HeaderDropdown({ children, ...restProps }) { |
| | return <Dropdown {...restProps}>{children}</Dropdown>; |
| | }; |
| |
|
| | Header.Text = function HeaderText({ children, ...restProps }) { |
| | return <Text {...restProps}>{children}</Text>; |
| | }; |
| |
|
| | Header.TextLink = function HeaderTextLink({ children, ...restProps }) { |
| | return <Link {...restProps}>{children}</Link>; |
| | }; |
| |
|
| | Header.PlayButton = function HeaderPlayButton({children, ...restProps}) { |
| | return <PlayButton {...restProps}>{children}</PlayButton> |
| | } |
| |
|
| | Header.Frame = function HeaderFrame({ children, ...restProps }) { |
| | return <Container { ...restProps}>{children}</Container>; |
| | }; |
| |
|
| | Header.Group = function HeaderGroup({ children, ...restProps }) { |
| | return <Group { ...restProps}>{children}</Group>; |
| | }; |
| |
|
| | Header.ButtonLink = function HeaderButtonLink({ children, ...restProps }) { |
| | return <ButtonLink { ...restProps}>{children}</ButtonLink>; |
| | }; |
| |
|
| | Header.Logo = function HeaderLogo({ to, ...restProps }) { |
| | return ( |
| | <ReactRouterLink to={to}> |
| | <Logo { ...restProps} /> |
| | </ReactRouterLink> |
| | ); |
| | }; |