forked from Isalafont/videos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Search Bar Add Axios to fetch Youtube API Add Style with semantic UI display youtube thumbnails and name with videoList and VideoItem components Add VideoItem css Add VideoDetails Component to add Callbacks and display VideoDetail in App Add some style to VideoDetails
- Loading branch information
Showing
19 changed files
with
177 additions
and
118 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
import axios from 'axios'; | ||
|
||
const KEY = 'AIzaSyBJDGB39IlFbvrMJ1rC8PIIzvsXePaKSi8'; | ||
|
||
export default axios.create({ | ||
baseURL: 'https://www.googleapis.com/youtube/v3', | ||
params: { | ||
part: 'snippet', | ||
type: 'video', | ||
maxResults: 5, | ||
key: KEY, | ||
}, | ||
}); | ||
|
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,38 @@ | ||
import React from 'react'; | ||
import SearchBar from './SearchBar'; | ||
import youtube from '../apis/youtube'; | ||
import VideoList from './VideoList'; | ||
import VideoDetail from './VideoDetail'; | ||
|
||
class App extends React.Component { | ||
state = { videos: [], selectedVideo: null }; | ||
|
||
onTermSubmit = async term => { | ||
const response = await youtube.get('/search', { | ||
params: { | ||
q: term, | ||
} | ||
}); | ||
|
||
this.setState({ videos: response.data.items }); | ||
}; | ||
|
||
onVideoSelect = (video) => { | ||
this.setState({ selectedVideo: video }) | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div className="ui container" style={{ marginTop: '30px' }}> | ||
<SearchBar onFormSubmit={this.onTermSubmit} /> | ||
<VideoDetail video={this.state.selectedVideo} /> | ||
<VideoList | ||
onVideoSelect={this.onVideoSelect} | ||
videos={this.state.videos} | ||
/> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default App; |
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,38 @@ | ||
import React from 'react'; | ||
|
||
class SearchBar extends React.Component { | ||
state = { term: '' }; | ||
|
||
onInputChange = (event) => { | ||
this.setState({ term: event.target.value }) | ||
}; | ||
|
||
onFormSubmit = event =>{ | ||
event.preventDefault(); | ||
|
||
this.props.onFormSubmit(this.state.term) | ||
}; | ||
|
||
render () { | ||
return ( | ||
<div className="search-bar ui segment"> | ||
<form onSubmit={this.onFormSubmit} className="ui form"> | ||
<div className="field"> | ||
<label>Video Search</label> | ||
<div className="ui icon input"> | ||
<input | ||
className="prompt" | ||
type="text" placeholder="Search videos..." | ||
value={this.state.term} | ||
onChange={this.onInputChange} | ||
/> | ||
<i className="search icon"></i> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default SearchBar; |
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,18 @@ | ||
import React from "react"; | ||
|
||
const VideoDetail = ({ video }) => { | ||
if (!video) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
return ( | ||
<div> | ||
<div className="ui segment"> | ||
<h4 className="ui header">{video.snippet.title}</h4> | ||
<p className="">{video.snippet.description}</p> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default VideoDetail; |
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,9 @@ | ||
.video-item { | ||
display: flex !important; | ||
align-items: center; | ||
cursor: pointer; | ||
} | ||
|
||
.video-item.item img { | ||
max-width: 180px; | ||
} |
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,15 @@ | ||
import './VideoItem.css'; | ||
import React from 'react'; | ||
|
||
const VideoItem = ({ video, onVideoSelect }) => { | ||
return ( | ||
<div onClick={() => onVideoSelect(video)} className='video-item item'> | ||
<img className='ui image' alt={video.snippet.description} src={video.snippet.thumbnails.medium.url} /> | ||
<div className='content'> | ||
<div className='header'>{video.snippet.title} </div> | ||
</div> | ||
</div> | ||
) | ||
}; | ||
|
||
export default VideoItem; |
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,12 @@ | ||
import React from 'react'; | ||
import VideoItem from './VideoItem'; | ||
|
||
const VideoList = ({ videos, onVideoSelect }) => { | ||
const renderedList = videos.map((video) => { | ||
return <VideoItem onVideoSelect={onVideoSelect} video={video} />; | ||
}); | ||
|
||
return <div className='ui relaxed divided list'>{renderedList}</div> | ||
}; | ||
|
||
export default VideoList; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,17 +1,8 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import './index.css'; | ||
import App from './App'; | ||
import reportWebVitals from './reportWebVitals'; | ||
import ReactDOM from 'react-dom'; | ||
import App from './components/App'; | ||
|
||
const root = ReactDOM.createRoot(document.getElementById('root')); | ||
root.render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode> | ||
); | ||
|
||
// If you want to start measuring performance in your app, pass a function | ||
// to log results (for example: reportWebVitals(console.log)) | ||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals | ||
reportWebVitals(); | ||
ReactDOM.render( | ||
<App />, | ||
document.querySelector('#root') | ||
); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.