Skip to content

Commit 6e7abac

Browse files
committed
lazy load
1 parent 7f83a26 commit 6e7abac

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

app/Livewire/Item/VoteHistory.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,23 @@
44

55
use App\Models\Item;
66
use Livewire\Component;
7+
use Livewire\Attributes\On;
78
use Illuminate\Contracts\View\View;
89

910
class VoteHistory extends Component
1011
{
1112
public Item $item;
1213

14+
public bool $modalOpened = false;
15+
16+
#[On('open-modal')]
17+
public function onModalOpen(string $id): void
18+
{
19+
if ($id === 'vote-history-modal') {
20+
$this->modalOpened = true;
21+
}
22+
}
23+
1324
public function render(): View
1425
{
1526
return view('livewire.item.vote-history');

resources/views/livewire/item/vote-history.blade.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,23 @@ class="text-sm text-gray-500 hover:text-primary-500 dark:text-gray-400 dark:hove
99
</button>
1010
</x-slot>
1111

12-
@if($this->item->votes()->exists())
13-
@livewire(\App\Filament\Widgets\VoteHistoryChart::class, ['item' => $this->item])
12+
@if($modalOpened)
13+
@if($this->item->votes()->exists())
14+
@livewire(\App\Filament\Widgets\VoteHistoryChart::class, ['item' => $this->item], key('vote-history-chart-' . $this->item->id))
15+
@else
16+
<x-filament::section>
17+
<x-slot name="heading">
18+
{{ trans('items.vote-history') }}
19+
</x-slot>
20+
<div class="text-center py-8 text-gray-500 dark:text-gray-400">
21+
{{ trans('items.no-vote-history') }}
22+
</div>
23+
</x-filament::section>
24+
@endif
1425
@else
15-
<x-filament::section>
16-
<x-slot name="heading">
17-
{{ trans('items.vote-history') }}
18-
</x-slot>
19-
<div class="text-center py-8 text-gray-500 dark:text-gray-400">
20-
{{ trans('items.no-vote-history') }}
21-
</div>
22-
</x-filament::section>
26+
<div class="flex items-center justify-center py-12">
27+
<x-filament::loading-indicator class="h-8 w-8" />
28+
</div>
2329
@endif
2430
</x-filament::modal>
2531
</div>

tests/Feature/Livewire/Item/VoteHistoryTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
]);
2727

2828
Livewire::test(VoteHistory::class, ['item' => $item])
29+
->dispatch('open-modal', id: 'vote-history-modal')
2930
->assertSee(trans('items.no-vote-history'));
3031
});
3132

0 commit comments

Comments
 (0)