Skip to content

Commit 65dc6a2

Browse files
committed
feat: implement infinite scroll for bounties page
1 parent 16c9f93 commit 65dc6a2

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

assets/js/app.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,42 @@ const Hooks = {
461461
});
462462
},
463463
},
464+
InfiniteScroll: {
465+
mounted() {
466+
this.observer = new IntersectionObserver(
467+
(entries) => {
468+
const entry = entries[0];
469+
if (entry.isIntersecting) {
470+
this.pushEvent("load_more");
471+
}
472+
},
473+
{
474+
root: null, // viewport
475+
rootMargin: "0px 0px 400px 0px", // trigger when indicator is 400px from viewport
476+
threshold: 0.1,
477+
}
478+
);
479+
480+
const loadMoreIndicator = document.getElementById("load-more-indicator");
481+
if (loadMoreIndicator) {
482+
this.observer.observe(loadMoreIndicator);
483+
}
484+
},
485+
486+
updated() {
487+
// Re-observe the indicator after updates
488+
const loadMoreIndicator = document.getElementById("load-more-indicator");
489+
if (loadMoreIndicator) {
490+
this.observer.observe(loadMoreIndicator);
491+
}
492+
},
493+
494+
destroyed() {
495+
if (this.observer) {
496+
this.observer.disconnect();
497+
}
498+
},
499+
},
464500
} satisfies Record<string, Partial<ViewHook> & Record<string, unknown>>;
465501

466502
// Accessible focus handling
@@ -643,3 +679,5 @@ window.addEventListener("phx:open_popup", (e: CustomEvent) => {
643679
newWindow.focus();
644680
}
645681
});
682+
683+
export default Hooks;

lib/algora_web/live/org/bounties_live.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defmodule AlgoraWeb.Org.BountiesLive do
1212

1313
def render(assigns) do
1414
~H"""
15-
<div class="max-w-7xl mx-auto p-6">
15+
<div class="max-w-7xl mx-auto p-6" id="bounties-container" phx-hook="InfiniteScroll">
1616
<div class="mb-6">
1717
<div class="flex flex-wrap items-start justify-between gap-4 lg:flex-nowrap">
1818
<div>
@@ -218,10 +218,10 @@ defmodule AlgoraWeb.Org.BountiesLive do
218218
</table>
219219
</div>
220220
</div>
221-
<div :if={@has_more} class="flex justify-center mt-4">
222-
<.button variant="ghost" phx-click="load_more">
223-
<.icon name="tabler-arrow-down" class="mr-2 h-4 w-4" /> Load More
224-
</.button>
221+
<div :if={@has_more} class="flex justify-center mt-4" id="load-more-indicator">
222+
<div class="animate-pulse text-gray-400">
223+
<.icon name="tabler-loader" class="h-6 w-6 animate-spin" />
224+
</div>
225225
</div>
226226
</div>
227227
"""

0 commit comments

Comments
 (0)