fox/app/Livewire/Goals.php

45 lines
1005 B
PHP

<?php
namespace App\Livewire;
use App\Models\Goal;
use Livewire\Attributes\On;
use Livewire\Attributes\Title;
use Livewire\Component;
#[Title('Ziele · Fox')]
class Goals extends Component
{
#[On('goal-created')]
public function refresh(): void
{
// No-op: triggert Re-Render.
}
public function updateProgress(int $id, int $progress): void
{
Goal::where('id', $id)->update(['progress' => max(0, min(100, $progress))]);
}
public function setStatus(int $id, string $status): void
{
if (! in_array($status, [Goal::STATUS_ACTIVE, Goal::STATUS_PAUSED, Goal::STATUS_DONE, Goal::STATUS_ABANDONED], true)) {
return;
}
Goal::where('id', $id)->update(['status' => $status]);
}
public function destroy(int $id): void
{
Goal::where('id', $id)->delete();
}
public function render()
{
return view('livewire.goals', [
'goals' => Goal::latest()->get(),
]);
}
}