Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"@testing-library/user-event": "^12.1.3",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-icons": "^4.2.0",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.3"
"react-scripts": "3.4.3",
"styled-components": "^5.2.1"
},
"scripts": {
"start": "react-scripts start",
Expand Down Expand Up @@ -57,5 +59,6 @@
"hooks": {
"pre-commit": "lint-staged"
}
}
},
"coverage": "react-scripts test --env=jsdom --watchAll=false --coverage"
}
57 changes: 8 additions & 49 deletions src/components/App/App.component.jsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,16 @@
import React, { useLayoutEffect } from 'react';
import { BrowserRouter, Switch, Route } from 'react-router-dom';
import React from 'react';
import Header from '../Header/Header.component';
import HomePage from '../../pages/Home/Home.page';

import AuthProvider from '../../providers/Auth';
import HomePage from '../../pages/Home';
import LoginPage from '../../pages/Login';
import NotFound from '../../pages/NotFound';
import SecretPage from '../../pages/Secret';
import Private from '../Private';
import Fortune from '../Fortune';
import Layout from '../Layout';
import { random } from '../../utils/fns';

function App() {
useLayoutEffect(() => {
const { body } = document;

function rotateBackground() {
const xPercent = random(100);
const yPercent = random(100);
body.style.setProperty('--bg-position', `${xPercent}% ${yPercent}%`);
}

const intervalId = setInterval(rotateBackground, 3000);
body.addEventListener('click', rotateBackground);

return () => {
clearInterval(intervalId);
body.removeEventListener('click', rotateBackground);
};
}, []);


return (
<BrowserRouter>
<AuthProvider>
<Layout>
<Switch>
<Route exact path="/">
<HomePage />
</Route>
<Route exact path="/login">
<LoginPage />
</Route>
<Private exact path="/secret">
<SecretPage />
</Private>
<Route path="*">
<NotFound />
</Route>
</Switch>
<Fortune />
</Layout>
</AuthProvider>
</BrowserRouter>
<div className="App-dark">
<Header/>
<HomePage/>
</div>
);
}

Expand Down
158 changes: 158 additions & 0 deletions src/components/Header/Header.component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import React from 'react';
import styled from 'styled-components';
import {MdMenu, MdSearch, MdPersonOutline} from 'react-icons/md';

const ContainerHeader = styled.header`
display: flex;
align-items: center;
position: fixed;
top:0;
width: 100%;
height: 65px;
background-color: #ACDEDF;

`;

const MenuButton = styled.button`
display: flex;
align-items: center;
justify-content: center;
width: 55px;
height: 55px;
padding: 10px;
background-color: transparent;
border:none;
font-size: 1.3rem;
`;

const InputSearch = styled.input`
align-items: center;
padding: 10px;
background-color: transparent;
box-sizing: content-box;
padding: 10px;
box-sizing: content-box;
border: 1px solid #bbc1bf;
font-size: 1.3rem;
background: #0000;
border-radius: 3px;
height: 1rem;
font-size: 1rem;
padding-left: 30px;
`;

const DivSearch = styled.div`
cursor: text;
display: inline-flex;
position: relative;
font-size: 1rem;
align-items: center;
height: 100%;
justify-content: center;
`;

const DivIcon = styled.div`
justify-content: center;
color: #fff;
position: relative;
left: 30px;
height: 100%;
align-items: center;
display: flex;
font-size: 1.3rem;
`;
Comment on lines +5 to +63
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract all the styles into different files depending of the component. You have various components mixed on the same file. I would create i.e. a file called SearchBar.styled.js, inside the file I inserted all the related styles for the SearchBar, export all the styles, and in another file SearchBar.component.jsx use them.

You have all the components in the Header component. React's good practice is to create small components, so you could reuse them in different places of your app, if you keep them in the same it is difficult to keep track where the component is defined and how to reuse it.



const DivFlex = styled.div`
flex-grow: 1;
`;

const ToggleSwitch = styled.label`
position: relative;
display: inline-block;
width: 60px;
height: 30px;
`;

const Slider = styled.span`
position: absolute;
cursor: pointer;
border-radius: 30px;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
&::before {
position: absolute;
content: "";
height: 24px;
width: 24px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
border-radius: 50%;
}
`;

const CheckboxSwitch = styled.input`
background-color: #b39541;
opacity: 0;
width: 0px;
height: 0px;
&:checked + ${Slider} {
background: #b39541;
&::before {
transform: translateX(24px);
}
}
`;
const Span = styled.span`
color: #b39541;
font-size: 0.8rem;
padding: 10px;
`;

const Avatar = styled.div`
background-color: #b39541;
border-radius: 999999px;
margin: 1%;
height: 45px;
width: 45px;
opacity: 0.5;
color: #fff;
display: inline-flex;
font-size: 1.6rem;
align-items: center;
justify-content: center;
`;
Comment on lines +66 to +132
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same CSS extraction comment here



function Header() {

return (

<ContainerHeader>
<MenuButton><MdMenu/></MenuButton>
<DivSearch>
<DivIcon><MdSearch/></DivIcon>
<InputSearch placeholder="Search"/>
</DivSearch>
<DivFlex/>
<Span>Dark mode</Span>
<ToggleSwitch>
<CheckboxSwitch type="checkbox" />
<Slider/>
</ToggleSwitch>
<Avatar>
<MdPersonOutline/>
</Avatar>
</ContainerHeader>
)
}

export default Header;
53 changes: 53 additions & 0 deletions src/components/Video/VideoCard.component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import styled from 'styled-components';

const Container = styled.div`
width: 323px;
height: 400px;
margin: 10px;
max-width: 100%;
display: inline-grid;
overflow: hidden;
border: 1px solid #eee;
max-width: 100%;
padding: 10px;
`;

const Description = styled.span`
font-size: .8rem;
line-height: 1.2rem;
display: inline-block;
`;

const ContainerImg = styled.div`
text-align:center;
height: 180px;
overflow: hidden;
`;

const Image = styled.img`
max-width:100%;
height: 100%;
`;

const Title = styled.h3`
font-size: 1rem;
line-height: 1.2rem;
display: inline-block;
`;
Comment on lines +4 to +37
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same CSS extraction comment here


function VideoCard (data) {
return (
<Container>
<ContainerImg>
<Image alt={data.title} src={data.img} />
</ContainerImg>
<Title data-testid="video-title">{data.title}</Title>
<Description data-testid="video-description">{data.description}</Description>

</Container>
);

}

export default VideoCard;
35 changes: 35 additions & 0 deletions src/components/Video/VideoCards.component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import styled from 'styled-components';

import {mockVideosData} from '../../mock/youtube-videos-mock';
import VideoCard from './VideoCard.component'



const ContainerVideos = styled.div`
max-width: 100%;
margin: 0 5%;
`;
Comment on lines +9 to +12
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same CSS extraction comment here


function VideoCards () {

return (
<ContainerVideos>
{mockVideosData.items
.filter((a) => (a.id.kind === "youtube#video"))
.map((data) => {
return (
<VideoCard
key={data.id.videoId}
title={data.snippet.title}
description={data.snippet.description}
img={data.snippet.thumbnails.medium.url}
/>
);
})
}
</ContainerVideos>
);
}

export default VideoCards;
13 changes: 3 additions & 10 deletions src/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ body {
margin: 0;
padding: 0;
text-rendering: optimizeLegibility;
background-image: linear-gradient(
120deg,
#eea2a2 0,
#bbc1bf 19%,
#57c6e1 42%,
#b49fda 79%,
#7ac5d8 100%
);
background-size: 400% 400%;
background-position: var(--bg-position);
transition: background-position 2s ease;
Expand All @@ -49,5 +41,6 @@ a:active {
color: blueviolet;
}

hr {
}
h1 {
font-size: 2rem;
}
Loading