-
Notifications
You must be signed in to change notification settings - Fork 52
Challenge 3 #48
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
base: master
Are you sure you want to change the base?
Challenge 3 #48
Changes from all commits
8cc4c26
d40b158
01ee58c
ecdb29e
f5f05c3
af685e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import axios from 'axios'; | ||
|
|
||
| const KEY = 'AIzaSyAKlMA9FgSpXSkjxhs69n6zsBOPhcHtiKA'; | ||
|
|
||
| export default axios.create({ | ||
| baseURL: 'https://www.googleapis.com/youtube/v3', | ||
| params: { | ||
| part: 'snippet', | ||
| maxResults: 5, | ||
| key: KEY, | ||
| }, | ||
| }); | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import React, { useState, useEffect } from 'react'; | ||
| import NavBar from '../NavBar'; | ||
| import HomePage from '../../pages/Home'; | ||
| import youtube from '../../apis/youtube'; | ||
|
|
||
| function App() { | ||
| const [search, setSearch] = useState('Wizeline'); | ||
| const [videos, setVideos] = useState([]); | ||
|
|
||
| const handleSearch = (e) => { | ||
| setSearch(e.target.value); | ||
| console.log(search); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| async function fetchData() { | ||
| const response = await youtube.get('/search', { | ||
| params: { | ||
| q: search, | ||
| }, | ||
| }); | ||
| console.log(response.data.items); | ||
| setVideos(response.data.items); | ||
| } | ||
| fetchData(); | ||
| }, [search]); | ||
| console.log(videos); | ||
| return ( | ||
| <div> | ||
| <NavBar search={handleSearch} /> | ||
| <HomePage videos={videos} /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default App; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| export { default } from './App.component'; | ||
| export { default } from './App'; |
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import React from 'react'; | ||
| import styled from 'styled-components'; | ||
|
|
||
| const InputSearchStyled = styled.div` | ||
| margin-left: 50px; | ||
| `; | ||
|
|
||
| export default function InputSearch({ search }) { | ||
| return ( | ||
| <InputSearchStyled> | ||
| <input type="text" placeholder="Search" onChange={search} /> | ||
| </InputSearchStyled> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './InputSearch'; |
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import React from 'react'; | ||
| import { FcManager } from 'react-icons/fc'; | ||
| import InputSearch from '../InputSearch'; | ||
| import { NavBarStyled } from './NavBar.styles'; | ||
|
|
||
| function NavBar({ search }) { | ||
| return ( | ||
| <NavBarStyled> | ||
| <InputSearch search={search} /> | ||
| <div> | ||
| <FcManager size="60" /> | ||
| </div> | ||
| </NavBarStyled> | ||
| ); | ||
| } | ||
|
|
||
| export default NavBar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import styled from 'styled-components'; | ||
|
|
||
| export const NavBarStyled = styled.div` | ||
| background-color: #5472ba; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: space-between; | ||
| `; | ||
|
|
||
| export const NavRightIconStyled = styled.div``; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './NavBar'; |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import React from 'react'; | ||
| import { Container, Title } from './VideoCard.styles'; | ||
|
|
||
| const VideoCard = ({ video, handleVideoSelected }) => { | ||
| return ( | ||
| <Container> | ||
| <div role="button"> | ||
| <img alt={video.snippet.description} src={video.snippet.thumbnails.default.url} /> | ||
| <div> | ||
| <Title>{video.snippet.title}</Title> | ||
| </div> | ||
| </div> | ||
| <button type="button" onClick={() => handleVideoSelected(video)}> | ||
| View details | ||
| </button> | ||
| </Container> | ||
| ); | ||
| }; | ||
|
|
||
| export default VideoCard; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import styled from 'styled-components'; | ||
|
|
||
| export const Container = styled.div` | ||
| border-bottom: 1px solid #cccccc; | ||
| border-radius: 5px; | ||
| padding: 20px; | ||
| text-align: left; | ||
| :hover { | ||
| background-color: #374b7a; | ||
| } | ||
| `; | ||
|
|
||
| export const Title = styled.div` | ||
| color: white; | ||
| `; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './VideoCard'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import React from 'react'; | ||
| import styled from 'styled-components'; | ||
|
|
||
| const VideoStyled = styled.div` | ||
| .video { | ||
| margin-top: 50px; | ||
| width: 100%; | ||
| height: 300px; | ||
| } | ||
| `; | ||
| const Title = styled.h4` | ||
| color: #b9b1b1; | ||
| `; | ||
|
|
||
| const VideoDetail = ({ video }) => { | ||
| if (!video) { | ||
| return ( | ||
| <div> | ||
| <Title>Select a video</Title> | ||
| </div> | ||
| ); | ||
| } | ||
| const videoSrc = `https://www.youtube.com/embed/${video.id.videoId}`; | ||
| return ( | ||
| <VideoStyled> | ||
| <iframe className="video" src={videoSrc} title="Video" /> | ||
|
|
||
| <div> | ||
| <Title>{video.snippet.title}</Title> | ||
| <Title>{video.snippet.description}</Title> | ||
| </div> | ||
| </VideoStyled> | ||
| ); | ||
| }; | ||
|
|
||
| export default VideoDetail; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './VideoDetail'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import React from 'react'; | ||
| import styled from 'styled-components'; | ||
| import VideoCard from '../VideoCard'; | ||
|
|
||
| const VideoListContainer = styled.div` | ||
| text-align: center; | ||
| `; | ||
|
|
||
| export default function VideoList({ videos, handleVideoSelected }) { | ||
| if (!videos) { | ||
| return <div />; | ||
| } | ||
| const renderedVideos = videos.map((video) => { | ||
| return ( | ||
| <VideoCard | ||
| key={Math.random()} | ||
| video={video} | ||
| handleVideoSelected={handleVideoSelected} | ||
| /> | ||
| ); | ||
| }); | ||
| return <VideoListContainer>{renderedVideos}</VideoListContainer>; | ||
|
Comment on lines
+13
to
+22
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. It is common to see the map usage inside the component without creating a variable with it. return (
<VideoListContainer>
{videos.map(...
)}
</VideoListContainer> |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './VideoList'; |
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 highly recommend hiding this key on .env file