Skip to content
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

Updated app.js and index.js #295

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3f877ef
Update app.js
vinay72 Jan 30, 2019
6521817
Update and rename app.js to search_bar.js
vinay72 Jan 30, 2019
bbfd853
Update index.js
vinay72 Jan 30, 2019
1e7bbc6
Update index.js
vinay72 Jan 30, 2019
8873ff6
Update search_bar.js
vinay72 Jan 30, 2019
5eda916
Update index.js
vinay72 Jan 30, 2019
c0ba9c2
Update index.js
vinay72 Jan 30, 2019
f2bad4d
Update index.js
vinay72 Jan 30, 2019
3016101
Add files via upload
vinay72 Feb 5, 2019
615f93d
Update video_list.js
vinay72 Feb 5, 2019
88adba6
Update index.js
vinay72 Feb 5, 2019
4763c06
Update video_list.js
vinay72 Feb 5, 2019
b3c2e66
Update video_list.js
vinay72 Feb 5, 2019
dcd129e
Add files via upload
vinay72 Feb 5, 2019
3baba19
Update video_list.js
vinay72 Feb 5, 2019
fa1d010
Update video_list_item.js
vinay72 Feb 7, 2019
7c17c55
Add files via upload
vinay72 Feb 7, 2019
2d618e3
Update index.js
vinay72 Feb 7, 2019
19bb0a0
Update video_detail.js
vinay72 Feb 7, 2019
1b51d38
Update index.js
vinay72 Feb 8, 2019
c728770
Update index.js
vinay72 Feb 8, 2019
e0df045
Update video_list.js
vinay72 Feb 8, 2019
9781a18
Update video_list_item.js
vinay72 Feb 8, 2019
344c987
Update style.css
vinay72 Feb 8, 2019
382fb76
Update search_bar.js
vinay72 Feb 8, 2019
74ca8de
Update index.js
vinay72 Feb 8, 2019
6feaa5f
Update search_bar.js
vinay72 Feb 8, 2019
a2d312a
Update index.js
vinay72 Feb 8, 2019
3a3cc3c
Update index.js
vinay72 Feb 8, 2019
c10b684
Update index.js
vinay72 Feb 11, 2019
8bb066e
Add files via upload
vinay72 Feb 21, 2019
22e71c5
Update README.md
vinay72 Feb 21, 2019
45d7fcc
Update README.md
vinay72 Feb 21, 2019
3d5ddba
Update README.md
vinay72 Apr 22, 2019
59f65bb
Update README.md
vinay72 Apr 22, 2019
7c0df95
Add files via upload
vinay72 May 28, 2019
e666981
Update README.md
vinay72 May 28, 2019
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Interested in learning [Redux](https://www.udemy.com/react-redux/)?

### OutPut
(https://github.com/vinay72/ReduxSimpleStarter/blob/master/v2.png)

### Getting Started

There are two methods for getting started with this repo.
Expand Down
9 changes: 0 additions & 9 deletions src/components/app.js

This file was deleted.

27 changes: 27 additions & 0 deletions src/components/search_bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { Component } from 'react';

class SearchBar extends Component {

constructor(props) {
super(props);

this.state = { term : ''};
}
render(){
return(
<div className="search-bar">
<input
value = {this.state.term}
onChange={event => this.onInputChange(event.target.value) }/>
</div>
);
}


onInputChange(term){
this.setState({term});
this.props.onSearchTermChange(term);
}

}
export default SearchBar;
24 changes: 24 additions & 0 deletions src/components/video_detail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';

const VideoDetail = ({video}) => {
if(!video){
return <div>Loading...</div>;
}

const videoId = video.id.videoId;
const url = `https://www.youtube.com/embed/${videoId}`;

return(
<div className = "video-detail col-md-8">
<div className = "embed-responsive embed-responsive-16by9">
<iframe className = "embed-responsive-item" src={url}></iframe>
</div>
<div className = "details">
<div>{video.snippet.title}</div>
<div>{video.snippet.description}</div>
</div>
</div>
)
};

export default VideoDetail;
22 changes: 22 additions & 0 deletions src/components/video_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import VideoListItem from './video_list_item';

const VideoList = (props) => {
const videoItems = props.videos.map((video) => {
return (
<VideoListItem
onVideoSelect={props.onVideoSelect}
key={video.etag}
video={video} />
):
});
});

return(
<ul className="col-md-4 list-group">
{videoItems}
</ul>
);
};

export default VideoList;
21 changes: 21 additions & 0 deletions src/components/video_list_item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';

const VideoListItem = ({video}) => {
const imageUrl = video.snippet.thumbnails.default.url;
return(
<li onClick={() => onVideoSelect(video)} className="list-group-item">
<div className="video-list media">
<div className="media-left">
<img className="media-object" src={imageUrl}/>
</div>
<div className="meida-body">
<div className="media-heading">
{video.snippet.title}
</div>
</div>
</div>
</li>
);
};

export default VideoListItem;
60 changes: 49 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
import React from 'react';
import _ from 'lodash';
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import SearchBar from './components/search_bar';
import YTSearch from 'youtube-api-search';
import VideoList from './components/video_list';
import VideoDetail from './components/video_detail';
const API_KEY = 'AIzaSyBZO62YgvAL3d0JIJnT5VQssG_jWV-94sg';

import App from './components/app';
import reducers from './reducers';
// Create a new Component. This component should produce
// some HTML

const createStoreWithMiddleware = applyMiddleware()(createStore);
class App extends Component {

ReactDOM.render(
<Provider store={createStoreWithMiddleware(reducers)}>
<App />
</Provider>
, document.querySelector('.container'));
constructor(props){
super(props);

this.state = {
videos:[],
selectedVideo: null
};

this.videoSearch('steve jobs');
}

videoSearch(term) {

YTSearch({key: API_KEY, term: term}, (videos) => {
this.setState({
videos: videos,
selectedVideo: videos[0]
});
//this.setState({ videos: videos});
});
}


render() {
const videoSearch = _.debounce((term) => {this.videoSearch(term), 300 } )
return (
<div>
<SearchBar onSearchTermChange={videoSearch}/>
<VideoDetail video={this.state.selectedVideo} />
<VideoList
onVideoSelect={selectedVideo => this.setState({selectedVideo})}
videos={this.state.videos} />
</div>
);
}
}


ReactDOM.render(<App />, document.querySelector('.container'));
22 changes: 22 additions & 0 deletions style/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.search-bar{
margin: 20px;
text-align: center;
}
.search-bar input{
width: 75%;
}
.video-itm img{
max-width: 64px;
}
.video-detail .details{
margin-top: 10px;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
}
.list-group-item{
cursor:pointer;
}
.list-group-item:hover{
background-color: #eee;
}
Binary file added v1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added v2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.