-
Notifications
You must be signed in to change notification settings - Fork 20
HT6 #56
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?
HT6 #56
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import React, { Component } from 'react' | ||
| import {connect} from 'react-redux' | ||
| import { NavLink, Route } from 'react-router-dom' | ||
| import Comment from '../comment' | ||
| import Loader from '../loader' | ||
| import { commentPagesSelector, commentsListSelector, commentsTotalSelector } from '../../selectors' | ||
| import { PER_PAGE } from '../../constants' | ||
| import { loadAllComments, loadPageComments } from '../../AC' | ||
|
|
||
| class CommentsRoute extends Component { | ||
| static propTypes = { | ||
|
|
||
| }; | ||
|
|
||
| componentDidMount() { | ||
| const { loadAllComments, loaded} = this.props | ||
| if (!loaded) loadPageComments() | ||
|
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. Работает?
Author
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. Работает.
Author
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. if (!loaded) loadPageComments() лишний.
Author
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. И неправильный к тому же. Правильный loadPageComments(no)
Author
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. То есть, конечно, конкретно этот кусок кода не работает. Работает в целом. Это ошибка. |
||
| } | ||
|
|
||
| render() { | ||
| const { pages, total} = this.props | ||
| const pageCount = Math.ceil(total / PER_PAGE); | ||
| const range = Array.apply(null, Array(pageCount)).map(function (_, i) {return i+1;}); | ||
| const pageElements = range.map(no => | ||
| <li><NavLink to = {`/comments/${no}`} >{no}</NavLink></li> | ||
| ) | ||
| return ( | ||
| <div> | ||
| <h2>Comments page</h2> | ||
| {pageElements} | ||
|
|
||
| {this.getPage()} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| getPage() { | ||
| const {match, loadPageComments} = this.props; | ||
| const no = match.params && match.params.id || '1'; | ||
| const { pages } = this.props | ||
| const page = pages.get(no) | ||
| const { loaded, loading, comments } = page || {} | ||
|
|
||
| if (loading) | ||
| return <Loader /> | ||
|
|
||
| if (!loaded) { | ||
| loadPageComments(no) | ||
| return <div></div> | ||
| } | ||
| return <div> {this.getComments(comments)} </div> | ||
| } | ||
|
|
||
| getComments(comments) { | ||
| return ( | ||
| <ul> | ||
| { | ||
| comments.map(id => | ||
| <li key = {id} className = "test__comment-list--item"> | ||
| <Comment id = {id}/> | ||
| </li>) | ||
| } | ||
| </ul> | ||
| ) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| const createMapStateToProps = (state) => ({ | ||
| comments: commentsListSelector(state), | ||
| pages: commentPagesSelector(state), | ||
| total: commentsTotalSelector(state), | ||
| }) | ||
|
|
||
| export default connect(createMapStateToProps, {loadAllComments, loadPageComments})(CommentsRoute) | ||
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.
это зачем?