-
Notifications
You must be signed in to change notification settings - Fork 14
HT5 #77
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?
HT5 #77
Changes from all commits
d06921d
e480c9e
a10302d
4ac3dde
a8e9176
e1ef14a
be027ed
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 |
|---|---|---|
|
|
@@ -8,16 +8,18 @@ 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 => ({ | ||
| label: article.title, | ||
| value: article.id | ||
| // console.log(articles) | ||
|
|
||
| const options = Object.values(articles).map(({title, id}) => ({ | ||
|
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: title, | ||
| value: id | ||
| })) | ||
|
|
||
| return <Select | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import {ADD_COMMENT} from '../constants' | ||
|
|
||
| const generateRandomId = (num = 10, str = '') => num ? generateRandomId(num - 1, str += String.fromCharCode(Math.round(Math.random() * 25) + 65)) : str; | ||
| // можно добавить проверку на id, чтобы не было повторений, но это потом | ||
|
|
||
| export default store => next => action => { | ||
| if (action.type === ADD_COMMENT) { | ||
|
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. через мидлвары будет проходить каждый экшин, они должны быть максимально общими, завязывать на конкретные экшины - не лучшее решение |
||
| action.payload.id = generateRandomId(); | ||
|
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. лучше не мутировать payload, мало-ли что там станут передавать |
||
| } | ||
| next(action) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,31 @@ | ||
| import { DELETE_ARTICLE } from '../constants' | ||
| import { DELETE_ARTICLE, ADD_COMMENT } from '../constants' | ||
| import {normalizedArticles as defaultArticles} from '../fixtures' | ||
|
|
||
| export default (articlesState = defaultArticles, action) => { | ||
| const { type, payload } = action | ||
| const articlesMap = defaultArticles.reduce((acc, article) => ( | ||
| article.comments = article.comments || [], | ||
| {...acc, [article.id]: article} | ||
| ), {}); | ||
|
|
||
| export default (articlesState = articlesMap, action) => { | ||
| const { type, payload } = action; | ||
|
|
||
| switch (type) { | ||
| case DELETE_ARTICLE: | ||
| return articlesState.filter(article => article.id !== payload.id) | ||
| const newState = {...articlesState}; | ||
| delete newState[payload.id]; | ||
| return newState; | ||
|
|
||
| case ADD_COMMENT: | ||
| const targetArticle = {...articlesState[payload.targetArticle]}; | ||
| targetArticle.comments = [...targetArticle.comments, payload.id]; | ||
|
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. comments может быть undefined |
||
|
|
||
| return { | ||
| ...articlesState, | ||
| [payload.targetArticle]: targetArticle | ||
| } | ||
|
|
||
| } | ||
|
|
||
| return articlesState | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import {createStore, applyMiddleware, compose} from 'redux' | ||
| import rootReducer from '../reducer' | ||
| import logger from '../middlewares/logger' | ||
| import randomizer from '../middlewares/randomizer' | ||
|
|
||
| const composeEnhancers = | ||
| typeof window === 'object' && | ||
|
|
@@ -10,7 +11,7 @@ const composeEnhancers = | |
| }) : compose | ||
|
|
||
| const enhancer = composeEnhancers( | ||
| applyMiddleware(logger) | ||
| applyMiddleware(logger, randomizer) | ||
|
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. лучше логгер в конце ставить |
||
| ) | ||
| const store = createStore(rootReducer, enhancer) | ||
|
|
||
|
|
||
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.
Не понял зачем это