47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Pages\Analytics;
|
|
|
|
use App\Domains\Analytics\Models\Click;
|
|
use App\Domains\Workspace\Models\Workspace;
|
|
use Illuminate\View\View;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Component;
|
|
|
|
class Index extends Component
|
|
{
|
|
/** @var array<int, array<string, mixed>> */
|
|
public array $recentClicks = [];
|
|
|
|
public int $totalToday = 0;
|
|
|
|
public function mount(): void
|
|
{
|
|
/** @var Workspace $workspace */
|
|
$workspace = app('current_workspace');
|
|
|
|
$this->totalToday = Click::where('workspace_id', $workspace->id)
|
|
->whereDate('clicked_at', today())
|
|
->count();
|
|
}
|
|
|
|
/** @param array<string, mixed> $data */
|
|
#[On('echo:workspace.{workspaceId}.analytics,click.recorded')]
|
|
public function handleNewClick(array $data): void
|
|
{
|
|
array_unshift($this->recentClicks, $data);
|
|
$this->recentClicks = array_slice($this->recentClicks, 0, 10);
|
|
$this->totalToday++;
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
/** @var Workspace $workspace */
|
|
$workspace = app('current_workspace');
|
|
|
|
return view('livewire.pages.analytics.index', [
|
|
'workspace' => $workspace,
|
|
])->layout('layouts.nimuli-app', ['title' => 'Analytics']);
|
|
}
|
|
}
|