This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Concerns\SortsTodos;
|
||||
use App\Models\Folder;
|
||||
use App\Models\Todo;
|
||||
use App\TodoStatus;
|
||||
@@ -17,6 +18,7 @@ use Livewire\WithPagination;
|
||||
|
||||
new #[Title('Dashboard')] class extends Component
|
||||
{
|
||||
use SortsTodos;
|
||||
use WithPagination;
|
||||
|
||||
private const PER_PAGE = 10;
|
||||
@@ -77,6 +79,11 @@ new #[Title('Dashboard')] class extends Component
|
||||
$this->resetPage();
|
||||
}
|
||||
|
||||
protected function sortChanged(): void
|
||||
{
|
||||
$this->resetPage();
|
||||
}
|
||||
|
||||
public function openCreateForm(?int $folderId = null): void
|
||||
{
|
||||
$this->reset('editingTodoId', 'description', 'todoStatus', 'dueDate', 'notes', 'formFolderId');
|
||||
@@ -259,10 +266,9 @@ new #[Title('Dashboard')] class extends Component
|
||||
#[Computed]
|
||||
public function todos(): LengthAwarePaginator
|
||||
{
|
||||
return $this->filteredTodoQuery()
|
||||
->with('folder.parent')
|
||||
->priority()
|
||||
->paginate(self::PER_PAGE);
|
||||
return $this->applyTodoSort(
|
||||
$this->filteredTodoQuery()->with('folder.parent')
|
||||
)->paginate(self::PER_PAGE);
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
@@ -273,6 +279,10 @@ new #[Title('Dashboard')] class extends Component
|
||||
|
||||
public function moveTodo(int $todoId, string $direction): void
|
||||
{
|
||||
if ($this->hasActiveSort()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->todoForAction($todoId, 'update');
|
||||
|
||||
$ids = $this->orderedTodoIds;
|
||||
@@ -293,6 +303,10 @@ new #[Title('Dashboard')] class extends Component
|
||||
|
||||
public function handleSort(int $todoId, int $position): void
|
||||
{
|
||||
if ($this->hasActiveSort()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->todoForAction($todoId, 'update');
|
||||
|
||||
$offset = ($this->todos->currentPage() - 1) * self::PER_PAGE;
|
||||
@@ -518,12 +532,12 @@ new #[Title('Dashboard')] class extends Component
|
||||
<flux:table.columns>
|
||||
<flux:table.column width="3rem"></flux:table.column>
|
||||
<flux:table.column width="3rem">{{ __('Done') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Description') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Status') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Folder') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Due') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Created') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Completed') }}</flux:table.column>
|
||||
<flux:table.column sortable :sorted="$sortBy === 'description'" :direction="$sortDirection" wire:click="sort('description')">{{ __('Description') }}</flux:table.column>
|
||||
<flux:table.column sortable :sorted="$sortBy === 'status'" :direction="$sortDirection" wire:click="sort('status')">{{ __('Status') }}</flux:table.column>
|
||||
<flux:table.column sortable :sorted="$sortBy === 'folder'" :direction="$sortDirection" wire:click="sort('folder')">{{ __('Folder') }}</flux:table.column>
|
||||
<flux:table.column sortable :sorted="$sortBy === 'due_date'" :direction="$sortDirection" wire:click="sort('due_date')">{{ __('Due') }}</flux:table.column>
|
||||
<flux:table.column sortable :sorted="$sortBy === 'created_at'" :direction="$sortDirection" wire:click="sort('created_at')">{{ __('Created') }}</flux:table.column>
|
||||
<flux:table.column sortable :sorted="$sortBy === 'completed_at'" :direction="$sortDirection" wire:click="sort('completed_at')">{{ __('Completed') }}</flux:table.column>
|
||||
<flux:table.column align="end" width="10rem">{{ __('Actions') }}</flux:table.column>
|
||||
</flux:table.columns>
|
||||
|
||||
@@ -532,7 +546,7 @@ new #[Title('Dashboard')] class extends Component
|
||||
<flux:table.row :key="$todo->id" wire:sort:item="{{ $todo->id }}" data-test="todo-row">
|
||||
<flux:table.cell class="py-0 text-zinc-300 dark:text-zinc-600">
|
||||
@can('update', $todo)
|
||||
<div wire:sort:handle class="inline-flex cursor-grab" title="{{ __('Reorder') }}">
|
||||
<div wire:sort:handle class="{{ $sortBy === null ? 'inline-flex cursor-grab' : 'hidden' }}" title="{{ __('Reorder') }}">
|
||||
<flux:icon.chevrons-up-down variant="micro" />
|
||||
</div>
|
||||
@endcan
|
||||
@@ -607,26 +621,28 @@ new #[Title('Dashboard')] class extends Component
|
||||
<flux:table.cell class="py-0">
|
||||
<div class="flex justify-end gap-1">
|
||||
@can('update', $todo)
|
||||
@if ($todo->id !== ($this->orderedTodoIds[0] ?? null))
|
||||
<flux:button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
icon="chevron-up"
|
||||
:title="__('Move up')"
|
||||
wire:click="moveTodo({{ $todo->id }}, 'up')"
|
||||
data-test="move-todo-up-{{ $todo->id }}"
|
||||
/>
|
||||
@endif
|
||||
@if ($sortBy === null)
|
||||
@if ($todo->id !== ($this->orderedTodoIds[0] ?? null))
|
||||
<flux:button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
icon="chevron-up"
|
||||
:title="__('Move up')"
|
||||
wire:click="moveTodo({{ $todo->id }}, 'up')"
|
||||
data-test="move-todo-up-{{ $todo->id }}"
|
||||
/>
|
||||
@endif
|
||||
|
||||
@if ($todo->id !== ($this->orderedTodoIds[array_key_last($this->orderedTodoIds)] ?? null))
|
||||
<flux:button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
icon="chevron-down"
|
||||
:title="__('Move down')"
|
||||
wire:click="moveTodo({{ $todo->id }}, 'down')"
|
||||
data-test="move-todo-down-{{ $todo->id }}"
|
||||
/>
|
||||
@if ($todo->id !== ($this->orderedTodoIds[array_key_last($this->orderedTodoIds)] ?? null))
|
||||
<flux:button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
icon="chevron-down"
|
||||
:title="__('Move down')"
|
||||
wire:click="moveTodo({{ $todo->id }}, 'down')"
|
||||
data-test="move-todo-down-{{ $todo->id }}"
|
||||
/>
|
||||
@endif
|
||||
@endif
|
||||
|
||||
<flux:button
|
||||
|
||||
Reference in New Issue
Block a user