Skip to content

Commit

Permalink
refactor Livewire components
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiorodriguesroque committed Nov 17, 2024
1 parent f8b58cc commit 3085d83
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
5 changes: 5 additions & 0 deletions app/Livewire/Item/VoteButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Livewire\Item;

use App\Models\User;
use App\Models\Vote;
use Livewire\Component;
use Illuminate\Support\Collection;
Expand All @@ -12,6 +13,10 @@ class VoteButton extends Component
{
public Model $model;
public Vote|null $vote;

/**
* @var Collection<User>
*/
public Collection $recentVoters;
public int $recentVotersToShow = 5;
public bool $showSubscribeOption;
Expand Down
3 changes: 2 additions & 1 deletion app/Livewire/Modals/Item/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Livewire\Modals\Item;

use App\Models\Item;
use Illuminate\Contracts\View\View;
use Livewire\Component;
use Filament\Tables\Table;
use Filament\Forms\Contracts\HasForms;
Expand All @@ -29,7 +30,7 @@ public function table(Table $table): Table
]);
}

public function render()
public function render(): View
{
return view('livewire.modals.item.search');
}
Expand Down
28 changes: 22 additions & 6 deletions app/Livewire/My.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace App\Livewire;

use App\Models\Item;
use Closure;
use Filament\Tables;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Model;
use Livewire\Component;
use Illuminate\Support\Carbon;
use Filament\Forms\Contracts\HasForms;
Expand All @@ -16,26 +19,39 @@ class My extends Component implements HasTable, HasForms
{
use InteractsWithTable, InteractsWithForms;

public $type = 'default';
public string $type = 'default';

protected function getTableQuery(): Builder
/**
* @return Builder<Item>|null
*/
protected function getTableQuery(): Builder|null
{
if ($this->type == 'default') {
return auth()->user()->items()->with('board.project')->getQuery();
return auth()->user()?->items()->with('board.project')->getQuery();
}

if ($this->type == 'commentedOn') {
return auth()->user()->commentedItems()->getQuery();
return auth()->user()?->commentedItems()->getQuery();
}

return auth()->user()->votedItems()->with('board.project')->latest('votes.created_at')->getQuery();
return auth()->user()?->votedItems()->with('board.project')->latest('votes.created_at')->getQuery();
}

/**
* Get per page select options.
*
* @return int[]
*/
protected function getTableRecordsPerPageSelectOptions(): array
{
return auth()->user()->per_page_setting ?? [5];
}

/**
* Get the table columns.
*
* @return Tables\Columns\TextColumn[]
*/
protected function getTableColumns(): array
{
return [
Expand Down Expand Up @@ -71,7 +87,7 @@ protected function getTableRecordUrlUsing(): ?Closure
};
}

public function render()
public function render(): View
{
return view('livewire.my');
}
Expand Down
13 changes: 13 additions & 0 deletions app/Livewire/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public function mount(): void
]);
}

/**
* @return Forms\Components\Component[] Array of form components.
*/
protected function getFormSchema(): array
{
return [
Expand Down Expand Up @@ -216,6 +219,11 @@ protected function getTableQuery(): Builder|null
return auth()->user()?->userSocials()->latest()->getQuery();
}

/**
* Get the table columns.
*
* @return Tables\Columns\TextColumn[]
*/
protected function getTableColumns(): array
{
return [
Expand All @@ -225,6 +233,11 @@ protected function getTableColumns(): array
];
}

/**
* Get the table bulk actions.
*
* @return Tables\Actions\BulkAction[]
*/
protected function getTableBulkActions(): array
{
return [
Expand Down

0 comments on commit 3085d83

Please sign in to comment.