Handle pagination in movie list view
This commit is contained in:
parent
9497995cf5
commit
678153c864
@ -13,11 +13,27 @@ export default function ListPosters(props) {
|
|||||||
extract: (el) => el.title
|
extract: (el) => el.title
|
||||||
});
|
});
|
||||||
elmts = filtered.map((el) => el.original);
|
elmts = filtered.map((el) => el.original);
|
||||||
}
|
} else {
|
||||||
|
// Get the page number if defined
|
||||||
|
let page = 1;
|
||||||
|
let perPage = props.perPage;
|
||||||
|
if (props.params && props.params.page) {
|
||||||
|
page = parseInt(props.params.page);
|
||||||
|
}
|
||||||
|
|
||||||
// Limit the number of results
|
let from = 0;
|
||||||
if (elmts.length > props.perPage) {
|
let to = perPage - 1;
|
||||||
elmts = elmts.slice(0, props.perPage);
|
if (page > 1) {
|
||||||
|
from = ((page - 1) * perPage) - 1;
|
||||||
|
to = from + perPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of results
|
||||||
|
if ((from + perPage) > elmts.length) {
|
||||||
|
elmts = elmts.slice(from);
|
||||||
|
} else {
|
||||||
|
elmts = elmts.slice(from, to);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -100,6 +100,7 @@ export default class MovieList extends React.Component {
|
|||||||
filter={this.props.movieStore.filter}
|
filter={this.props.movieStore.filter}
|
||||||
perPage={this.props.movieStore.perPage}
|
perPage={this.props.movieStore.perPage}
|
||||||
onClick={this.props.selectMovie}
|
onClick={this.props.selectMovie}
|
||||||
|
params={this.props.params}
|
||||||
/>
|
/>
|
||||||
{selectedMovie &&
|
{selectedMovie &&
|
||||||
<ListDetails data={selectedMovie}>
|
<ListDetails data={selectedMovie}>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user