-
Notifications
You must be signed in to change notification settings - Fork 20
ht4 done #43
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?
ht4 done #43
Changes from all commits
fd553e2
64490bf
b6f6f75
0c4af9b
0e0eaed
4cc4aba
4ba9791
c58ee9a
f200184
9b34db1
78776db
a15bf6c
79bfa4b
12c1204
1874311
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,20 @@ | ||
| import React from 'react' | ||
| import {render, mount} from 'enzyme' | ||
| import Article from './index.js' | ||
| import articles from '../../fixtures' | ||
|
|
||
| describe('Article', () => { | ||
| it('should render Article', () => { | ||
| const wrapper = render(<Article article={articles[0]} onButtonClick={() => console.log('click')} isOpen = {true} />) | ||
|
|
||
| expect(wrapper.find('.test__article--button').length).toEqual(1) | ||
| }) | ||
|
|
||
| it('should open comment on button click', () => { | ||
| const wrapper = mount(<Article article={articles[0]} onButtonClick={() => console.log('click')} isOpen = {true} />) | ||
|
|
||
| wrapper.find('.comments__button').at(0).simulate('click') | ||
|
|
||
| expect(wrapper.find('.comments-list').length).toEqual(1) | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,4 +23,4 @@ class Chart extends Component { | |
| } | ||
| } | ||
|
|
||
| export default Chart | ||
| export default Chart | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,46 @@ | ||
| .comments-enter { | ||
| opacity: 0; | ||
| opacity: 0; | ||
| } | ||
|
|
||
| .comments-enter.comments-enter-active { | ||
| opacity: 1; | ||
| transition: opacity 500ms ease-in; | ||
| opacity: 1; | ||
| transition: opacity 500ms ease-in; | ||
| } | ||
|
|
||
| .comments-leave { | ||
| opacity: 1; | ||
| opacity: 1; | ||
| } | ||
|
|
||
| .comments-leave.comments-leave-active { | ||
| opacity: 0; | ||
| transition: opacity 500ms ease-in; | ||
| } | ||
| opacity: 0; | ||
| transition: opacity 500ms ease-in; | ||
| } | ||
|
|
||
| .comments-list__name{ | ||
| display:block; | ||
| width:200px; | ||
| height:24px; | ||
| padding:0 7px; | ||
| margin-bottom: 10px; | ||
| box-sizing: border-box; | ||
| margin-top: -10px; | ||
| } | ||
|
|
||
| .comments-list__text{ | ||
| display:block; | ||
| width:200px; | ||
| height:100px; | ||
| padding:5px 7px; | ||
| resize:none; | ||
| overfow:hidden; | ||
| margin-bottom: 10px; | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| .comments-list__add{ | ||
| display:block; | ||
| width:200px; | ||
| height:24px; | ||
| text-align:center; | ||
| box-sizing: border-box; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import React, {Component} from 'react' | ||
| import { connect } from 'react-redux' | ||
| import PropTypes from 'prop-types' | ||
| import { addComment } from '../../AC' | ||
|
|
||
| class CommentAddForm extends Component { | ||
| static propTypes = { | ||
| articleId: PropTypes.string.isRequired, | ||
| } | ||
|
|
||
| state = { | ||
| textIsEmpty: true, | ||
| nameIsEmpty: true | ||
| } | ||
|
|
||
| handeChangeName = (e) => { | ||
| e.target.value.trim().length ? this.setState({ nameIsEmpty: false }) : this.setState({ nameIsEmpty: true }) | ||
| } | ||
|
|
||
| handeChangeText = (e) => { | ||
| e.target.value.trim().length ? this.setState({ textIsEmpty: false }) : this.setState({ textIsEmpty: true }) | ||
| } | ||
|
|
||
| handleAddComment = () => { | ||
| const { addComment, articleId } = this.props | ||
| addComment({ | ||
| "user": this.refs.commentName.value, | ||
|
Owner
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. Не трогай ref без крайней необходимости. Храни значения в state |
||
| "text": this.refs.commentText.value | ||
| }, articleId) | ||
|
|
||
| this.refs.commentName.value = '' | ||
|
Owner
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. Не меняй ничего руками в DOM! |
||
| this.refs.commentText.value = '' | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| <div> | ||
| <p><b>Добавить комментарий:</b></p> | ||
| <input | ||
| type="text" | ||
| ref="commentName" | ||
| className="comments-list__name" | ||
| placeholder="Ваше имя" | ||
| onChange = { this.handeChangeName } | ||
| /> | ||
| <textarea | ||
| placeholder="Текст комментария" | ||
| className="comments-list__text" | ||
| ref="commentText" | ||
| onChange = { this.handeChangeText } | ||
| > | ||
| </textarea> | ||
| <button | ||
| className="comments-list__add" | ||
| onClick = { this.handleAddComment } | ||
| disabled = { this.state.textIsEmpty || this.state.nameIsEmpty } | ||
| > | ||
| Добавить | ||
| </button> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| export default connect(null, { addComment })(CommentAddForm) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,14 +9,14 @@ import 'react-select/dist/react-select.css' | |
|
|
||
| class SelectFilter extends Component { | ||
| static propTypes = { | ||
| articles: PropTypes.array.isRequired | ||
| articles: PropTypes.object.isRequired | ||
| }; | ||
|
|
||
| handleChange = selected => this.props.changeSelection(selected.map(option => option.value)) | ||
|
|
||
| render() { | ||
| const { articles, selected } = this.props | ||
| const options = articles.map(article => ({ | ||
| const options = Object.values(articles).map(article => ({ | ||
|
Owner
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. Лучше селектор, который достанет из в виде массива |
||
| label: article.title, | ||
| value: article.id | ||
| })) | ||
|
|
@@ -33,4 +33,4 @@ class SelectFilter extends Component { | |
| export default connect(state => ({ | ||
| selected: state.filters.selected, | ||
| articles: articleListSelector(state) | ||
| }), { changeSelection })(SelectFilter) | ||
| }), { changeSelection })(SelectFilter) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,4 +28,4 @@ class UserForm extends Component { | |
| } | ||
| } | ||
|
|
||
| export default UserForm | ||
| export default UserForm | ||
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.
зачем это?
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.
у меня концептуально в форме кнопка "отправить" становится доступной только при заполнении обоих полей.
Для этого тут и работа с рефами, чтобы данные формы подтягивать и стейт текущего состояния инпутов и все такое прочее.
И обнуление заполненности полей через реф тоже за этим.)
Все равно неверно?)