-
Notifications
You must be signed in to change notification settings - Fork 17
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
Ht4 #38
base: master
Are you sure you want to change the base?
Ht4 #38
Changes from all commits
f60bc4a
86dde51
1ed30aa
9dcfb71
ee00e77
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,56 @@ | ||
import React, { PureComponent } from 'react' | ||
import PropTypes from 'prop-types' | ||
import './style.css' | ||
|
||
class NewCommentForm extends PureComponent { | ||
static propTypes = { | ||
onSendComment: PropTypes.func | ||
} | ||
|
||
state = { | ||
user: '', | ||
text: '' | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className="new-comment-form__container"> | ||
<form onSubmit={this.handleSubmit}> | ||
<div className="new-comment-form__user"> | ||
<label>Your name:</label> | ||
<input | ||
type="text" | ||
value={this.state.user} | ||
name="user" | ||
onChange={this.handleChange} | ||
/> | ||
</div> | ||
<div className="new-comment-form__text"> | ||
<textarea | ||
value={this.state.text} | ||
name="text" | ||
onChange={this.handleChange} | ||
/> | ||
</div> | ||
<div className="new-comment-form__button"> | ||
<button type="submit">Send</button> | ||
</div> | ||
</form> | ||
</div> | ||
) | ||
} | ||
|
||
handleChange = (ev) => { | ||
this.setState({ [ev.target.name]: ev.target.value }) | ||
} | ||
|
||
handleSubmit = (ev) => { | ||
ev.preventDefault() | ||
|
||
const { onSendComment } = this.props | ||
|
||
onSendComment && onSendComment(this.state.user, this.state.text) | ||
} | ||
} | ||
|
||
export default NewCommentForm |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.new-comment-form__container { | ||
border: 1px solid gray; | ||
margin-top: 15px; | ||
padding: 20px 15px; | ||
width: 500px; | ||
} | ||
|
||
.new-comment-form__user { | ||
margin-bottom: 10px; | ||
} | ||
|
||
.new-comment-form__user label { | ||
margin-right: 10px; | ||
} | ||
|
||
.new-comment-form__text textarea { | ||
width: 100%; | ||
height: 50px; | ||
} | ||
|
||
.new-comment-form__button { | ||
margin-top: 10px; | ||
text-align: right; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Chance from 'chance' | ||
import { CREATE_COMMENT_TO_ARTICLE } from '../constants' | ||
|
||
export default (store) => (next) => (action) => { | ||
if (action.type === CREATE_COMMENT_TO_ARTICLE) { | ||
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. через мидлвары будет проходить каждый экшин, они должны быть максимально общими, завязывать на конкретные экшины - не лучшее решение |
||
const chance = new Chance() | ||
action.payload.id = chance.guid() | ||
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. лучше не мутировать payload, мало-ли что там станут передавать |
||
} | ||
|
||
next(action) | ||
} |
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.
Лучше селектор, который достанет их в виде массива