From f00980f7489e672e8d143f416a2df49793bf9815 Mon Sep 17 00:00:00 2001 From: annakovarskaya Date: Tue, 20 Mar 2018 20:57:58 +0000 Subject: [PATCH] ht 7.1 --- src/App.js | 35 ++++++++++++++++++++++++---- src/components/comment-list/index.js | 9 ++++--- src/components/routes/articles.js | 10 ++++++-- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/App.js b/src/App.js index a650aee..57fe441 100644 --- a/src/App.js +++ b/src/App.js @@ -14,16 +14,35 @@ class App extends Component { }; static childContextTypes = { - user: PropTypes.string + user: PropTypes.string, + lang: PropTypes.string, + vocab: PropTypes.object } state = { - username: '' + username: '', + language: 'en', + vocabulary: { + 'counter':{ + 'en':'counter', + 'ru':'счетчик' + }, + 'hide comments':{ + 'en':'hide comments', + 'ru':'скрыть комментарии' + }, + 'Articles page':{ + 'en':'Articles page', + 'ru':'Страница статей' + } + } } getChildContext() { return { - user: this.state.username + user: this.state.username, + lang: this.state.language, + vocab: this.state.vocabulary } } @@ -31,9 +50,14 @@ class App extends Component { console.log('---', 'rendering App') return (
+ Language: + English + Russian + +
    -
  • counter
  • +
  • {this.state.vocabulary['counter'][this.state.language]}
  • filters
  • articles
  • comments
  • @@ -53,6 +77,7 @@ class App extends Component { } handleUserChange = username => this.setState({ username }) + handleLanguageChange = changeEvent => this.setState({ language: changeEvent.target.value }) } -export default App \ No newline at end of file +export default App diff --git a/src/components/comment-list/index.js b/src/components/comment-list/index.js index 7bb587e..22849fb 100644 --- a/src/components/comment-list/index.js +++ b/src/components/comment-list/index.js @@ -24,7 +24,10 @@ class CommentList extends Component { static contextTypes = { store: PropTypes.object, router: PropTypes.object, - user: PropTypes.string + user: PropTypes.string, + vocab: PropTypes.object, + lang: PropTypes.string + } componentWillReceiveProps({ isOpen, article, loadArticleComments }) { @@ -36,7 +39,7 @@ class CommentList extends Component { render() { const {isOpen, toggleOpen} = this.props console.log('---', 'rendering CommentList') - const text = isOpen ? 'hide comments' : 'show comments' + const text = isOpen ? this.context.vocab['hide comments'][this.context.lang] : 'show comments' return (
    @@ -85,4 +88,4 @@ class CommentList extends Component { } -export default connect(null, { loadArticleComments }, null, { pure: false })(toggleOpen(CommentList)) \ No newline at end of file +export default connect(null, { loadArticleComments }, null, { pure: false })(toggleOpen(CommentList)) diff --git a/src/components/routes/articles.js b/src/components/routes/articles.js index 7d866b8..6029d98 100644 --- a/src/components/routes/articles.js +++ b/src/components/routes/articles.js @@ -2,17 +2,23 @@ import React, { Component } from 'react' import { Route } from 'react-router-dom' import ArticleList from '../article-list' import Article from '../article' +import PropTypes from 'prop-types' class ArticlesRoute extends Component { static propTypes = { }; + static contextTypes = { + vocab: PropTypes.object, + lang: PropTypes.string + }; + render() { console.log('---', 'rendering Articles Page') return (
    -

    Articles page

    +

    {this.context.vocab['Articles page'][this.context.lang]}

    @@ -26,4 +32,4 @@ class ArticlesRoute extends Component { } } -export default ArticlesRoute \ No newline at end of file +export default ArticlesRoute