-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
import { Fragment } from "astro/jsx-runtime"; | ||
import "./Pagination.scss"; | ||
const { paginator } = Astro.props; | ||
const adjacentLinks = 2; | ||
const maxLinks = adjacentLinks * 2 + 1; | ||
const lowerLimit = adjacentLinks + 1; | ||
const upperLimit = paginator.totalPages - adjacentLinks; | ||
--- | ||
|
||
{ | ||
paginator.totalPages > 1 && ( | ||
<ul class="pagination"> | ||
{/* First page */} | ||
{paginator.pageNumber !== 1 && ( | ||
<li class="pagination__item pagination__item--first"> | ||
<a class="pagination__link pagination__link--first" href={1}> | ||
«« | ||
</a> | ||
</li> | ||
)} | ||
|
||
{/* Previous page */} | ||
{paginator.hasPrev && ( | ||
<li class="pagination__item pagination__item--previous"> | ||
<a | ||
href={paginator.prev.url} | ||
class="pagination__link pagination__link--previous" | ||
> | ||
« | ||
</a> | ||
</li> | ||
)} | ||
|
||
{/* Page numbers */} | ||
{paginator.pagers.map((page) => { | ||
return ( | ||
<Fragment> | ||
{(() => { | ||
const isInRange = | ||
paginator.totalPages > maxLinks | ||
? paginator.pageNumber < lowerLimit + 1 | ||
? page.pageNumber < maxLinks + 1 | ||
: paginator.pageNumber >= upperLimit | ||
? page.pageNumber > paginator.totalPages - maxLinks | ||
: page.pageNumber >= | ||
paginator.pageNumber - adjacentLinks && | ||
page.pageNumber < | ||
paginator.pageNumber + adjacentLinks + 1 | ||
: true; | ||
|
||
return ( | ||
isInRange && ( | ||
<li | ||
class={`pagination__item${page.pageNumber === paginator.pageNumber ? " pagination__item--current" : ""}`} | ||
> | ||
<a href={page.url} class="pagination__link"> | ||
{page.pageNumber} | ||
</a> | ||
</li> | ||
) | ||
); | ||
})()} | ||
</Fragment> | ||
); | ||
})} | ||
|
||
{/* Next page */} | ||
{paginator.hasNext && ( | ||
<li class="pagination__item pagination__item--next"> | ||
<a | ||
href={paginator.next.url} | ||
class="pagination__link pagination__link--next" | ||
> | ||
» | ||
</a> | ||
</li> | ||
)} | ||
|
||
{/* Last page */} | ||
{paginator.pageNumber !== paginator.totalPages && ( | ||
<li class="pagination__item pagination__item--last"> | ||
<a | ||
class="pagination__link pagination__link--last" | ||
href={paginator.last.url} | ||
> | ||
»» | ||
</a> | ||
</li> | ||
)} | ||
</ul> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.pagination { | ||
text-align: center; | ||
font-weight: bold; | ||
display: flex; | ||
justify-content: space-between; | ||
max-width: 10rem; | ||
margin: auto; | ||
padding: 0; | ||
|
||
li { | ||
display: inline; | ||
text-align: center; | ||
} | ||
|
||
a { | ||
text-decoration: auto; | ||
} | ||
|
||
.pagination__item--current { | ||
color: black; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
--- | ||
import Back from "@components/Back/Back.astro"; | ||
import RowCard from "@components/RowCard/RowCard.astro"; | ||
import { getCollection } from "astro:content"; | ||
import { default as Layout } from "src/layouts/Content/Content.astro"; | ||
import Pagination from "@components/Pagination/Pagination.astro"; | ||
const evaluations = await getCollection("evaluations"); | ||
const courseCodes = { | ||
comp2804: "COMP 2804", | ||
}; | ||
const comp2804Evaluations = evaluations | ||
.filter((evaluation) => evaluation.data.course === "comp2804") | ||
.sort((a, b) => Number(b.data.created_at) - Number(a.data.created_at)); | ||
export async function getStaticPaths({ paginate }) { | ||
const evaluations = await getCollection("evaluations"); | ||
const comp2804Evaluations = evaluations | ||
.filter((evaluation) => evaluation.data.course === "comp2804") | ||
.sort((a, b) => Number(b.data.created_at) - Number(a.data.created_at)); | ||
// turn the above into a list | ||
const evaluationPages = comp2804Evaluations.map((evaluation) => ({ | ||
evaluation, | ||
})); | ||
// Generate pages from our array of evaluations, with 5 to a page | ||
return paginate(evaluationPages, { pageSize: 3 }); | ||
} | ||
// All paginated data is passed on the "page" prop | ||
const { page } = Astro.props; | ||
--- | ||
|
||
<Layout title="Evaluations"> | ||
<div class="Question__bar"> | ||
<div><Back href={`/`} label="Home" /></div> | ||
</div> | ||
<h1>Evaluations</h1> | ||
<p> | ||
Practice previous evaluations from Carleton University's Computer Science | ||
courses. | ||
</p> | ||
<div style="margin-top:2.5rem"></div> | ||
<!-- <h2>COMP 2804: Discrete Structures II</h2> | ||
<p> | ||
Topics include: counting, sequences and sums, discrete probability, basic | ||
statistics, recurrence relations, randomized algorithms. Material is | ||
illustrated through examples from computing. | ||
</p> | ||
<br /> --> | ||
<div class="Evaluations__list" style="margin-bottom:0.75rem"> | ||
{ | ||
page.data.map(({ evaluation }) => ( | ||
<div> | ||
<a href={`/evaluations/${evaluation.slug}`}> | ||
<RowCard | ||
title={`${courseCodes.comp2804}: ${evaluation.data.title}`} | ||
icon="mdi mdi-book-open-variant" | ||
/> | ||
</a> | ||
</div> | ||
)) | ||
} | ||
</div> | ||
<Pagination | ||
paginator={{ | ||
pageNumber: page.currentPage, | ||
totalPages: page.lastPage, | ||
hasPrev: !!page.url.prev, | ||
prev: { url: page.url.prev || "" }, | ||
hasNext: !!page.url.next, | ||
next: { url: page.url.next || "" }, | ||
first: { url: "/evaluations/1" }, | ||
last: { url: page.lastPage ? `/evaluations/${page.lastPage}` : "" }, | ||
pagers: Array.from({ length: page.lastPage }, (_, i) => ({ | ||
pageNumber: i + 1, | ||
url: `/evaluations/${i + 1}`, | ||
})), | ||
}} | ||
/> | ||
</Layout> | ||
|
||
<style> | ||
p { | ||
color: gray; | ||
} | ||
|
||
.Evaluations__list { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.75rem; | ||
} | ||
</style> |