Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.

Commit a5e2555

Browse files
authored
Add files via upload
1 parent ab5094e commit a5e2555

28 files changed

+7119
-0
lines changed

notes/learn-redux/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Learn Redux
2+
3+
This is my course for wes bos's learn redux
4+
5+
## Running
6+
7+
First `npm install` to grab all the necessary dependencies.
8+
9+
Then run `npm start` and open <localhost:7770> in your browser.
10+
11+
## Production Build
12+
13+
Run `npm build` to create a distro folder and a bundle.js file.
14+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// increment (increment likes)
2+
export function increment(index) {
3+
return {
4+
type: 'INCREMENT_LIKES',
5+
index
6+
}
7+
}
8+
// add comment
9+
export function addComment(postId, author, comment) {
10+
return {
11+
type: 'ADD_COMMENT',
12+
postId,
13+
author,
14+
comment
15+
}
16+
}
17+
// remove comment
18+
export function removeComment(postId, i) {
19+
return {
20+
type: 'REMOVE_COMMENT',
21+
i,
22+
postId
23+
}
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { bindActionCreators } from 'redux';
2+
import { connect } from 'react-redux';
3+
import * as actionCreators from '../actions/actionCreators';
4+
import Main from './Main';
5+
6+
function mapStateToProps(state) {
7+
return {
8+
posts: state.posts,
9+
comments: state.comments
10+
}
11+
}
12+
13+
function mapDispachToProps(dispatch) {
14+
return bindActionCreators(actionCreators, dispatch);
15+
}
16+
17+
const App = connect(mapStateToProps, mapDispachToProps)(Main);
18+
19+
export default App;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
3+
const Comments = React.createClass({
4+
renderComment(comment, i) {
5+
return (
6+
<div className="comment" key={i}>
7+
<p>
8+
<strong>{comment.user}</strong>
9+
{comment.text}
10+
<button className="remove-comment" onClick={this.props.removeComment.bind(null, this.props.params.postId, i)}>&times;</button>
11+
</p>
12+
</div>
13+
)
14+
},
15+
handleSubmit(e) {
16+
e.preventDefault();
17+
console.log('Submitting the form!');
18+
console.log(this.refs);
19+
const { postId } = this.props.params;
20+
const author = this.refs.comment.value;
21+
const comment = this.refs.comment.value;
22+
this.props.addComment(postId, author, comment);
23+
this.refs.commentForm.reset();
24+
},
25+
26+
render() {
27+
return (
28+
<div className="comments">
29+
{this.props.postComments.map(this.renderComment)}
30+
<form ref="commentForm" className="comment-form" onSumbit={this.handleSubmit}>
31+
<input type="text" ref="author" placeholder="author" />
32+
<input type="text" ref="comment" placeholder="comment" />
33+
<input type="submit" hidden />
34+
</form>
35+
</div>
36+
)
37+
}
38+
});
39+
40+
export default Comments;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import { Link } from 'react-router';
3+
4+
const Main = React.createClass({
5+
render() {
6+
return (
7+
<div>
8+
<h1>
9+
<Link to="/">Reduxstagram</Link>
10+
</h1>
11+
{React.cloneElement(this.props.children, this.props)}
12+
</div>
13+
)
14+
}
15+
});
16+
17+
export default Main;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from 'react';
2+
import { Link } from 'react-router';
3+
import CSSTransitionGroup from 'react-addons-css-transition-group';
4+
5+
const Photo = React.createClass({
6+
render() {
7+
const { post, i, comments } = this.props;
8+
return (
9+
<figure className="grid-figure">
10+
<div className="grid-photo-wrap">
11+
<Link to={`/view/${post.code}`}>
12+
<img src={post.display_src} alt={post.caption} className="grid-photo" />
13+
</Link>
14+
15+
<CSSTransitionGroup transitionName="like" transitionEnterTimeout={500} transitionLeaveTimeout={500}>
16+
<span key={post.likes} className="likes-heart">{post.likes}</span>
17+
</CSSTransitionGroup>
18+
19+
</div>
20+
21+
<figcaption>
22+
<p>{post.caption}</p>
23+
<div className="control-buttons">
24+
<button onClick={this.props.increment.bind(null, i)} className="likes">&hearts; {post.likes}</button>
25+
<Link className="button" to={`/view/${post.code}`}>
26+
<span className="comment-count">
27+
<span className="speech-bubble"></span>
28+
{comments[post.code] ? comments[post.code].length : 0}
29+
</span>
30+
</Link>
31+
</div>
32+
</figcaption>
33+
34+
</figure>
35+
)
36+
}
37+
});
38+
39+
export default Photo;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import Photo from './Photo'
3+
4+
const PhotoGrid = React.createClass({
5+
render() {
6+
return (
7+
<div className="photo-grid">
8+
{this.props.posts.map((post, i) => <Photo {...this.props} key={i} i={i} post={post} />)}
9+
</div>
10+
)
11+
}
12+
});
13+
14+
export default PhotoGrid;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import Photo from './Photo';
3+
import Comments from './Comments';
4+
5+
const Single = React.createClass({
6+
render() {
7+
const { postId } = this.props.params;
8+
const i = this.props.posts.findIndex((post) => post.code === postId);
9+
const post = this.props.posts[i];
10+
const postComments = this.props.comments[postId] || [];
11+
return (
12+
<div className="single-photo">
13+
<Photo i={i} post={post} {...this.props} />
14+
<Comments postComments={postComments} {...this.props} />
15+
</div>
16+
)
17+
}
18+
});
19+
20+
export default Single;

0 commit comments

Comments
 (0)