Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import Filters from './components/filters'
import Counter from './components/counter'
import 'react-select/dist/react-select.css'
import CommentsPage from './components/routes/comments-page'
import dictionary from './dictionary';

class App extends Component {
static propTypes = {
};

static childContextTypes = {
user: PropTypes.string
user: PropTypes.string,
dictionary: PropTypes.object
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше для этого Provider завести

}

state = {
Expand All @@ -23,7 +25,8 @@ class App extends Component {

getChildContext() {
return {
user: this.state.username
user: this.state.username,
dictionary: dictionary
}
}

Expand Down
1 change: 1 addition & 0 deletions src/components/article-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class ArticleList extends Component {

render() {
const { articles, loading } = this.props
console.log('LOADING', loading);
if (loading) return <Loader />
const articleElements = articles.map(article =>
<li key = {article.id} className = "test__article-list--item">
Expand Down
9 changes: 7 additions & 2 deletions src/components/article/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class Article extends Component {
error: null
}

static contextTypes = {
dictionary: PropTypes.object
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут и в других местах: лучше сделай декоратор либо компонент-обертку для локализации, чтоб не обращатся каждый раз к контексту, иначе потом тяжело будет что-либо поменять

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Спасибо

}

componentDidCatch(error) {
console.log('---', error)
this.setState({ error })
Expand All @@ -25,6 +29,7 @@ class Article extends Component {

render() {
console.log('---', 'rendering Article')
const {dictionary: {deleteMe, open, close}} = this.context
if (this.state.error) return <h2>{this.state.error.message}</h2>

const { isOpen, article, onButtonClick } = this.props
Expand All @@ -38,10 +43,10 @@ class Article extends Component {
className = "test__article--button"
onClick={() => onButtonClick(article.id)}
>
{isOpen ? 'close' : 'open'}
{isOpen ? close : open}
</button>
<button onClick = {this.handleDelete}>
delete me
{deleteMe}
</button>
</h2>
<CSSTransition
Expand Down
8 changes: 5 additions & 3 deletions src/components/comment-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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 }) {
Expand All @@ -34,9 +35,10 @@ class CommentList extends Component {
}

render() {
const {isOpen, toggleOpen} = this.props
const {isOpen, toggleOpen} = this.props,
{hideComments, showComments} = this.context;
console.log('---', 'rendering CommentList')
const text = isOpen ? 'hide comments' : 'show comments'
const text = isOpen ? hideComments : showComments;
return (
<div>
<button onClick={toggleOpen} className="test__comment-list--btn">{text}</button>
Expand Down
10 changes: 8 additions & 2 deletions src/components/routes/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@ 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 = {
dictionary: PropTypes.object
}

render() {
console.log('---', 'rendering Articles Page')
return (
<div>
<h2>Articles page</h2>
<h2>{this.context.dictionary.articlePage}</h2>
<ArticleList />
<Route path = {`${this.props.match.path}/:id`} children = {this.getArticle}/>
</div>
)
}

getArticle = ({ match }) => {
if (!match) return <h2>Please select an article</h2>
const {dictionary} = this.context
if (!match) return <h2>{dictionary.pleaseSelectArticle}</h2>

return <Article id = {match.params.id} key = {match.params.id} isOpen />
}
Expand Down
9 changes: 7 additions & 2 deletions src/components/user-form.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import React, { Component } from 'react'
import PropTypes from "prop-types";

class UserForm extends Component {
static propTypes = {

};
}

static contextTypes = {
dictionary: PropTypes.object
}

render() {
return (
<div>
username: <input value = {this.props.value} onChange = {this.handleChange}/>
{this.context.dictionary.username}: <input value = {this.props.value} onChange = {this.handleChange}/>
</div>
)
}
Expand Down
14 changes: 14 additions & 0 deletions src/dictionary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const dictionary = {
username: 'Имя пользователя',
articlesPage: 'Статьи',
pleaseSelectArticle: 'Выберите статью',
loading: 'Загрузка',
hideComments: 'Спрятать коментарии',
showComments: 'Показать комментарии',
articlePage: 'Стараница статей',
deleteMe: 'Удалить',
open: 'Открыть',
close: 'Закрыть'
}

export default dictionary
5 changes: 4 additions & 1 deletion src/middlewares/logger.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import articles from "../reducer/articles";
import comments from "../reducer/comments";

export default store => next => action => {
console.log('---', 'state before: ', store.getState())
console.log('---', 'dispatching action: ', action)

next(action)

console.log('---', 'state after: ', store.getState())
console.log('---', 'state after: ', store.getState().articles.toJS(), store.getState().comments.toJS());
}
4 changes: 2 additions & 2 deletions src/reducer/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
START, SUCCESS, FAIL
} from '../constants'
import { arrToMap } from './utils'
import { Record } from 'immutable'
import { Record, fromJS } from 'immutable'

const ArticleRecord = Record({
id: null,
Expand Down Expand Up @@ -41,7 +41,7 @@ export default (articles = new ReducerState(), action) => {

case LOAD_ALL_ARTICLES + SUCCESS:
return articles
.set('entities', arrToMap(response, ArticleRecord))
.update('entities', entities => entities.merge(arrToMap(response, ArticleRecord), entities))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ты делаешь 2 мерджа

.set('loading', false)
.set('loaded', true)

Expand Down
Loading