Skip to content

Commit

Permalink
feat(catalogue): Add sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh committed Mar 17, 2024
1 parent 516f07c commit fdba18c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/components/catalogue/Core.astro
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ const pageLenth = 30;
<option value="hated">Hated</option>
</select>
</div>

<div>
<label for="catalogue-sort">Sort</label>
<select name="sort" id="catalogue-sort">
<option value="date">Date</option>
<option value="rating">Rating</option>
<option value="alphabetical">Title</option>
</select>
</div>
</div>
<div id="catalogue-entry-count" class="flex items-center justify-end sm:justify-start">
... entries
Expand All @@ -59,6 +68,7 @@ const pageLenth = 30;
<script>
const searchInput = document.getElementById("catalogue-search") as HTMLInputElement;
const ratingSelect = document.getElementById("catalogue-ratings") as HTMLSelectElement;
const sortSelect = document.getElementById("catalogue-sort") as HTMLSelectElement;
const typeSelect = document.getElementById("catalogue-types") as HTMLSelectElement;
const seeMoreButton = document.getElementById("catalogue-seemore") as HTMLButtonElement;
const content = document.getElementById("catalogue-content") as HTMLDivElement;
Expand All @@ -76,6 +86,9 @@ const pageLenth = 30;

function updateCurrentPage(value: number) {
_currentPage = value;
}

function updateSeeMoreButton() {
seeMoreButton.disabled = _currentPage === serverStatus.totalPages;
}

Expand All @@ -85,19 +98,22 @@ const pageLenth = 30;
searchDebounce = setTimeout(async () => {
updateCurrentPage(1);
await buildLibrary();
updateSeeMoreButton();
}, 75);
});

[ratingSelect, typeSelect].forEach((select) => {
[ratingSelect, typeSelect, sortSelect].forEach((select) => {
select.addEventListener("change", async () => {
updateCurrentPage(1);
await buildLibrary();
updateSeeMoreButton();
});
});

seeMoreButton.addEventListener("click", async () => {
updateCurrentPage(_currentPage + 1);
await buildLibrary(true);
updateSeeMoreButton();
});

await buildLibrary();
Expand Down Expand Up @@ -132,6 +148,7 @@ const pageLenth = 30;
url.searchParams.append("search", searchInput.value);
url.searchParams.append("type", typeSelect.value);
url.searchParams.append("rating", ratingSelect.value);
url.searchParams.append("sort", sortSelect.value);
url.searchParams.append("page", _currentPage.toString());

return url;
Expand Down

0 comments on commit fdba18c

Please sign in to comment.