style pagination controls
This commit is contained in:
parent
2d7fdae813
commit
c2a99f61c7
3 changed files with 18 additions and 10 deletions
|
@ -28,7 +28,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const posts = result.data.allMdx.edges;
|
const posts = result.data.allMdx.edges;
|
||||||
const postsPerPage = 2;
|
const postsPerPage = 10;
|
||||||
const numPages = Math.ceil(posts.length / postsPerPage);
|
const numPages = Math.ceil(posts.length / postsPerPage);
|
||||||
const rootPath = "/notes";
|
const rootPath = "/notes";
|
||||||
|
|
||||||
|
|
|
@ -2,3 +2,11 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.prev-page-link {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.next-page-link {
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
|
|
@ -6,12 +6,12 @@ import style from "./notes.module.css";
|
||||||
export default ({ data, pageContext }) => {
|
export default ({ data, pageContext }) => {
|
||||||
const posts = data.allMdx.edges;
|
const posts = data.allMdx.edges;
|
||||||
const { currentPage, numPages, rootPath } = pageContext;
|
const { currentPage, numPages, rootPath } = pageContext;
|
||||||
let backElement = null;
|
let prevPageLink = null;
|
||||||
|
|
||||||
if (currentPage === 2) {
|
if (currentPage === 2) {
|
||||||
backElement = <a href={rootPath}><<</a>;
|
prevPageLink = <a href={rootPath} className={style.prevPageLink}><<</a>;
|
||||||
} else if (currentPage !== 1) {
|
} else if (currentPage !== 1) {
|
||||||
backElement = <a href={rootPath + '/' + (currentPage - 1)}><<</a>;
|
prevPageLink = <a href={rootPath + '/' + (currentPage - 1)} className={style.prevPageLink}><<</a>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -31,11 +31,11 @@ export default ({ data, pageContext }) => {
|
||||||
</article>
|
</article>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
<div>
|
<p className={style.paginationNav}>
|
||||||
{backElement}
|
{prevPageLink}
|
||||||
<p>{currentPage}</p>
|
{currentPage}
|
||||||
{currentPage !== numPages ? <a href={rootPath + '/' + (currentPage + 1)}>>></a> : ''}
|
{currentPage !== numPages && <a href={rootPath + '/' + (currentPage + 1)} className={style.nextPageLink}>>></a>}
|
||||||
</div>
|
</p>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue