Skip to content

Commit

Permalink
feat: add custom behavior for load more button in updates page
Browse files Browse the repository at this point in the history
Now, when you click on the load more button, and there are no more updates to load, the button will show a message saying "Nothing more found" and get disabled, both for 1 second.
  • Loading branch information
GabsEdits committed Sep 21, 2024
1 parent 10ba787 commit 0c11a46
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/views/Updates.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@

<div class="spacer spacer--lg"></div>
<center>
<button @click="loadMoreDays" class="btn btn--primary">Load More</button>
<button @click="handleLoadMoreDays" class="btn btn--primary">
{{ buttonText }}
</button>
</center>
<div class="spacer spacer--lg"></div>
<div class="card card--hz card--type-adv card--type-adv--hz card--purple">
Expand Down Expand Up @@ -107,13 +109,27 @@ export default defineComponent({
displayedDays: [] as Day[],
loadIndex: 0,
loadIncrement: 15,
buttonText: 'Load More',
};
},
methods: {
loadMoreDays() {
this.loadIndex += this.loadIncrement;
this.displayedDays = this.days.slice(0, this.loadIndex);
},
handleLoadMoreDays() {
const button = document.querySelector('.btn.btn--primary');
if (this.loadIndex >= this.days.length) {
this.buttonText = 'Nothing more found';
if (button) button.setAttribute('disabled', 'true');
setTimeout(() => {
this.buttonText = 'Load More';
if (button) button.removeAttribute('disabled');
}, 1000);
} else {
this.loadMoreDays();
}
},
formatDate(dateString: string): string {
const [month, day, year] = dateString.split('-');
const date = new Date(`${year}-${month}-${day}T00:00:00`);
Expand Down

0 comments on commit 0c11a46

Please sign in to comment.