Not Found Page
} />
@@ -32,4 +34,5 @@ class App extends Component {
}
}
-export default App
\ No newline at end of file
+export default App
+//export default withRouter(connect(mapStateToProps)(App))
\ No newline at end of file
diff --git a/src/components/routes/comments.js b/src/components/routes/comments.js
new file mode 100644
index 0000000..d50aed1
--- /dev/null
+++ b/src/components/routes/comments.js
@@ -0,0 +1,63 @@
+import React, { Component } from 'react'
+import { Route, NavLink } from 'react-router-dom'
+import { connect } from 'react-redux'
+import Loader from '../loader'
+import { commentListSelector } from '../../selectors'
+import { loadCommentsList } from '../../AC'
+import { LIMIT } from '../../constants'
+
+class CommentsRoute extends Component {
+ componentDidMount(){
+ const {loadCommentsList} = this.props
+ loadCommentsList()
+ }
+ componentWillReceiveProps(){
+ //console.log("need rerender!")
+ }
+ render(){
+ const {total} = this.props
+
+ return (
+
+ { this.getLinks(total) }
+
+
+ )
+ }
+
+ getComments = ({ match }) => {
+ if (!match) return Select comments list
+ const {loadedComments} = this.props
+ if (!loadedComments) return
+ const list = loadedComments[match.params.list - 1]
+ if ( !list || !list.length) return
+ const commentElement = list.map( comment => {
+ return(
+
+ {comment.user}: {comment.text}
+
+ )
+ })
+ return
+ }
+
+ getLinks = (total) => {
+ if (!total) return
+ const count = Math.floor(total/ LIMIT) +( total % LIMIT === 0 ? 0 : 1)
+ const links =(Array.from(Array(count).keys())).map( i => {
+ const p = i + 1
+ return
+ {p}
+
+ })
+ return
+ }
+}
+
+
+export default connect(state => ({
+ loadedComments: commentListSelector(state),
+ total: state.comments.total
+}), { loadCommentsList })(CommentsRoute)
\ No newline at end of file
diff --git a/src/constants/index.js b/src/constants/index.js
index c71387f..6618296 100644
--- a/src/constants/index.js
+++ b/src/constants/index.js
@@ -9,6 +9,8 @@ export const CHANGE_SELECTION = 'CHANGE_SELECTION'
export const CHANGE_DATE_RANGE = 'CHANGE_DATE_RANGE'
export const ADD_COMMENT = 'ADD_COMMENT'
+export const LOAD_COMMENTS = 'LOAD_COMMENTS'
+export const LIMIT = 5
export const START = '_START'
export const SUCCESS = '_SUCCESS'
diff --git a/src/reducer/comments.js b/src/reducer/comments.js
index 6586253..622ebbd 100644
--- a/src/reducer/comments.js
+++ b/src/reducer/comments.js
@@ -1,4 +1,4 @@
-import { ADD_COMMENT, LOAD_ARTICLE_COMMENTS, SUCCESS } from '../constants'
+import { ADD_COMMENT, LOAD_ARTICLE_COMMENTS, LOAD_COMMENTS, START, SUCCESS } from '../constants'
import {Record, OrderedMap} from 'immutable'
import {arrToMap} from './utils'
@@ -9,7 +9,9 @@ const CommentRecord = Record({
})
const ReducerState = Record({
- entities: new OrderedMap({})
+ entities: new OrderedMap({}),
+ loadedComments: [],
+ total: null
})
export default (state = new ReducerState(), action) => {
@@ -25,6 +27,16 @@ export default (state = new ReducerState(), action) => {
case LOAD_ARTICLE_COMMENTS + SUCCESS:
return state.mergeIn(['entities'], arrToMap(response, CommentRecord))
+ case LOAD_COMMENTS + START:
+ let item = state.loadedComments[payload.i - 1]
+ return typeof item === 'undefined' ? state.setIn(['loadedComments', payload.i - 1], false) : state
+
+ case LOAD_COMMENTS + SUCCESS:
+ console.log("SUCCESS load comments: ", response)
+
+ return state.set('total', response.total)
+ .setIn(['loadedComments', payload.i - 1], response.records)//arrToMap(response.records, CommentRecord))
+
default:
return state
}
diff --git a/src/selectors/index.js b/src/selectors/index.js
index 421e61a..623bc23 100644
--- a/src/selectors/index.js
+++ b/src/selectors/index.js
@@ -8,6 +8,7 @@ export const loadedArticlesSelector = state => state.articles.loaded
const commentsSelector = state => state.comments.entities
const filtersSelector = state => state.filters
const idSelector = (_, props) => props.id
+export const commentListSelector = state => state.comments.get('loadedComments')
export const filtratedArticles = createSelector(articleListSelector, filtersSelector, (articles, filters) => {
const {selected, dateRange: {from, to}} = filters