From cba9fe1e7bcb53c1b21cbf8406b50ee64912cb8e Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Fri, 29 Nov 2024 14:22:35 -0600 Subject: [PATCH] feat: adds pagination to recent activity list --- config/livewire.php | 2 +- resources/views/dashboard.blade.php | 4 +- .../livewire/transactions-list.blade.php | 46 ++++++++++++++++++- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/config/livewire.php b/config/livewire.php index 89b8780..b8f4ac7 100644 --- a/config/livewire.php +++ b/config/livewire.php @@ -143,7 +143,7 @@ | */ - 'inject_morph_markers' => true, + 'inject_morph_markers' => false, /* |--------------------------------------------------------------------------- diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 5891a90..a2dadf4 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -63,7 +63,9 @@ @livewire('transactions-list', [ - 'transactions' => $user->transactions + 'transactions' => $user->transactions, + 'showPortfolio' => true, + 'paginate' => false ]) diff --git a/resources/views/livewire/transactions-list.blade.php b/resources/views/livewire/transactions-list.blade.php index 15030e0..b20cf50 100644 --- a/resources/views/livewire/transactions-list.blade.php +++ b/resources/views/livewire/transactions-list.blade.php @@ -15,6 +15,10 @@ public ?Portfolio $portfolio; public ?Transaction $editingTransaction; public Bool $shouldGoToHolding = true; + public Bool $showPortfolio = false; + public Bool $paginate = true; + public Int $perPage = 5; + public Int $offset = 0; protected $listeners = [ 'transaction-updated' => '$refresh', @@ -38,17 +42,23 @@ public function goToHolding($holding) return $this->redirect(route('holding.show', ['portfolio' => $holding['portfolio_id'], 'symbol' => $holding['symbol']])); } + public function updateOffset($amount = 0) + { + $this->offset = $this->offset + $amount; + } + }; ?>
- @foreach($transactions->sortByDesc('date')->take(10) as $transaction) + @foreach($transactions->sortByDesc('date')->slice($offset)->take($perPage) as $transaction) transaction_type == 'BUY' + @if($showPortfolio) + {{ $transaction->portfolio->title }} + · + @endif {{ $transaction->date->format('F j, Y') }} @endforeach + @if ($paginate && count($transactions) > $perPage) +
+ + + @if($offset > 0) + + {!! __('pagination.previous') !!} + + @endif + + + + @if(count($transactions) - $offset > $offset) + + {!! __('pagination.next') !!} + + @endif + + +
+ @endif +