updated folder colors, reordering, new todo page, updated sidebar
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Locked;
|
||||
@@ -18,6 +19,8 @@ new #[Title('Dashboard')] class extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
private const PER_PAGE = 10;
|
||||
|
||||
#[Locked]
|
||||
public ?int $editingTodoId = null;
|
||||
|
||||
@@ -124,7 +127,10 @@ new #[Title('Dashboard')] class extends Component
|
||||
if ($this->editingTodoId !== null) {
|
||||
$this->todoForUser($this->editingTodoId)->update($data);
|
||||
} else {
|
||||
Todo::create($data + ['user_id' => auth()->id()]);
|
||||
Todo::create($data + [
|
||||
'user_id' => auth()->id(),
|
||||
'position' => Todo::nextPositionFor(auth()->user()),
|
||||
]);
|
||||
}
|
||||
|
||||
$this->reset('showTodoForm', 'editingTodoId', 'description', 'todoStatus', 'dueDate', 'notes', 'formFolderId');
|
||||
@@ -134,9 +140,15 @@ new #[Title('Dashboard')] class extends Component
|
||||
{
|
||||
$todo = $this->todoForUser($todoId);
|
||||
|
||||
$todo->update([
|
||||
'completed_at' => $todo->completed_at === null ? now() : null,
|
||||
]);
|
||||
$data = ['completed_at' => $todo->completed_at === null ? now() : null];
|
||||
|
||||
if ($todo->completed_at === null && in_array($todo->status, [TodoStatus::Open, TodoStatus::InProgress], true)) {
|
||||
$data['status'] = TodoStatus::Completed;
|
||||
} elseif ($todo->completed_at !== null && $todo->status === TodoStatus::Completed) {
|
||||
$data['status'] = TodoStatus::Open;
|
||||
}
|
||||
|
||||
$todo->update($data);
|
||||
}
|
||||
|
||||
public function confirmTodoDelete(int $todoId): void
|
||||
@@ -237,10 +249,79 @@ new #[Title('Dashboard')] class extends Component
|
||||
|
||||
#[Computed]
|
||||
public function todos(): LengthAwarePaginator
|
||||
{
|
||||
return $this->filteredTodoQuery()
|
||||
->with('folder.parent')
|
||||
->priority()
|
||||
->paginate(self::PER_PAGE);
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function orderedTodoIds(): array
|
||||
{
|
||||
return $this->filteredTodoQuery()->priority()->pluck('id')->all();
|
||||
}
|
||||
|
||||
public function moveTodo(int $todoId, string $direction): void
|
||||
{
|
||||
$this->todoForUser($todoId);
|
||||
|
||||
$ids = $this->filteredTodoQuery()->priority()->pluck('id')->all();
|
||||
$currentIndex = array_search($todoId, $ids, true);
|
||||
|
||||
if ($currentIndex === false || $ids === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$target = $direction === 'up' ? $currentIndex - 1 : $currentIndex + 1;
|
||||
|
||||
if ($target < 0 || $target >= count($ids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->reorderTodo($todoId, $ids, $target);
|
||||
}
|
||||
|
||||
public function handleSort(int $todoId, int $position): void
|
||||
{
|
||||
$this->todoForUser($todoId);
|
||||
|
||||
$ids = $this->filteredTodoQuery()->priority()->pluck('id')->all();
|
||||
$currentIndex = array_search($todoId, $ids, true);
|
||||
|
||||
if ($currentIndex === false || $ids === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$offset = ($this->todos->currentPage() - 1) * self::PER_PAGE;
|
||||
|
||||
$this->reorderTodo($todoId, $ids, $offset + $position);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, int> $ids
|
||||
*/
|
||||
private function reorderTodo(int $todoId, array $ids, int $newIndex): void
|
||||
{
|
||||
unset($ids[array_search($todoId, $ids, true)]);
|
||||
$ids = array_values($ids);
|
||||
|
||||
$newIndex = max(0, min($newIndex, count($ids)));
|
||||
|
||||
array_splice($ids, $newIndex, 0, $todoId);
|
||||
|
||||
foreach ($ids as $position => $id) {
|
||||
Todo::query()->forUser(auth()->id())->whereKey($id)->update(['position' => $position]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder<Todo>
|
||||
*/
|
||||
private function filteredTodoQuery(): Builder
|
||||
{
|
||||
return Todo::query()
|
||||
->forUser(auth()->id())
|
||||
->with('folder.parent')
|
||||
->when(
|
||||
$this->search !== '',
|
||||
fn (Builder $query) => $query->where('description', 'like', '%'.$this->search.'%')
|
||||
@@ -257,12 +338,7 @@ new #[Title('Dashboard')] class extends Component
|
||||
'all', '' => $query,
|
||||
default => $query->where('status', $this->status)->incomplete(),
|
||||
};
|
||||
})
|
||||
->orderByRaw('completed_at IS NOT NULL')
|
||||
->orderByRaw('due_date IS NULL')
|
||||
->orderBy('due_date')
|
||||
->orderByDesc('id')
|
||||
->paginate(10);
|
||||
});
|
||||
}
|
||||
|
||||
private function descendantIds(int $folderId): array
|
||||
@@ -311,7 +387,7 @@ new #[Title('Dashboard')] class extends Component
|
||||
</flux:callout>
|
||||
@endif
|
||||
|
||||
<div class="grid grid-cols-4 gap-3">
|
||||
<div class="grid grid-cols-2 gap-3 md:grid-cols-4">
|
||||
<flux:card size="sm">
|
||||
<flux:heading size="sm" class="text-zinc-500">{{ __('Open') }}</flux:heading>
|
||||
<flux:heading size="xl" class="mt-1" data-test="count-open">{{ $this->todoCounts['open'] }}</flux:heading>
|
||||
@@ -402,18 +478,26 @@ new #[Title('Dashboard')] class extends Component
|
||||
<flux:card>
|
||||
<flux:table :paginate="$this->todos">
|
||||
<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 align="end" width="7rem">{{ __('Actions') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Completed') }}</flux:table.column>
|
||||
<flux:table.column align="end" width="10rem">{{ __('Actions') }}</flux:table.column>
|
||||
</flux:table.columns>
|
||||
|
||||
<flux:table.rows>
|
||||
<flux:table.rows wire:sort="handleSort">
|
||||
@forelse ($this->todos as $todo)
|
||||
<flux:table.row :key="$todo->id" data-test="todo-row">
|
||||
<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">
|
||||
<div wire:sort:handle class="inline-flex cursor-grab" :title="__('Reorder')">
|
||||
<flux:icon.chevrons-up-down variant="micro" />
|
||||
</div>
|
||||
</flux:table.cell>
|
||||
|
||||
<flux:table.cell class="py-0">
|
||||
<flux:checkbox
|
||||
:checked="$todo->completed_at !== null"
|
||||
@@ -437,7 +521,10 @@ new #[Title('Dashboard')] class extends Component
|
||||
</flux:table.cell>
|
||||
|
||||
<flux:table.cell class="text-zinc-500">
|
||||
{{ $todo->folder?->parent?->name }}@if ($todo->folder?->parent) / @endif{{ $todo->folder?->name }}
|
||||
<div class="flex items-center gap-1.5">
|
||||
<x-folder-dot :color="$todo->folder?->color" />
|
||||
<span class="truncate">{{ $todo->folder?->parent?->name }}@if ($todo->folder?->parent) / @endif{{ $todo->folder?->name }}</span>
|
||||
</div>
|
||||
</flux:table.cell>
|
||||
|
||||
<flux:table.cell>
|
||||
@@ -456,8 +543,49 @@ new #[Title('Dashboard')] class extends Component
|
||||
{{ $todo->created_at->format('M j, Y') }}
|
||||
</flux:table.cell>
|
||||
|
||||
<flux:table.cell data-test="todo-completed-{{ $todo->id }}">
|
||||
@if ($todo->completed_at)
|
||||
<div class="text-zinc-700 dark:text-zinc-300">{{ $todo->completed_at->format('M j, Y') }}</div>
|
||||
@if ($todo->daysToComplete() === 0)
|
||||
<flux:text size="sm" class="block text-zinc-500">{{ __('Same day') }}</flux:text>
|
||||
@else
|
||||
<flux:text
|
||||
size="sm"
|
||||
class="block text-zinc-500"
|
||||
data-test="days-to-complete-{{ $todo->id }}"
|
||||
>
|
||||
{{ __('Completed in') }} {{ $todo->daysToComplete() }} {{ Str::plural('day', $todo->daysToComplete()) }}
|
||||
</flux:text>
|
||||
@endif
|
||||
@else
|
||||
<flux:text class="text-zinc-400">—</flux:text>
|
||||
@endif
|
||||
</flux:table.cell>
|
||||
|
||||
<flux:table.cell class="py-0">
|
||||
<div class="flex justify-end gap-1">
|
||||
@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 }}"
|
||||
/>
|
||||
@endif
|
||||
|
||||
<flux:button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
@@ -479,7 +607,7 @@ new #[Title('Dashboard')] class extends Component
|
||||
</flux:table.row>
|
||||
@empty
|
||||
<flux:table.row>
|
||||
<flux:table.cell colspan="7" align="center" class="py-10">
|
||||
<flux:table.cell colspan="9" align="center" class="py-10">
|
||||
<flux:text>{{ __('No todos match your filters.') }}</flux:text>
|
||||
</flux:table.cell>
|
||||
</flux:table.row>
|
||||
|
||||
Reference in New Issue
Block a user