feat: implement infinite scroll pagination for assignment cards with dynamic loading
This commit is contained in:
parent
59838782f9
commit
d609e959fb
@ -30,6 +30,13 @@ class ListAssignments extends Page
|
|||||||
#[Url]
|
#[Url]
|
||||||
public ?string $search = '';
|
public ?string $search = '';
|
||||||
|
|
||||||
|
public int $perPage = 12;
|
||||||
|
|
||||||
|
public function loadMore(): void
|
||||||
|
{
|
||||||
|
$this->perPage += 12;
|
||||||
|
}
|
||||||
|
|
||||||
#[Url]
|
#[Url]
|
||||||
public ?int $course_id = null;
|
public ?int $course_id = null;
|
||||||
|
|
||||||
@ -61,7 +68,10 @@ public function form(Schema $schema): Schema
|
|||||||
->placeholder('Cari Judul Tugas...')
|
->placeholder('Cari Judul Tugas...')
|
||||||
->autocomplete(false)
|
->autocomplete(false)
|
||||||
->live(debounce: 500)
|
->live(debounce: 500)
|
||||||
->afterStateUpdated(fn ($state) => $this->search = $state),
|
->afterStateUpdated(function ($state) {
|
||||||
|
$this->search = $state;
|
||||||
|
$this->perPage = 12;
|
||||||
|
}),
|
||||||
|
|
||||||
Select::make('course_id')
|
Select::make('course_id')
|
||||||
->label('Mata Kuliah')
|
->label('Mata Kuliah')
|
||||||
@ -75,7 +85,10 @@ public function form(Schema $schema): Schema
|
|||||||
})
|
})
|
||||||
->searchable()
|
->searchable()
|
||||||
->live()
|
->live()
|
||||||
->afterStateUpdated(fn ($state) => $this->course_id = $state),
|
->afterStateUpdated(function ($state) {
|
||||||
|
$this->course_id = $state;
|
||||||
|
$this->perPage = 12;
|
||||||
|
}),
|
||||||
])
|
])
|
||||||
->columns([
|
->columns([
|
||||||
'sm' => 2,
|
'sm' => 2,
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-6">
|
<div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-6">
|
||||||
@forelse ($this->assignmentCards as $card)
|
@forelse ($this->assignmentCards->take($this->perPage) as $card)
|
||||||
<div class="{{ $card->card_classes }} flex-col">
|
<div class="{{ $card->card_classes }} flex-col">
|
||||||
|
|
||||||
<a href="{{ $card->url }}"
|
<a href="{{ $card->url }}"
|
||||||
@ -105,5 +105,11 @@ class="flex flex-wrap items-center gap-3 px-5 py-4 border-t border-gray-100 dark
|
|||||||
</div>
|
</div>
|
||||||
@endforelse
|
@endforelse
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@if ($this->assignmentCards->count() > $this->perPage)
|
||||||
|
<div x-intersect="$wire.loadMore()" class="h-10 mt-6 flex items-center justify-center text-primary-500">
|
||||||
|
<x-filament::loading-indicator class="h-8 w-8" />
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
</x-filament::section>
|
</x-filament::section>
|
||||||
</x-filament-panels::page>
|
</x-filament-panels::page>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user