Last active
July 26, 2021 06:08
-
-
Save patrickcurl/b49d28e639f0ef202ee806ad150559b2 to your computer and use it in GitHub Desktop.
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
<div class="container p-4 mx-auto"> | |
<h1 class="text-2xl text-gray-900">Infinite Load Posts</h1> | |
<div class="grid grid-cols-1 gap-8 mt-4 md:grid-cols-1 lg:grid-cols-1"> | |
@foreach($posts as $post) | |
<a href="#" class="block p-4 overflow-hidden bg-white rounded shadow-sm hover:shadow" :key="$post['id']"> | |
<h1 class="text-lg text-gray-800 truncate"> | |
{{ $post['title'] }} | |
</h1> | |
<p class="text-gray-900"> | |
{{ $post['content'] }} | |
</p> | |
</a> | |
@endforeach | |
@if($hasMorePages) | |
<button wire:click.prevent="loadPosts">Load post</button> | |
@endif | |
</div> | |
@if($hasMorePages) | |
<div | |
x-data="{ | |
init () { | |
let observer = new IntersectionObserver((entries) => { | |
entries.forEach(entry => { | |
if (entry.isIntersecting) { | |
@this.call('loadPosts') | |
} | |
}) | |
}, { | |
root: null | |
}); | |
observer.POLL_INTERVAL = 100 | |
observer.observe(this.$el); | |
} | |
}" | |
class="grid grid-cols-1 gap-8 mt-4 md:grid-cols-1 lg:grid-cols-1" | |
> | |
</div> | |
@endif | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment