diff --git a/resources/views/pages/⚡dashboard.blade.php b/resources/views/pages/⚡dashboard.blade.php index 8d9716c..bcbfa81 100644 --- a/resources/views/pages/⚡dashboard.blade.php +++ b/resources/views/pages/⚡dashboard.blade.php @@ -2,6 +2,7 @@ use App\Models\Folder; use App\Models\Todo; +use App\TodoStatus; use Illuminate\Database\Eloquent\Builder; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Carbon; @@ -30,6 +31,8 @@ new #[Title('Dashboard')] class extends Component public string $description = ''; + public string $todoStatus = 'open'; + public ?string $dueDate = null; public string $notes = ''; @@ -73,7 +76,7 @@ new #[Title('Dashboard')] class extends Component public function openCreateForm(?int $folderId = null): void { - $this->reset('editingTodoId', 'description', 'dueDate', 'notes', 'formFolderId'); + $this->reset('editingTodoId', 'description', 'todoStatus', 'dueDate', 'notes', 'formFolderId'); $this->resetErrorBag(); if ($folderId !== null && $this->folderTree->contains(fn ($node) => $node['folder']->id === $folderId)) { @@ -91,6 +94,7 @@ new #[Title('Dashboard')] class extends Component $this->editingTodoId = $todo->id; $this->description = $todo->description; + $this->todoStatus = $todo->status->value; $this->dueDate = $todo->due_date?->format('Y-m-d') ?? ''; $this->notes = $todo->notes ?? ''; $this->formFolderId = $todo->folder_id; @@ -103,6 +107,7 @@ new #[Title('Dashboard')] class extends Component { $validated = $this->validate([ 'description' => ['required', 'string', 'max:255'], + 'todoStatus' => ['required', Rule::enum(TodoStatus::class)], 'dueDate' => ['nullable', 'date'], 'notes' => ['nullable', 'string', 'max:'.auth()->user()->notesLimit()], 'formFolderId' => ['required', 'integer', Rule::exists('folders', 'id')->where('user_id', auth()->id())], @@ -111,6 +116,7 @@ new #[Title('Dashboard')] class extends Component $data = [ 'folder_id' => $validated['formFolderId'], 'description' => $validated['description'], + 'status' => TodoStatus::from($validated['todoStatus']), 'due_date' => filled($validated['dueDate']) ? Carbon::parse($validated['dueDate']) : null, 'notes' => filled($validated['notes']) ? $validated['notes'] : null, ]; @@ -121,7 +127,7 @@ new #[Title('Dashboard')] class extends Component Todo::create($data + ['user_id' => auth()->id()]); } - $this->reset('showTodoForm', 'editingTodoId', 'description', 'dueDate', 'notes', 'formFolderId'); + $this->reset('showTodoForm', 'editingTodoId', 'description', 'todoStatus', 'dueDate', 'notes', 'formFolderId'); } public function toggleComplete(int $todoId): void @@ -161,7 +167,7 @@ new #[Title('Dashboard')] class extends Component $query = Todo::query()->forUser(auth()->id()); return [ - 'open' => (clone $query)->incomplete()->count(), + 'open' => (clone $query)->active()->count(), 'completed' => (clone $query)->completed()->count(), 'overdue' => (clone $query)->overdue()->count(), 'dueToday' => (clone $query)->dueToday()->count(), @@ -191,7 +197,7 @@ new #[Title('Dashboard')] class extends Component $openByFolder = Todo::query() ->forUser(auth()->id()) - ->incomplete() + ->active() ->pluck('folder_id') ->countBy(); $overdueByFolder = Todo::query() @@ -216,6 +222,19 @@ new #[Title('Dashboard')] class extends Component return $this->search !== '' || $this->folderId !== null || $this->status !== 'all'; } + #[Computed] + public function statusFilters(): array + { + return [ + 'all' => 'All', + ...collect(TodoStatus::cases()) + ->mapWithKeys(fn (TodoStatus $status) => [$status->value => $status->label()]) + ->all(), + 'completed' => 'Completed', + 'overdue' => 'Overdue', + ]; + } + #[Computed] public function todos(): LengthAwarePaginator { @@ -232,10 +251,11 @@ new #[Title('Dashboard')] class extends Component ) ->when($this->status, function (Builder $query) { return match ($this->status) { - 'open' => $query->incomplete(), + 'open' => $query->active(), 'completed' => $query->completed(), 'overdue' => $query->overdue(), - default => $query, + 'all', '' => $query, + default => $query->where('status', $this->status)->incomplete(), }; }) ->orderByRaw('completed_at IS NOT NULL') @@ -342,7 +362,7 @@ new #[Title('Dashboard')] class extends Component @endif
- @foreach (['all' => 'All', 'open' => 'Open', 'completed' => 'Completed', 'overdue' => 'Overdue'] as $value => $label) + @foreach ($this->statusFilters as $value => $label) {{ __('Done') }} {{ __('Description') }} + {{ __('Status') }} {{ __('Folder') }} {{ __('Due') }} {{ __('Created') }} @@ -403,12 +424,18 @@ new #[Title('Dashboard')] class extends Component - {{ $todo->description }} + $todo->completed_at !== null])>{{ $todo->description }} @if ($todo->notes) {{ $todo->notes }} @endif + + + {{ $todo->status->label() }} + + + {{ $todo->folder?->parent?->name }}@if ($todo->folder?->parent) / @endif{{ $todo->folder?->name }} @@ -452,7 +479,7 @@ new #[Title('Dashboard')] class extends Component @empty - + {{ __('No todos match your filters.') }} @@ -480,6 +507,16 @@ new #[Title('Dashboard')] class extends Component + + {{ __('Status') }} + + @foreach (TodoStatus::cases() as $status) + {{ $status->label() }} + @endforeach + + + + {{ __('Due date') }} diff --git a/resources/views/pages/⚡folders.blade.php b/resources/views/pages/⚡folders.blade.php index 752c727..83a1ce9 100644 --- a/resources/views/pages/⚡folders.blade.php +++ b/resources/views/pages/⚡folders.blade.php @@ -2,6 +2,7 @@ use App\Models\Folder; use App\Models\Todo; +use App\TodoStatus; use Illuminate\Support\Carbon; use Illuminate\Support\Collection; use Illuminate\Validation\Rule; @@ -34,6 +35,8 @@ new #[Title('Folders')] class extends Component public string $todoDescription = ''; + public string $todoStatus = 'open'; + public ?string $todoDueDate = null; public string $todoNotes = ''; @@ -132,8 +135,8 @@ new #[Title('Folders')] class extends Component $this->folderForUser($folderId); $this->todoFolderId = $folderId; - $this->reset('todoDescription', 'todoDueDate', 'todoNotes'); - $this->resetErrorBag('todoDescription', 'todoDueDate', 'todoNotes'); + $this->reset('todoDescription', 'todoStatus', 'todoDueDate', 'todoNotes'); + $this->resetErrorBag('todoDescription', 'todoStatus', 'todoDueDate', 'todoNotes'); $this->showTodoForm = true; } @@ -143,6 +146,7 @@ new #[Title('Folders')] class extends Component $validated = $this->validate([ 'todoDescription' => ['required', 'string', 'max:255'], + 'todoStatus' => ['required', Rule::enum(TodoStatus::class)], 'todoDueDate' => ['nullable', 'date'], 'todoNotes' => ['nullable', 'string', 'max:'.auth()->user()->notesLimit()], ]); @@ -151,11 +155,12 @@ new #[Title('Folders')] class extends Component 'user_id' => auth()->id(), 'folder_id' => $folder->id, 'description' => $validated['todoDescription'], + 'status' => TodoStatus::from($validated['todoStatus']), 'due_date' => filled($validated['todoDueDate']) ? Carbon::parse($validated['todoDueDate']) : null, 'notes' => filled($validated['todoNotes']) ? $validated['todoNotes'] : null, ]); - $this->reset('showTodoForm', 'todoFolderId', 'todoDescription', 'todoDueDate', 'todoNotes'); + $this->reset('showTodoForm', 'todoFolderId', 'todoDescription', 'todoStatus', 'todoDueDate', 'todoNotes'); } #[Computed] @@ -164,12 +169,34 @@ new #[Title('Folders')] class extends Component return Folder::treeForUser(auth()->id()); } + #[Computed] + public function todoFolder(): ?Folder + { + if ($this->todoFolderId === null) { + return null; + } + + return Folder::query()->with('parent')->forUser(auth()->id())->find($this->todoFolderId); + } + + #[Computed] + public function todoFolderPath(): string + { + if ($this->todoFolder === null) { + return ''; + } + + return collect([$this->todoFolder->parent?->name, $this->todoFolder->name]) + ->filter() + ->implode(' / '); + } + #[Computed] public function openCounts(): Collection { return Todo::query() ->forUser(auth()->id()) - ->incomplete() + ->active() ->pluck('folder_id') ->countBy(); } @@ -347,8 +374,26 @@ new #[Title('Folders')] class extends Component
- {{ __('Add todo') }} + @if ($this->todoFolder !== null) + + {{ __('Add todo') }} - {{ $this->todoFolderPath }} + + @else + {{ __('Add todo') }} + @endif {{ __('Add a task with a description. A due date is optional.') }} + + @if ($this->todoFolder !== null) +
+ + + {{ __('Adding to') }} + + {{ $this->todoFolderPath }} + + +
+ @endif
@@ -363,6 +408,16 @@ new #[Title('Folders')] class extends Component + + {{ __('Status') }} + + @foreach (TodoStatus::cases() as $status) + {{ $status->label() }} + @endforeach + + + + {{ __('Due date') }}