diff --git a/src/components/App.js b/src/components/App.js index f357b24..228dd59 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -13,6 +13,10 @@ class App extends Component { user: PropTypes.string } + static contextTypes = { + dictionary: PropTypes.object + } + state = { username: 'Roma' } @@ -27,25 +31,26 @@ class App extends Component { render() { console.log('---', 1) + const { dictionary } = this.context return (
-

App name

+

{dictionary.App_name}

- Articles - Filters - Counter - Comments + {dictionary.Articles} + {dictionary.Filters} + {dictionary.Counter} + {dictionary.Comments} -

Add new Article form

}/> +

{dictionary.Add_new_Article_form}

}/> -

Error page

}/> +

{dictionary.Error_page}

}/> -

Nor found

}/> +

{dictionary.Nor_found}

}/>
) diff --git a/src/components/Article/index.js b/src/components/Article/index.js index 1b38661..76ed63e 100644 --- a/src/components/Article/index.js +++ b/src/components/Article/index.js @@ -22,6 +22,10 @@ class Article extends Component { }), } + static contextTypes = { + dictionary: PropTypes.object + } + constructor(props) { super(props) @@ -39,6 +43,7 @@ class Article extends Component { render() { console.log('---', 4) const {article, isOpen, toggleOpen} = this.props + const { dictionary } = this.context if (!article) return null return ( @@ -46,10 +51,10 @@ class Article extends Component {

{article.title}

- if (!articles.length) return

No Articles

+ if (!articles.length) return

{this.context.dictionary.No_Articles}

const articleElements = articles.map((article) =>
  • {article.title}
  • ) @@ -43,4 +47,4 @@ export default withRouter(connect(state => { loading: articlesLoadingSelector(state), // router: state.router } -}, { loadAllArticles })(ArticleList)) \ No newline at end of file +}, { loadAllArticles }, null, { pure: false })(ArticleList)) \ No newline at end of file diff --git a/src/components/CommentList.js b/src/components/CommentList.js index c468574..1ccc103 100644 --- a/src/components/CommentList.js +++ b/src/components/CommentList.js @@ -18,7 +18,8 @@ class CommentList extends Component { static contextTypes = { store: PropTypes.object, router: PropTypes.object, - user: PropTypes.string + user: PropTypes.string, + dictionary: PropTypes.object } componentWillReceiveProps({ isOpen, article, loadArticleComments }) { @@ -28,13 +29,13 @@ class CommentList extends Component { } render() { - console.log('---', 'context: ', this.context) const {isOpen, toggleOpen} = this.props - const text = isOpen ? 'hide comments' : 'show comments' + const {dictionary} = this.context + const text = isOpen ? dictionary.hide_comments : dictionary.show_comments return (
    -

    User: {this.context.user}

    +

    {this.context.dictionary.User}: {this.context.user}

    {this.getBody()}
    ) @@ -50,7 +51,7 @@ class CommentList extends Component { - ) :

    No comments yet

    + ) :

    {this.context.dictionary.No_comments_yet}

    return (
    diff --git a/src/components/Menu/index.js b/src/components/Menu/index.js index 096e674..52bbd70 100644 --- a/src/components/Menu/index.js +++ b/src/components/Menu/index.js @@ -7,10 +7,14 @@ class Menu extends Component { }; + static contextTypes = { + dictionary: PropTypes.object + } + render() { return (
    -

    Main menu:

    +

    {this.context.dictionary.Main_menu}:

    {this.props.children}
    ) diff --git a/src/components/Root.js b/src/components/Root.js new file mode 100644 index 0000000..2f566c8 --- /dev/null +++ b/src/components/Root.js @@ -0,0 +1,26 @@ +import React, { Component } from 'react' +import PropTypes from 'prop-types' +import App from './App' +import dictionary from '../dictionary' + +class Root extends Component { + static childContextTypes = { + dictionary: PropTypes.object + } + + getChildContext() { + return { + dictionary + } + } + + render() { + return ( +
    + +
    + ) + } +} + +export default Root \ No newline at end of file diff --git a/src/components/UserForm.js b/src/components/UserForm.js index 9a96e38..c99ae25 100644 --- a/src/components/UserForm.js +++ b/src/components/UserForm.js @@ -1,9 +1,14 @@ import React, { Component } from 'react' +import PropTypes from 'prop-types' class UserForm extends Component { static propTypes = { - }; + } + + static contextTypes = { + dictionary: PropTypes.object + } state = { user: '' @@ -13,7 +18,7 @@ class UserForm extends Component { const {value} = this.props return (
    - Username: + {this.context.dictionary.Username}:
    ) } diff --git a/src/components/common/Loader.js b/src/components/common/Loader.js index 7577062..3bd2bdc 100644 --- a/src/components/common/Loader.js +++ b/src/components/common/Loader.js @@ -1,13 +1,17 @@ import React from 'react' import PropTypes from 'prop-types' -function Loader(props) { +function Loader(props, {dictionary}) { return ( -

    Loading...

    +

    {dictionary.Loading}...

    ) } Loader.propTypes = { } +Loader.contextTypes = { + dictionary: PropTypes.object +} + export default Loader \ No newline at end of file diff --git a/src/components/routes/ArticleList.js b/src/components/routes/ArticleList.js index 3cceedd..03111db 100644 --- a/src/components/routes/ArticleList.js +++ b/src/components/routes/ArticleList.js @@ -2,17 +2,22 @@ import React, { Component } from 'react' import ArticleList from '../ArticleList' import Article from '../Article' import {Route} from 'react-router-dom' +import PropTypes from 'prop-types' class ArticleListPage extends Component { static propTypes = { - }; + } + + static contextTypes = { + dictionary: PropTypes.object + } render() { console.log('---', 2) return (
    -

    Article list:

    +

    {this.context.dictionary.Article_list}:

    @@ -20,7 +25,7 @@ class ArticleListPage extends Component { } getArticle = ({ match }) => { - if (!match) return

    Please select an article

    + if (!match) return

    {this.context.dictionary.Please_select_an_article}

    console.log('---', 3) return
    } diff --git a/src/dictionary.js b/src/dictionary.js new file mode 100644 index 0000000..7d0f4d4 --- /dev/null +++ b/src/dictionary.js @@ -0,0 +1,23 @@ +export default { + 'App_name': 'Название приложения', + 'Articles': 'Статьи', + 'Filters': 'Фильтры', + 'Counter': 'Счетчик', + 'Comments': 'Комментарии', + 'Add_new_Article_form': 'Добавить новую статью', + 'Error_page': 'Ошбика', + 'Nor_found': 'Не найдено', + 'Main_menu': 'Главное меню', + 'Username': 'Имя пользователя', + 'No_Articles': 'Нет статей', + 'Article_list': 'Список статей', + 'Please_select_an_article': 'Пожалуйста, выберите статью', + 'Loading': 'Загрузка', + 'User': 'Пользователь', + 'No_comments_yet': 'Пока нет комментариев', + 'hide_comments': 'скрыть комментарии', + 'show_comments': 'показать комметарии', + 'close': 'закрыть', + 'open': 'открыть', + 'delete': 'удалить' +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 8615453..c72acb5 100644 --- a/src/index.js +++ b/src/index.js @@ -1,14 +1,16 @@ import React from 'react' import {render} from 'react-dom' import {Provider} from 'react-redux' -import App from './components/App' +import Root from './components/Root' import {ConnectedRouter} from 'react-router-redux' //import {HashRouter, BrowserRouter} from 'react-router-dom' import store from './store' import history from './history' + + render( - + , document.getElementById('container')) \ No newline at end of file diff --git a/src/reducer/articles.js b/src/reducer/articles.js index ebde012..b8d1735 100644 --- a/src/reducer/articles.js +++ b/src/reducer/articles.js @@ -48,7 +48,11 @@ export default (articles = new ReducerRecord(), action) => { return articles .set('loading', false) .set('loaded', true) - .set('entities', arrToMap(response, ArticleRecord)) + .update('entities', (entitiesValue) => { + return entitiesValue.mergeDeepWith((oldValue, newValue, key)=> { + return newValue === null ? oldValue : newValue + }, arrToMap(response, ArticleRecord)) + }) case LOAD_ARTICLE + START: return articles.setIn(['entities', payload.id, 'loading'], true)