-
Notifications
You must be signed in to change notification settings - Fork 14
Hometask5 #76
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?
Hometask5 #76
Changes from all commits
d181650
430a4e6
464d9d1
297041f
575604f
f24a29b
70e3a1e
b9b2119
6422a3b
21cca2b
d10ad46
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 |
|---|---|---|
|
|
@@ -7,14 +7,23 @@ import {filtratedArticlesSelector} from '../selectors' | |
|
|
||
| class ArticleList extends Accordion { | ||
| render() { | ||
| console.log('---', 'rerendering article list') | ||
|
|
||
|
|
||
|
|
||
|
|
||
| console.log('---', 'rerendering article list' ) | ||
| const {articles} = this.props | ||
| console.log(articles) | ||
| if (!articles.length) return <h3>No Articles</h3> | ||
| const articleElements = articles.map((article) => <li key={article.id}> | ||
| <Article article={article} | ||
| const articleElements = Object.values(articles).map((article) => <li key={article.id}> | ||
|
|
||
| <Article | ||
| // article={article} /// это точно наверно не надо | ||
| id={article.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. не очень зачем это |
||
| isOpen={article.id === this.state.openItemId} | ||
| toggleOpen={this.toggleOpenItemMemoized(article.id)} | ||
| /> | ||
|
|
||
| </li>) | ||
| return ( | ||
| <ul> | ||
|
|
@@ -29,9 +38,9 @@ ArticleList.defaultProps = { | |
| articles: [] | ||
| } | ||
|
|
||
| ArticleList.propTypes = { | ||
| articles: PropTypes.array.isRequired | ||
| } | ||
| // ArticleList.propTypes = { | ||
| // articles: PropTypes.array.isRequired | ||
| // } | ||
|
|
||
| export default connect(state => { | ||
| console.log('---', 'connect updated') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { ADD_NEW_COMMENT } from '../constants' | ||
|
|
||
|
|
||
| export default store => next => action => { | ||
| console.log('--- state before: ', store.getState()) | ||
| console.log('--- action: ', action) | ||
|
|
||
| function randId() { | ||
| return (Math.random() * 1e32).toString(36); | ||
| } | ||
|
|
||
| // console.log(randId()) // для теста | ||
|
|
||
|
|
||
| if (action.type === ADD_NEW_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. через мидлвары будет проходить каждый экшин, они должны быть максимально общими, завязывать на конкретные экшины - не лучшее решение |
||
|
|
||
| console.log("new id" + randId()) | ||
|
|
||
| action.payload.id = randId() | ||
|
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, мало-ли что там станут передавать |
||
| } | ||
| console.log('--- new pay ac', action) | ||
|
|
||
|
|
||
| next(action) | ||
| console.log('--- state after: ', store.getState()) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,96 @@ | ||
| import { DELETE_ARTICLE } from '../constants' | ||
| import {normalizedArticles as defaultArticles} from '../fixtures' | ||
| import { DELETE_ARTICLE, ADD_NEW_ID_COMMENT_TO_ARCTICLE } from '../constants' | ||
| import { normalizedArticles as defaultArticles } from '../fixtures' | ||
|
|
||
|
|
||
| const articleMap = defaultArticles.reduce((acc, article) => ({ | ||
| ...acc, | ||
| [article.id]: article | ||
| }), {}) | ||
|
|
||
| export default (articlesState = defaultArticles, action) => { | ||
| const { type, payload } = action | ||
|
|
||
| export default (articlesState = articleMap, action) => { | ||
| const { type, payload } = action | ||
| /// исправить потом | ||
| switch (type) { | ||
| case DELETE_ARTICLE: | ||
| return articlesState.filter(article => article.id !== payload.id) | ||
|
|
||
| const articles = Object.keys(articlesState).reduce((obj, key) => { | ||
| if (key !== payload.id) return {...obj, [key]: articlesState[key] } | ||
| return obj | ||
| }, {}) | ||
|
|
||
| return articles | ||
| case ADD_NEW_ID_COMMENT_TO_ARCTICLE: | ||
| console.log(" тут будет логика добавления ") | ||
| // console.log(" тут произошло обновление " + payload.idarcticle) | ||
| const articleid = payload.idarcticle; | ||
| // console.log(articlesState[id]) | ||
| // console.log(store) | ||
| // console.log(store.getState().comments) | ||
| // console.log( Object.key(store.getState().comments).reduce( ( obj ) ) ) | ||
| console.log(Object.values(store.getState().comments).length) | ||
|
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 l = Object.values(store.getState().comments).length; | ||
|
|
||
| console.log(Object.values(store.getState().comments)[l - 1]) | ||
|
|
||
|
|
||
| const newIdComment = Object.values(store.getState().comments)[l - 1].id | ||
| console.log(newIdComment) | ||
|
|
||
|
|
||
| const art = Object.keys(articlesState).reduce((obj, key) => { | ||
|
|
||
|
|
||
| if (key == articleid) { | ||
| console.log(articlesState[key].comments) | ||
| articlesState[key].comments.push(newIdComment) | ||
| console.log(articlesState[key].comments) | ||
| return {...obj, [key]: articlesState[key] } | ||
| } | ||
| if (key !== articleid) return {...obj, [key]: articlesState[key] } | ||
|
|
||
| }, {}) | ||
|
|
||
| return art | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| // Object.values(store.getState().comments).forEach(element => { | ||
| // console.log(" zlo" + element) | ||
| // }); | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| // return articlesState.filter(article => article.id !== payload.id) | ||
| } | ||
|
|
||
| return articlesState | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| // import {normalizedComments as defaultComments} from '../fixtures' | ||
|
|
||
| // const commentsMap = defaultComments.reduce((acc, comment) => ({ | ||
| // ...acc, | ||
| // [comment.id]: comment | ||
| // }), {}) | ||
|
|
||
| // export default (state = commentsMap, action) => { | ||
| // const { type } = action | ||
|
|
||
| // switch (type) { | ||
|
|
||
| // } | ||
|
|
||
| // return state | ||
| // } | ||
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.
Лучше селектор, который достанет из в виде массива