43 lines
983 B
PHP
43 lines
983 B
PHP
<?php
|
|
|
|
namespace App\Livewire\Widgets;
|
|
|
|
use App\Models\Message;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Component;
|
|
|
|
class FoxAvatar extends Component
|
|
{
|
|
public string $status = 'online'; // online | thinking | speaking
|
|
|
|
public function getRecentLabelProperty(): string
|
|
{
|
|
$latest = Message::latest()->first();
|
|
|
|
return match (true) {
|
|
! $latest => 'bereit',
|
|
$latest->role === Message::ROLE_USER => 'denkt nach …',
|
|
default => 'online',
|
|
};
|
|
}
|
|
|
|
#[On('echo:fox,.message.created')]
|
|
public function onBroadcastedMessage(array $data = []): void
|
|
{
|
|
$this->status = ($data['role'] ?? null) === 'user' ? 'thinking' : 'online';
|
|
}
|
|
|
|
#[On('fox-thinking')]
|
|
public function setThinking(): void
|
|
{
|
|
$this->status = 'thinking';
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.widgets.fox-avatar', [
|
|
'label' => $this->recentLabel,
|
|
]);
|
|
}
|
|
}
|