@@ -2,56 +2,26 @@ import React, {Component} from 'react';
22import { connect } from 'react-redux' ;
33import { Link } from 'react-router-dom' ;
44import PropTypes from 'prop-types' ;
5- import { list , reset , page } from '../../actions/{{{ lc }}}/list' ;
5+ import { list , reset } from '../../actions/{{{ lc }}}/list' ;
66import { success } from '../../actions/{{{ lc }}}/delete' ;
7- import { paginationRoute , itemToLinks } from '../../utils/helpers' ;
7+ import { itemToLinks } from '../../utils/helpers' ;
88
99class List extends Component {
1010 static propTypes = {
1111 error : PropTypes . string ,
1212 loading : PropTypes . bool . isRequired ,
13- items : PropTypes . array . isRequired ,
13+ data : PropTypes . object . isRequired ,
1414 deletedItem : PropTypes . object ,
1515 list : PropTypes . func . isRequired ,
1616 reset : PropTypes . func . isRequired ,
17- page : PropTypes . func . isRequired ,
1817 } ;
1918
20- pagination ( ) {
21- return (
22- < span >
23- < button
24- type = "button"
25- className = "btn btn-basic btn-sm"
26- onClick = { ( ) => this . props . page ( paginationRoute ( this . props . view [ '{{{ hydraPrefix }}}first' ] ) ) }
27- disabled = { ! this . props . view [ '{{{ hydraPrefix }}}previous' ] }
28- > First</ button >
29-
30- < button
31- type = "button"
32- className = "btn btn-basic btn-sm"
33- onClick = { ( ) => this . props . page ( paginationRoute ( this . props . view [ '{{{ hydraPrefix }}}previous' ] ) ) }
34- disabled = { ! this . props . view [ '{{{ hydraPrefix }}}previous' ] }
35- > Previous</ button >
36-
37- < button
38- type = "button" className = "btn btn-basic btn-sm"
39- onClick = { ( ) => this . props . page ( paginationRoute ( this . props . view [ '{{{ hydraPrefix }}}next' ] ) ) }
40- disabled = { ! this . props . view [ '{{{ hydraPrefix }}}next' ] }
41- > Next</ button >
42-
43- < button
44- type = "button" className = "btn btn-basic btn-sm"
45- onClick = { ( ) => this . props . page ( paginationRoute ( this . props . view [ '{{{ hydraPrefix }}}last' ] ) ) }
46- disabled = { ! this . props . view [ '{{{ hydraPrefix }}}next' ] }
47- > Last</ button >
48-
49- </ span >
50- ) ;
19+ componentDidMount ( ) {
20+ this . props . list ( this . props . match . params . page && decodeURIComponent ( this . props . match . params . page ) ) ;
5121 }
5222
53- componentDidMount ( ) {
54- this . props . list ( ) ;
23+ componentWillReceiveProps ( nextProps ) {
24+ if ( this . props . match . params . page !== nextProps . match . params . page ) nextProps . list ( nextProps . match . params . page && decodeURIComponent ( nextProps . match . params . page ) ) ;
5525 }
5626
5727 componentWillUnmount ( ) {
@@ -65,7 +35,8 @@ class List extends Component {
6535 { this . props . loading && < div className = "alert alert-info" > Loading...</ div > }
6636 { this . props . deletedItem && < div className = "alert alert-success" > { this . props . deletedItem [ '@id' ] } deleted.</ div > }
6737 { this . props . error && < div className = "alert alert-danger" > { this . props . error } </ div > }
68- { this . pagination ( ) }
38+
39+ < p > < Link to = "create" className = "btn btn-default" > Create</ Link > </ p >
6940
7041 < div className = "table-responsive" >
7142 < table className = "table table-striped table-hover" >
@@ -80,7 +51,7 @@ class List extends Component {
8051 </ tr >
8152 </ thead >
8253 < tbody >
83- { this . props . items . map ( item =>
54+ { this . props . data [ '{{{ hydraPrefix }}}member' ] && this . props . data [ '{{{ hydraPrefix }}}member' ] . map ( item =>
8455 < tr className = { item [ '@id' ] } key = { item [ '@id' ] } >
8556 < td > < Link to = { `show/${ encodeURIComponent ( item [ '@id' ] ) } ` } > { item [ '@id' ] } </ Link > </ td >
8657{ { #each fields} }
@@ -104,25 +75,37 @@ class List extends Component {
10475 </ table >
10576 </ div >
10677
107- < Link to = "create" className = "btn btn-default" > Create </ Link >
78+ { this . pagination ( ) }
10879 </ div > ;
10980 }
81+
82+ pagination ( ) {
83+ const view = this . props . data [ 'hydra:view' ] ;
84+ if ( ! view ) return ;
85+
86+ const { '{{{ hydraPrefix }}}first' : first , '{{{ hydraPrefix }}}previous' : previous , '{{{ hydraPrefix }}}next' : next , '{{{ hydraPrefix }}}last' : last } = view ;
87+
88+ return < nav aria-label = "Page navigation" >
89+ < Link to = '.' className = { `btn btn-default${ previous ? '' : ' disabled' } ` } > < span aria-hidden = "true" > ⇐</ span > First</ Link >
90+ < Link to = { ! previous || previous === first ? '.' : encodeURIComponent ( previous ) } className = { `btn btn-default${ previous ? '' : ' disabled' } ` } > < span aria-hidden = "true" > ←</ span > Previous</ Link >
91+ < Link to = { next ? encodeURIComponent ( next ) : '#' } className = { `btn btn-default${ next ? '' : ' disabled' } ` } > Next < span aria-hidden = "true" > →</ span > </ Link >
92+ < Link to = { last ? encodeURIComponent ( last ) : '#' } className = { `btn btn-default${ next ? '' : ' disabled' } ` } > Last < span aria-hidden = "true" > ⇒</ span > </ Link >
93+ </ nav > ;
94+ }
11095}
11196
11297const mapStateToProps = ( state ) => {
11398 return {
114- items : state . { { { lc } } } . list . items ,
99+ data : state . { { { lc } } } . list . data ,
115100 error : state . { { { lc } } } . list . error,
116101 loading : state . { { { lc } } } . list . loading ,
117102 deletedItem : state . { { { lc } } } . del . deleted,
118- view : state . { { { lc } } } . list . view ,
119103 } ;
120104} ;
121105
122106const mapDispatchToProps = ( dispatch ) => {
123107 return {
124- list : ( ) => dispatch ( list ( ) ) ,
125- page : ( arg ) => dispatch ( page ( arg ) ) ,
108+ list : ( page ) => dispatch ( list ( page ) ) ,
126109 reset : ( ) => {
127110 dispatch ( reset ( ) ) ;
128111 dispatch ( success ( null ) ) ;
0 commit comments