'tasks'])] #[Lazy] class Index extends Component { public static function placeholder(array $params = []): View { return view('livewire.tasks.placeholder'); } #[Url(as: 'filter', keep: true)] public string $filter = 'open'; /** @var array */ protected array $allowedFilters = ['open', 'done', 'all']; public function mount(): void { if (! in_array($this->filter, $this->allowedFilters, true)) { $this->filter = 'open'; } } public function setFilter(string $filter): void { if (in_array($filter, $this->allowedFilters, true)) { $this->filter = $filter; } } /** @var array */ public array $startedKeys = []; public function startTask(string $slug): void { $task = collect($this->tasks)->firstWhere('slug', $slug); if ($task === null) { return; } if (! in_array($slug, $this->startedKeys, true)) { $this->startedKeys[] = $slug; } // Start navigates to the dedicated Run page (per-slug quiz + Lerni AI). $this->redirectRoute('tasks.run', ['slug' => $slug], navigate: true); } public function repeatTask(string $slug): void { $this->startTask($slug); } #[Computed] public function tasks(): array { return config('tasks', []); } #[Computed] public function filteredTasks(): array { if ($this->filter === 'all') { return $this->tasks; } return array_values(array_filter($this->tasks, fn($t) => $t['status'] === $this->filter)); } #[Computed] public function counts(): array { return [ 'open' => count(array_filter($this->tasks, fn($t) => $t['status'] === 'open')), 'done' => count(array_filter($this->tasks, fn($t) => $t['status'] === 'done')), 'all' => count($this->tasks), ]; } public function render(): View { return view('livewire.tasks.index'); } }