Skip to content

Commit

Permalink
refactor: update RecentMentions, RecentComments and RecentItems
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiorodriguesroque committed Nov 13, 2024
1 parent 30f1a58 commit c44683a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
12 changes: 9 additions & 3 deletions app/Livewire/RecentMentions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@

namespace App\Livewire;

use App\Models\Comment;
use Closure;
use Filament\Tables;
use Illuminate\Contracts\View\View;
use Livewire\Component;
use Filament\Forms\Contracts\HasForms;
use Filament\Tables\Contracts\HasTable;
use Illuminate\Database\Eloquent\Builder;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Tables\Concerns\InteractsWithTable;
use Xetaio\Mentions\Models\Mention;

class RecentMentions extends Component implements HasTable, HasForms
{
use InteractsWithTable, InteractsWithForms;

protected function getTableQuery(): Builder
/**
* @return Builder<Comment>|null
*/
protected function getTableQuery(): Builder|null
{
return auth()->user()->mentions()->latest('mentions.created_at')->getQuery();
return auth()->user()?->mentions()->latest('mentions.created_at')->getQuery();
}

protected function getTableRecordsPerPageSelectOptions(): array
Expand All @@ -41,7 +47,7 @@ protected function getTableRecordUrlUsing(): ?Closure
};
}

public function render()
public function render(): View
{
return view('livewire.recent-mentions');
}
Expand Down
6 changes: 5 additions & 1 deletion app/Livewire/Welcome/RecentComments.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Closure;
use Filament\Tables;
use App\Models\Comment;
use Illuminate\Contracts\View\View;
use Livewire\Component;
use Filament\Forms\Contracts\HasForms;
use Filament\Tables\Contracts\HasTable;
Expand All @@ -16,6 +17,9 @@ class RecentComments extends Component implements HasTable, HasForms
{
use InteractsWithTable, InteractsWithForms;

/**
* @return Builder<Comment>
*/
protected function getTableQuery(): Builder
{
return Comment::query()->public()->limit(10);
Expand Down Expand Up @@ -55,7 +59,7 @@ protected function getDefaultTableSortDirection(): ?string
return 'desc';
}

public function render()
public function render(): View
{
return view('livewire.welcome.recent-comments');
}
Expand Down
6 changes: 5 additions & 1 deletion app/Livewire/Welcome/RecentItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Closure;
use App\Models\Item;
use Filament\Tables;
use Illuminate\Contracts\View\View;
use Livewire\Component;
use Illuminate\Support\Arr;
use App\Settings\GeneralSettings;
Expand All @@ -18,6 +19,9 @@ class RecentItems extends Component implements HasTable, HasForms
{
use InteractsWithTable, InteractsWithForms;

/**
* @return Builder<Item>
*/
protected function getTableQuery(): Builder
{
$recentItemsConfig = collect(app(GeneralSettings::class)->dashboard_items)->first();
Expand Down Expand Up @@ -88,7 +92,7 @@ protected function getDefaultTableSortDirection(): ?string
return 'desc';
}

public function render()
public function render(): View
{
return view('livewire.welcome.recent-items');
}
Expand Down

0 comments on commit c44683a

Please sign in to comment.