-
Notifications
You must be signed in to change notification settings - Fork 20
Hw 7 #66
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?
Hw 7 #66
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,9 @@ class Article extends Component { | |
| state = { | ||
| error: null | ||
| } | ||
| static contextTypes = { | ||
| glossary: PropTypes.object | ||
|
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. тут и в других местах: лучше сделай декоратор либо компонент-обертку для локализации, чтоб не обращатся каждый раз к контексту, иначе потом тяжело будет что-либо поменять
Author
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. я правильно понимаю: вынести в контекст, а потом через props-ы декоратора передавать? |
||
| } | ||
|
|
||
| componentDidCatch(error) { | ||
| console.log('---', error) | ||
|
|
@@ -28,6 +31,7 @@ class Article extends Component { | |
| if (this.state.error) return <h2>{this.state.error.message}</h2> | ||
|
|
||
| const { isOpen, article, onButtonClick } = this.props | ||
| const { glossary } = this.context | ||
| if (!article) return null | ||
|
|
||
| return ( | ||
|
|
@@ -38,10 +42,10 @@ class Article extends Component { | |
| className = "test__article--button" | ||
| onClick={() => onButtonClick(article.id)} | ||
| > | ||
| {isOpen ? 'close' : 'open'} | ||
| {isOpen ? glossary['close'] : glossary['show']} | ||
| </button> | ||
| <button onClick = {this.handleDelete}> | ||
| delete me | ||
| {glossary['delete']} | ||
| </button> | ||
| </h2> | ||
| <CSSTransition | ||
|
|
@@ -64,7 +68,7 @@ class Article extends Component { | |
| if (article.loading) return <Loader/> | ||
|
|
||
| return ( | ||
| <section className = "test__article--body"> | ||
| <section key={article.id} className = "test__article--body"> | ||
| {article.text} | ||
| <CommentList article = {article}/> | ||
| </section> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import React, { Component } from 'react' | ||
| import PropTypes from 'prop-types' | ||
|
|
||
| class HandleLng extends Component { | ||
| static propTypes = { | ||
| val: PropTypes.number, | ||
| onChange: PropTypes.func | ||
| }; | ||
|
|
||
| render () { | ||
| const langids = ["langEN", "langRU", "langDE"] | ||
| const langlbls = ['English', "Русский", "Deutsch"] | ||
|
|
||
| const radioElements = langlbls.map( (l, index) => { | ||
| const {val, onChange} = this.props | ||
| return ( | ||
| <span key={langids[index]}> | ||
| <input type="radio" name="language" value={index} id={langids[index]} | ||
| defaultChecked = {val === index} | ||
| onClick={onChange}/> | ||
| <label htmlFor={langids[index]}>{l}</label> | ||
| </span> | ||
| ) | ||
| }) | ||
|
|
||
| return ( | ||
| <p> | ||
| {radioElements} | ||
| </p> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export default HandleLng |
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.
почему бы не в конструкторе? А еще лучше в Provider вынести