style pagination controls

master
Edward Shen 2020-11-27 14:19:33 -05:00
parent 2d7fdae813
commit c2a99f61c7
Signed by: edward
GPG Key ID: F350507060ED6C90
3 changed files with 18 additions and 10 deletions

View File

@ -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";

View File

@ -1,4 +1,12 @@
.note-title { .note-title {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
} }
.prev-page-link {
margin-right: 10px;
}
.next-page-link {
margin-left: 10px;
}

View File

@ -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}>&lt;&lt;</a>; prevPageLink = <a href={rootPath} className={style.prevPageLink}>&lt;&lt;</a>;
} else if (currentPage !== 1) { } else if (currentPage !== 1) {
backElement = <a href={rootPath + '/' + (currentPage - 1)}>&lt;&lt;</a>; prevPageLink = <a href={rootPath + '/' + (currentPage - 1)} className={style.prevPageLink}>&lt;&lt;</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)}>&gt;&gt;</a> : ''} {currentPage !== numPages && <a href={rootPath + '/' + (currentPage + 1)} className={style.nextPageLink}>&gt;&gt;</a>}
</div> </p>
</> </>
) )
} }