forked from villacoder/react-certification-2021
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mini challenge5 #99
Open
BigOsvaap
wants to merge
14
commits into
cvillanueva84:master
Choose a base branch
from
BigOsvaap:mini-challenge5
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mini challenge5 #99
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c63e267
Installed styled-components
BigOsvaap 082c48f
Installed react-icons
BigOsvaap ba3a6c3
Added global styles and theme, components created
BigOsvaap b39a4c7
Test created and added file test-coverage.txt in root directory
BigOsvaap d13396e
Added hook to retrieve Youtube videos
BigOsvaap 3c08575
Updated globalStyles
BigOsvaap 68d85fa
Added onClick event to handle the change of light theme to dark theme
BigOsvaap 6f2c1dd
Styled component for Link to deleted text-decoration
BigOsvaap f32da79
Use of hook to retrieve data and added page and elements to visualize…
BigOsvaap 337e8b5
Added default option in thumbnail
BigOsvaap 470debb
Added useContext to provide theme
BigOsvaap 2bebb2b
Deleted use of props to use context
BigOsvaap 5a900a4
Added favorites and login validation
BigOsvaap 2f6c102
Added favorite details page
BigOsvaap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,7 @@ | |
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
#netlify | ||
|
||
.netlify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import React, { useContext, useEffect, useState } from 'react'; | ||
import VideoContext from '../Context/VideoContext'; | ||
import VideoFavoriteContext from '../Context/VideoFavorite'; | ||
import LinkVideo from '../Link.element'; | ||
import { | ||
CardVideoDisplayerContainer, | ||
CardVideoContainer, | ||
CardVideoImage, | ||
CardVideoBottom, | ||
} from './CardVideo.elements'; | ||
|
||
export function CardVideo({ video, id }) { | ||
const urlVideo = `/watch?v=${id}`; | ||
|
||
const { setVideo } = useContext(VideoContext); | ||
|
||
const handleClick = () => { | ||
setVideo(video); | ||
}; | ||
|
||
return ( | ||
<> | ||
<LinkVideo to={urlVideo} onClick={handleClick}> | ||
<CardVideoContainer> | ||
<CardVideoImage | ||
src={ | ||
video.snippet.thumbnails.high.url | ||
? video.snippet.thumbnails.high.url | ||
: video.snippet.thumbnails.default.url | ||
} | ||
/> | ||
<CardVideoBottom | ||
title={video.snippet.title} | ||
description={video.snippet.description} | ||
/> | ||
</CardVideoContainer> | ||
</LinkVideo> | ||
</> | ||
); | ||
} | ||
|
||
export function CardVideoFavorite({ video, id }) { | ||
const urlVideo = `favorites/${id}`; | ||
|
||
const { setVideoFavorite } = useContext(VideoFavoriteContext); | ||
|
||
const handleClick = () => { | ||
setVideoFavorite(id); | ||
}; | ||
|
||
return ( | ||
<> | ||
<LinkVideo to={urlVideo} onClick={handleClick}> | ||
<CardVideoContainer> | ||
<CardVideoImage | ||
src={ | ||
video.snippet.thumbnails.high.url | ||
? video.snippet.thumbnails.high.url | ||
: video.snippet.thumbnails.default.url | ||
} | ||
/> | ||
<CardVideoBottom | ||
title={video.snippet.title} | ||
description={video.snippet.description} | ||
/> | ||
</CardVideoContainer> | ||
</LinkVideo> | ||
</> | ||
); | ||
} | ||
|
||
function CardVideoDisplayer({ videos }) { | ||
const [listVideos, setListVideo] = useState(); | ||
|
||
useEffect(() => { | ||
if (videos) { | ||
setListVideo( | ||
videos.map((video) => ( | ||
<CardVideo id={video.id.videoId} key={video.etag} video={video} /> | ||
)) | ||
); | ||
} | ||
}, [videos]); | ||
|
||
return ( | ||
<> | ||
<CardVideoDisplayerContainer>{listVideos}</CardVideoDisplayerContainer> | ||
</> | ||
); | ||
} | ||
|
||
export default CardVideoDisplayer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
export const CardVideoDisplayerContainer = styled.div` | ||
display: flex; | ||
flex-wrap: wrap; | ||
position: absolute; | ||
justify-content: center; | ||
padding-bottom: 2rem; | ||
|
||
top: ${(props) => props.theme.navbar_height}; | ||
left: ${(props) => props.theme.sidemenu_width}; | ||
|
||
width: calc(100vw - ${(props) => props.theme.sidemenu_width}); | ||
`; | ||
|
||
export const CardVideoContainer = styled.div` | ||
width: calc((100vw - ${({ theme }) => theme.sidemenu_width}) / 1 - 4rem - 0.01px); | ||
aspect-ratio: 16/14; | ||
margin-top: 2rem; | ||
margin-left: 1rem; | ||
margin-right: 1rem; | ||
|
||
@media (min-width: 750px) { | ||
width: calc((100vw - ${({ theme }) => theme.sidemenu_width}) / 2 - 4rem - 0.01px); | ||
} | ||
|
||
@media (min-width: 1000px) { | ||
width: calc((100vw - ${({ theme }) => theme.sidemenu_width}) / 3 - 4rem - 0.01px); | ||
} | ||
|
||
&:hover { | ||
cursor: pointer; | ||
} | ||
`; | ||
|
||
export const CardVideoImage = styled.img` | ||
width: 100%; | ||
aspect-ratio: 16/9; | ||
height: auto; | ||
`; | ||
|
||
const CardVideoBottomContainer = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
aspect-ratio: 16/5; | ||
align-items: center; | ||
justify-content: center; | ||
`; | ||
|
||
const CardVideoTitle = styled.h2` | ||
color: ${(props) => props.theme.text_color}; | ||
font-size: 1.2rem; | ||
padding: 0.5rem 0.3rem; | ||
text-align: center; | ||
`; | ||
|
||
const CardVideoDescription = styled.p` | ||
color: ${(props) => props.theme.text_color}; | ||
|
||
padding-left: 0.5rem; | ||
padding-right: 0.5rem; | ||
padding-bottom: 0.5rem; | ||
font-size: 1rem; | ||
`; | ||
|
||
export function CardVideoBottom({ title, description }) { | ||
function trucateText(text) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function can live outside |
||
const maxLength = 50; | ||
return text.length <= maxLength ? text : `${text.substring(0, maxLength)}...`; | ||
} | ||
|
||
return ( | ||
<> | ||
<CardVideoBottomContainer> | ||
<CardVideoTitle>{title}</CardVideoTitle> | ||
<CardVideoDescription>{trucateText(description)}</CardVideoDescription> | ||
</CardVideoBottomContainer> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import CardVideoDisplayer from './CardVideo.component'; | ||
|
||
describe('navbar', () => { | ||
beforeEach(() => { | ||
const videos = [ | ||
{ | ||
etag: 'sadlkjsakdljsa', | ||
snippet: { | ||
title: 'Wizeline', | ||
description: 'hlksjdakjskldja asjdaks', | ||
thumbnails: { | ||
high: { | ||
url: | ||
'https://yt3.ggpht.com/ytc/AAUvwnighSReQlmHl_S_vSfvnWBAG5Cw4A0YxtE0tm5OpQ=s800-c-k-c0xffffffff-no-rj-mo', | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
render(<CardVideoDisplayer videos={videos} />); | ||
}); | ||
|
||
test('should contains a title', () => { | ||
const title = screen.queryByText('Wizeline'); | ||
|
||
expect(title).toBeInTheDocument(); | ||
}); | ||
|
||
test('should contains a img', () => { | ||
const img = screen.queryByText('hlksjdakjskldja asjdaks'); | ||
|
||
expect(img).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default, CardVideo } from './CardVideo.component'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createContext } from 'react'; | ||
|
||
const ThemeContext = createContext({}); | ||
|
||
export default ThemeContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createContext } from 'react'; | ||
|
||
const VideoContext = createContext({}); | ||
|
||
export default VideoContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createContext } from 'react'; | ||
|
||
const VideoFavoriteContext = createContext({}); | ||
|
||
export default VideoFavoriteContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import styled from 'styled-components'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
const LinkVideo = styled(Link)` | ||
text-decoration: none; | ||
`; | ||
|
||
export default LinkVideo; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this empty fragment
<>
is necessary here