add lazy load to EncounterHistory
This commit is contained in:
1 parent
22a17f1d0a
commit
64fd59101d
1 file changed
+20
-8
@@ -12,14 +12,18 @@ use Filament\Schemas\Contracts\HasSchemas;
|
|||||||
use Filament\Schemas\Schema;
|
use Filament\Schemas\Schema;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Livewire\Attributes\Lazy;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
|
#[Lazy]
|
||||||
class EncounterHistory extends Component implements HasSchemas
|
class EncounterHistory extends Component implements HasSchemas
|
||||||
{
|
{
|
||||||
use InteractsWithSchemas;
|
use InteractsWithSchemas;
|
||||||
|
|
||||||
public $data = [];
|
public $data = [];
|
||||||
|
|
||||||
|
public $betsapi_id;
|
||||||
|
|
||||||
public $home;
|
public $home;
|
||||||
|
|
||||||
public $away;
|
public $away;
|
||||||
@@ -27,7 +31,7 @@ class EncounterHistory extends Component implements HasSchemas
|
|||||||
public function eventsInfolist(Schema $schema): Schema
|
public function eventsInfolist(Schema $schema): Schema
|
||||||
{
|
{
|
||||||
return $schema
|
return $schema
|
||||||
->record($this->data)
|
->record($this->getData())
|
||||||
->components([
|
->components([
|
||||||
Tabs::make('Tabs')
|
Tabs::make('Tabs')
|
||||||
->tabs([
|
->tabs([
|
||||||
@@ -68,8 +72,8 @@ class EncounterHistory extends Component implements HasSchemas
|
|||||||
TextEntry::make('time')->formatStateUsing(function ($state) {
|
TextEntry::make('time')->formatStateUsing(function ($state) {
|
||||||
return Carbon::createFromTimestamp($state)->format('d. m. Y H:i');
|
return Carbon::createFromTimestamp($state)->format('d. m. Y H:i');
|
||||||
}),
|
}),
|
||||||
TextEntry::make('home.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' : 'gray'),
|
TextEntry::make('away.name')->color(fn ($state) => $state == $this->home ? 'primary' : 'warning'),
|
||||||
TextEntry::make('ss'),
|
TextEntry::make('ss'),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
@@ -89,8 +93,8 @@ class EncounterHistory extends Component implements HasSchemas
|
|||||||
TextEntry::make('time')->formatStateUsing(function ($state) {
|
TextEntry::make('time')->formatStateUsing(function ($state) {
|
||||||
return Carbon::createFromTimestamp($state)->format('d. m. Y H:i');
|
return Carbon::createFromTimestamp($state)->format('d. m. Y H:i');
|
||||||
}),
|
}),
|
||||||
TextEntry::make('home.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' : 'gray'),
|
TextEntry::make('away.name')->color(fn ($state) => $state == $this->away ? 'warning' : 'primary'),
|
||||||
TextEntry::make('ss'),
|
TextEntry::make('ss'),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
@@ -100,9 +104,7 @@ class EncounterHistory extends Component implements HasSchemas
|
|||||||
|
|
||||||
public function mount($betsapi_id)
|
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->betsapi_id = $betsapi_id;
|
||||||
$this->home = $this->data['results']['h2h']['0']['home']['name'];
|
|
||||||
$this->away = $this->data['results']['h2h']['0']['away']['name'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHome()
|
public function getHome()
|
||||||
@@ -114,4 +116,14 @@ class EncounterHistory extends Component implements HasSchemas
|
|||||||
{
|
{
|
||||||
return $this->away;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user