Skip to content
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

Pagination code added #2969

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 93 additions & 14 deletions client/modules/IDE/components/SketchList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ class SketchList extends React.Component {
this.props.resetSorting();

this.state = {
isInitialDataLoad: true
isInitialDataLoad: true,
currentPage: 1
};
}

Expand Down Expand Up @@ -361,6 +362,19 @@ class SketchList extends React.Component {
? this.props.username
: this.props.user.username;
const { mobile } = this.props;
const pageNumbers = [];
let sketchesPerPage = 5;
if (mobile) {
sketchesPerPage = 7;
}
const { currentPage } = this.state;
const totalSketches = this.props.sketches.length;
const indexOfLastSketch = currentPage * sketchesPerPage;
const indexOfFirstSketch = indexOfLastSketch - sketchesPerPage;
const TotalPages = Math.ceil(totalSketches / sketchesPerPage);
for (let i = 1; i <= TotalPages; i += 1) {
pageNumbers.push(i);
}
return (
<article className="sketches-table-container">
<Helmet>
Expand Down Expand Up @@ -395,22 +409,87 @@ class SketchList extends React.Component {
</tr>
</thead>
<tbody>
{this.props.sketches.map((sketch) => (
<SketchListRow
mobile={mobile}
key={sketch.id}
sketch={sketch}
user={this.props.user}
username={username}
onAddToCollection={() => {
this.setState({ sketchToAddToCollection: sketch });
}}
t={this.props.t}
/>
))}
{this.props.sketches
.slice(indexOfFirstSketch, indexOfLastSketch)
.map((sketch) => (
<SketchListRow
mobile={mobile}
key={sketch.id}
sketch={sketch}
user={this.props.user}
username={username}
onAddToCollection={() => {
this.setState({ sketchToAddToCollection: sketch });
}}
t={this.props.t}
/>
))}
</tbody>
</table>
)}
<div className="pagination">
<ul className="pagination-ul">
<li className="page-item">
<button
className="page-link"
onClick={() =>
this.setState({
currentPage: Math.max(currentPage - 1, 1)
})
}
disabled={currentPage === 1}
>
Prev
</button>
</li>
<li>
<button
className="page-link"
onClick={() =>
this.setState({
currentPage: 1
})
}
>
1
</button>
</li>
<li>
<span>.......</span>
</li>
<li>
<button className="page-link"> {currentPage} </button>
</li>
<li>
<span>&nbsp;of&nbsp;</span>
</li>
<li>
<button
className="page-link"
onClick={() =>
this.setState({
currentPage: TotalPages
})
}
>
{TotalPages}
</button>
</li>
<li className="page-item">
<button
className="page-link"
onClick={() =>
this.setState({
currentPage: Math.min(currentPage + 1, TotalPages)
})
}
disabled={currentPage === TotalPages}
>
Next
</button>
</li>
</ul>
</div>
{this.state.sketchToAddToCollection && (
<Overlay
isFixedHeight
Expand Down
34 changes: 34 additions & 0 deletions client/styles/components/_sketch-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,40 @@
}
}

.pagination {
width: 100%;
position: fixed;
bottom: 0;
left: 0;
justify-content: center;

.pagination-ul {
bottom: 0;
margin-top: auto;
display: flex;
justify-content: center;

> li {
margin: 0 2px;

.page-link {
@include themify() {
color: #ed225d;
font-weight: 800;
padding: 0 10px;
border: 1px solid #fbd2de;
}
}
}
}
}

.pagination-ul > li button:hover {
@include themify() {
background-color: #f9bcce;
}
}

.sketches-table {
width: 100%;

Expand Down
Loading