From 64fd59101da0bbf860a02f06b4d46edacc9f29f5 Mon Sep 17 00:00:00 2001 From: salam Date: Mon, 9 Mar 2026 12:09:10 +0100 Subject: [PATCH] add lazy load to EncounterHistory --- app/Livewire/EncounterHistory.php | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/app/Livewire/EncounterHistory.php b/app/Livewire/EncounterHistory.php index 280a09be..5d22751e 100644 --- a/app/Livewire/EncounterHistory.php +++ b/app/Livewire/EncounterHistory.php @@ -12,14 +12,18 @@ use Filament\Schemas\Contracts\HasSchemas; use Filament\Schemas\Schema; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Http; +use Livewire\Attributes\Lazy; use Livewire\Component; +#[Lazy] class EncounterHistory extends Component implements HasSchemas { use InteractsWithSchemas; public $data = []; + public $betsapi_id; + public $home; public $away; @@ -27,7 +31,7 @@ class EncounterHistory extends Component implements HasSchemas public function eventsInfolist(Schema $schema): Schema { return $schema - ->record($this->data) + ->record($this->getData()) ->components([ Tabs::make('Tabs') ->tabs([ @@ -68,8 +72,8 @@ class EncounterHistory extends Component implements HasSchemas TextEntry::make('time')->formatStateUsing(function ($state) { return Carbon::createFromTimestamp($state)->format('d. m. Y H:i'); }), - TextEntry::make('home.name')->color(fn ($state) => $state == $this->home ? 'primary' : 'gray'), - TextEntry::make('away.name')->color(fn ($state) => $state == $this->home ? 'primary' : 'gray'), + TextEntry::make('home.name')->color(fn ($state) => $state == $this->home ? 'primary' : 'warning'), + TextEntry::make('away.name')->color(fn ($state) => $state == $this->home ? 'primary' : 'warning'), TextEntry::make('ss'), ]), ]), @@ -89,8 +93,8 @@ class EncounterHistory extends Component implements HasSchemas TextEntry::make('time')->formatStateUsing(function ($state) { return Carbon::createFromTimestamp($state)->format('d. m. Y H:i'); }), - TextEntry::make('home.name')->color(fn ($state) => $state == $this->away ? 'warning' : 'gray'), - TextEntry::make('away.name')->color(fn ($state) => $state == $this->away ? 'warning' : 'gray'), + TextEntry::make('home.name')->color(fn ($state) => $state == $this->away ? 'warning' : 'primary'), + TextEntry::make('away.name')->color(fn ($state) => $state == $this->away ? 'warning' : 'primary'), TextEntry::make('ss'), ]), ]), @@ -100,9 +104,7 @@ class EncounterHistory extends Component implements HasSchemas public function mount($betsapi_id) { - $this->data = Http::get('https://api.b365api.com/v1/event/history?token='.config('env.betsapi_token').'&event_id='.$betsapi_id)->json(); - $this->home = $this->data['results']['h2h']['0']['home']['name']; - $this->away = $this->data['results']['h2h']['0']['away']['name']; + $this->betsapi_id = $betsapi_id; } public function getHome() @@ -114,4 +116,14 @@ class EncounterHistory extends Component implements HasSchemas { return $this->away; } + + public function getData() + { + $res = Http::get('https://api.b365api.com/v1/event/history?token='.config('env.betsapi_token').'&event_id='.$this->betsapi_id)->json(); + + $this->home = $res['results']['h2h']['0']['home']['name']; + $this->away = $res['results']['h2h']['0']['away']['name']; + + return $res; + } }