Skip to content

Commit

Permalink
refactor: move pagination listeners to outbox.html
Browse files Browse the repository at this point in the history
  • Loading branch information
akhileshthite committed Feb 22, 2024
1 parent c0c6cef commit 1a1144b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
12 changes: 12 additions & 0 deletions outbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@
</div>
<script type="module" src="./outbox.js"></script>
<script type="module" src="./post.js"></script>
<script>
const outboxElement = document.querySelector("distributed-outbox");
const prevButton = document.getElementById("prevPage");
const nextButton = document.getElementById("nextPage");

if (prevButton) {
prevButton.addEventListener("click", () => outboxElement.prevPage());
}
if (nextButton) {
nextButton.addEventListener("click", () => outboxElement.nextPage());
}
</script>
13 changes: 0 additions & 13 deletions outbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class DistributedOutbox extends HTMLElement {
this.numPosts = parseInt(this.getAttribute("num-posts"), 10) || this.numPosts;
this.page = parseInt(this.getAttribute("page"), 10) || this.page;
this.loadOutbox(this.getAttribute("url"));
this.paginationControls();
}

async loadOutbox(outboxUrl) {
Expand Down Expand Up @@ -81,18 +80,6 @@ class DistributedOutbox extends HTMLElement {
this.appendChild(activityElement);
}

paginationControls() {
// Attach event listeners for pagination
const prevButton = document.getElementById("prevPage");
const nextButton = document.getElementById("nextPage");
if (prevButton) {
prevButton.addEventListener("click", () => this.prevPage());
}
if (nextButton) {
nextButton.addEventListener("click", () => this.nextPage());
}
}

nextPage() {
const currentPage = this.page;
if (currentPage < this.totalPages) {
Expand Down

0 comments on commit 1a1144b

Please sign in to comment.