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>
|
||||
|
||||
@@ -15,11 +15,15 @@ new #[Title('Folders')] class extends Component
|
||||
{
|
||||
public string $newFolderName = '';
|
||||
|
||||
public string $newFolderColor = '';
|
||||
|
||||
#[Locked]
|
||||
public ?int $creatingChildOf = null;
|
||||
|
||||
public string $newChildName = '';
|
||||
|
||||
public string $newChildColor = '';
|
||||
|
||||
#[Locked]
|
||||
public ?int $renamingFolderId = null;
|
||||
|
||||
@@ -28,6 +32,14 @@ new #[Title('Folders')] class extends Component
|
||||
#[Locked]
|
||||
public ?int $confirmingFolderDelete = null;
|
||||
|
||||
#[Locked]
|
||||
public ?int $expandedFolderId = null;
|
||||
|
||||
#[Locked]
|
||||
public ?int $colorEditingFolderId = null;
|
||||
|
||||
public string $colorDraft = '';
|
||||
|
||||
public bool $showTodoForm = false;
|
||||
|
||||
#[Locked]
|
||||
@@ -45,15 +57,17 @@ new #[Title('Folders')] class extends Component
|
||||
{
|
||||
$validated = $this->validate([
|
||||
'newFolderName' => $this->folderNameRules(parentId: null),
|
||||
'newFolderColor' => $this->folderColorRules(),
|
||||
]);
|
||||
|
||||
Folder::create([
|
||||
'user_id' => auth()->id(),
|
||||
'name' => $validated['newFolderName'],
|
||||
'color' => filled($validated['newFolderColor']) ? $validated['newFolderColor'] : null,
|
||||
'parent_id' => null,
|
||||
]);
|
||||
|
||||
$this->reset('newFolderName');
|
||||
$this->reset('newFolderName', 'newFolderColor');
|
||||
}
|
||||
|
||||
public function startChildCreate(int $folderId): void
|
||||
@@ -61,13 +75,13 @@ new #[Title('Folders')] class extends Component
|
||||
$this->folderForUser($folderId);
|
||||
|
||||
$this->creatingChildOf = $folderId;
|
||||
$this->reset('newChildName');
|
||||
$this->resetErrorBag('newChildName');
|
||||
$this->reset('newChildName', 'newChildColor');
|
||||
$this->resetErrorBag('newChildName', 'newChildColor');
|
||||
}
|
||||
|
||||
public function cancelChildCreate(): void
|
||||
{
|
||||
$this->reset('creatingChildOf', 'newChildName');
|
||||
$this->reset('creatingChildOf', 'newChildName', 'newChildColor');
|
||||
}
|
||||
|
||||
public function createChildFolder(): void
|
||||
@@ -76,15 +90,17 @@ new #[Title('Folders')] class extends Component
|
||||
|
||||
$validated = $this->validate([
|
||||
'newChildName' => $this->folderNameRules(parentId: $this->creatingChildOf),
|
||||
'newChildColor' => $this->folderColorRules(),
|
||||
]);
|
||||
|
||||
Folder::create([
|
||||
'user_id' => auth()->id(),
|
||||
'name' => $validated['newChildName'],
|
||||
'color' => filled($validated['newChildColor']) ? $validated['newChildColor'] : null,
|
||||
'parent_id' => $this->creatingChildOf,
|
||||
]);
|
||||
|
||||
$this->reset('creatingChildOf', 'newChildName');
|
||||
$this->reset('creatingChildOf', 'newChildName', 'newChildColor');
|
||||
}
|
||||
|
||||
public function startRename(int $folderId): void
|
||||
@@ -124,12 +140,70 @@ new #[Title('Folders')] class extends Component
|
||||
|
||||
public function deleteFolder(): void
|
||||
{
|
||||
$this->folderForUser($this->confirmingFolderDelete)->delete();
|
||||
$folder = $this->folderForUser($this->confirmingFolderDelete);
|
||||
|
||||
if ($this->expandedFolderId === $folder->id) {
|
||||
$this->expandedFolderId = null;
|
||||
}
|
||||
|
||||
$folder->delete();
|
||||
|
||||
$this->confirmingFolderDelete = null;
|
||||
$this->modal('confirm-folder-delete')->close();
|
||||
}
|
||||
|
||||
public function toggleExpandFolder(int $folderId): void
|
||||
{
|
||||
$this->folderForUser($folderId);
|
||||
|
||||
$this->expandedFolderId = $this->expandedFolderId === $folderId ? null : $folderId;
|
||||
}
|
||||
|
||||
public function startColorEdit(int $folderId): void
|
||||
{
|
||||
$folder = $this->folderForUser($folderId);
|
||||
|
||||
$this->colorEditingFolderId = $folder->id;
|
||||
$this->colorDraft = $folder->color ?? '';
|
||||
$this->resetErrorBag('colorDraft');
|
||||
$this->modal('folder-color')->show();
|
||||
}
|
||||
|
||||
public function saveFolderColor(): void
|
||||
{
|
||||
$folder = $this->folderForUser($this->colorEditingFolderId ?? 0);
|
||||
|
||||
$validated = $this->validate([
|
||||
'colorDraft' => $this->folderColorRules(),
|
||||
]);
|
||||
|
||||
$folder->update([
|
||||
'color' => filled($validated['colorDraft']) ? $validated['colorDraft'] : null,
|
||||
]);
|
||||
|
||||
$this->reset('colorEditingFolderId', 'colorDraft');
|
||||
$this->modal('folder-color')->close();
|
||||
}
|
||||
|
||||
public function moveTodoToFolder(int $todoId, int $folderId): void
|
||||
{
|
||||
$todo = Todo::query()->forUser(auth()->id())->findOrFail($todoId);
|
||||
|
||||
$folder = Folder::query()->forUser(auth()->id())->findOrFail($folderId);
|
||||
|
||||
$todo->update(['folder_id' => $folder->id]);
|
||||
}
|
||||
|
||||
public function todosForFolder(int $folderId): Collection
|
||||
{
|
||||
return Todo::query()
|
||||
->forUser(auth()->id())
|
||||
->where('folder_id', $folderId)
|
||||
->active()
|
||||
->priority()
|
||||
->get();
|
||||
}
|
||||
|
||||
public function startTodoCreate(int $folderId): void
|
||||
{
|
||||
$this->folderForUser($folderId);
|
||||
@@ -158,6 +232,7 @@ new #[Title('Folders')] class extends Component
|
||||
'status' => TodoStatus::from($validated['todoStatus']),
|
||||
'due_date' => filled($validated['todoDueDate']) ? Carbon::parse($validated['todoDueDate']) : null,
|
||||
'notes' => filled($validated['todoNotes']) ? $validated['todoNotes'] : null,
|
||||
'position' => Todo::nextPositionFor(auth()->user()),
|
||||
]);
|
||||
|
||||
$this->reset('showTodoForm', 'todoFolderId', 'todoDescription', 'todoStatus', 'todoDueDate', 'todoNotes');
|
||||
@@ -201,6 +276,14 @@ new #[Title('Folders')] class extends Component
|
||||
->countBy();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, mixed>
|
||||
*/
|
||||
private function folderColorRules(): array
|
||||
{
|
||||
return ['nullable', 'string', 'max:20', Rule::in([...Folder::COLORS, ''])];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, mixed>
|
||||
*/
|
||||
@@ -250,6 +333,12 @@ new #[Title('Folders')] class extends Component
|
||||
<flux:error name="newFolderName" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<flux:label>{{ __('Color') }}</flux:label>
|
||||
<x-color-picker model="newFolderColor" />
|
||||
<flux:error name="newFolderColor" />
|
||||
</div>
|
||||
|
||||
<flux:button variant="primary" type="submit" icon="plus" data-test="add-folder-button">
|
||||
{{ __('Add folder') }}
|
||||
</flux:button>
|
||||
@@ -259,7 +348,15 @@ new #[Title('Folders')] class extends Component
|
||||
<div class="flex flex-col divide-y divide-zinc-200 rounded-xl border border-zinc-200 bg-white dark:divide-zinc-700 dark:border-zinc-700 dark:bg-zinc-900" data-test="folder-list">
|
||||
@forelse ($this->folderTree as $node)
|
||||
<div class="p-4" :style="'margin-left: {{ $node['depth'] * 1.5 }}rem'">
|
||||
<div class="flex flex-wrap items-center gap-3" data-test="folder-row-{{ $node['folder']->id }}">
|
||||
<div
|
||||
x-data="{ drop: false }"
|
||||
class="flex flex-wrap items-center gap-3 transition-colors"
|
||||
:class="drop && 'rounded-lg bg-blue-50 ring-2 ring-inset ring-blue-400 dark:bg-blue-500/10'"
|
||||
@dragover.prevent="drop = true"
|
||||
@dragleave="!$el.contains($event.relatedTarget) && (drop = false)"
|
||||
@drop.prevent="drop = false; if (window.__mtTodoDrag && window.__mtTodoDrag.folderId !== {{ $node['folder']->id }}) $wire.moveTodoToFolder(window.__mtTodoDrag.todoId, {{ $node['folder']->id }}); window.__mtTodoDrag = null"
|
||||
data-test="folder-row-{{ $node['folder']->id }}"
|
||||
>
|
||||
@if ($renamingFolderId === $node['folder']->id)
|
||||
<form wire:submit="saveRename" class="flex flex-1 flex-wrap items-center gap-3">
|
||||
<flux:input
|
||||
@@ -280,17 +377,39 @@ new #[Title('Folders')] class extends Component
|
||||
<flux:error name="renameName" />
|
||||
</form>
|
||||
@else
|
||||
<flux:heading size="sm" class="truncate" data-test="folder-name-{{ $node['folder']->id }}">
|
||||
{{ $node['folder']->name }}
|
||||
</flux:heading>
|
||||
<div class="flex min-w-0 items-center gap-2">
|
||||
<x-folder-dot :color="$node['folder']->color" data-test="folder-dot-{{ $node['folder']->id }}" />
|
||||
<flux:heading size="sm" class="truncate" data-test="folder-name-{{ $node['folder']->id }}">
|
||||
{{ $node['folder']->name }}
|
||||
</flux:heading>
|
||||
</div>
|
||||
|
||||
<flux:badge size="sm" color="blue">
|
||||
<flux:badge
|
||||
size="sm"
|
||||
color="blue"
|
||||
class="cursor-pointer select-none"
|
||||
wire:click="toggleExpandFolder({{ $node['folder']->id }})"
|
||||
data-test="expand-folder-{{ $node['folder']->id }}"
|
||||
>
|
||||
<flux:icon.chevron-down
|
||||
variant="micro"
|
||||
:class="'me-0.5' . ($expandedFolderId === $node['folder']->id ? ' rotate-180 transition-transform' : ' transition-transform')"
|
||||
/>
|
||||
{{ $this->openCounts->get($node['folder']->id, 0) }} {{ __('open') }}
|
||||
</flux:badge>
|
||||
|
||||
<flux:spacer />
|
||||
|
||||
<div class="flex items-center gap-1">
|
||||
<flux:tooltip :content="__('Choose color')">
|
||||
<flux:button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
icon="swatch"
|
||||
wire:click="startColorEdit({{ $node['folder']->id }})"
|
||||
data-test="color-folder-{{ $node['folder']->id }}"
|
||||
/>
|
||||
</flux:tooltip>
|
||||
<flux:tooltip :content="__('View todos')">
|
||||
<flux:button
|
||||
size="sm"
|
||||
@@ -341,6 +460,36 @@ new #[Title('Folders')] class extends Component
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@if ($expandedFolderId === $node['folder']->id)
|
||||
<div class="mt-3 flex flex-col gap-2 rounded-lg border border-zinc-200 bg-zinc-50 p-3 dark:border-zinc-700 dark:bg-zinc-800/50" data-test="folder-todos-{{ $node['folder']->id }}">
|
||||
<flux:text size="sm" class="text-zinc-500">{{ __('Drag a todo onto any folder row to move it.') }}</flux:text>
|
||||
|
||||
@forelse ($this->todosForFolder($node['folder']->id) as $todo)
|
||||
<div
|
||||
x-data="{ dragging: false }"
|
||||
draggable="true"
|
||||
class="flex cursor-grab select-none flex-wrap items-center gap-3"
|
||||
:class="dragging && 'opacity-40'"
|
||||
@dragstart="dragging = true; window.__mtTodoDrag = { todoId: {{ $todo->id }}, folderId: {{ $node['folder']->id }} }"
|
||||
@dragend="dragging = false; window.__mtTodoDrag = null"
|
||||
data-test="folder-todo-row-{{ $todo->id }}"
|
||||
>
|
||||
<flux:icon.chevrons-up-down variant="micro" class="text-zinc-400 dark:text-zinc-500" />
|
||||
|
||||
<flux:heading size="sm" class="min-w-0 flex-1 truncate" data-test="folder-todo-description-{{ $todo->id }}">
|
||||
{{ $todo->description }}
|
||||
</flux:heading>
|
||||
|
||||
<flux:badge size="sm" :color="$todo->status->badgeColor()">
|
||||
{{ $todo->status->label() }}
|
||||
</flux:badge>
|
||||
</div>
|
||||
@empty
|
||||
<flux:text class="text-sm text-zinc-500">{{ __('No open todos in this folder.') }}</flux:text>
|
||||
@endforelse
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if ($creatingChildOf === $node['folder']->id)
|
||||
<form wire:submit="createChildFolder" class="mt-3 flex flex-wrap items-end gap-3">
|
||||
<div class="min-w-64 flex-1">
|
||||
@@ -353,6 +502,11 @@ new #[Title('Folders')] class extends Component
|
||||
/>
|
||||
<flux:error name="newChildName" />
|
||||
</div>
|
||||
<div>
|
||||
<flux:label size="sm">{{ __('Color') }}</flux:label>
|
||||
<x-color-picker model="newChildColor" />
|
||||
<flux:error name="newChildColor" />
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<flux:button size="sm" variant="primary" type="submit" icon="plus" data-test="add-child-button">
|
||||
{{ __('Add') }}
|
||||
@@ -444,6 +598,30 @@ new #[Title('Folders')] class extends Component
|
||||
</form>
|
||||
</flux:modal>
|
||||
|
||||
<flux:modal name="folder-color" class="md:w-lg">
|
||||
<form wire:submit="saveFolderColor" class="space-y-6">
|
||||
<div>
|
||||
<flux:heading size="lg">{{ __('Folder color') }}</flux:heading>
|
||||
<flux:text class="mt-2">{{ __('Choose a color for this folder, or clear it to remove any color.') }}</flux:text>
|
||||
</div>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>{{ __('Color') }}</flux:label>
|
||||
<x-color-picker model="colorDraft" />
|
||||
<flux:error name="colorDraft" />
|
||||
</flux:field>
|
||||
|
||||
<div class="flex justify-end gap-3">
|
||||
<flux:modal.close>
|
||||
<flux:button variant="ghost">{{ __('Cancel') }}</flux:button>
|
||||
</flux:modal.close>
|
||||
<flux:button type="submit" variant="primary" data-test="save-folder-color">
|
||||
{{ __('Save color') }}
|
||||
</flux:button>
|
||||
</div>
|
||||
</form>
|
||||
</flux:modal>
|
||||
|
||||
<flux:modal name="confirm-folder-delete" class="md:w-lg">
|
||||
<div class="space-y-6">
|
||||
<div>
|
||||
|
||||
@@ -0,0 +1,644 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Folder;
|
||||
use App\Models\Todo;
|
||||
use App\TodoStatus;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Attributes\Title;
|
||||
use Livewire\Component;
|
||||
|
||||
new #[Title('Todos')] class extends Component
|
||||
{
|
||||
private const PER_PAGE = 50;
|
||||
|
||||
#[Locked]
|
||||
public ?int $editingTodoId = null;
|
||||
|
||||
public string $search = '';
|
||||
|
||||
public ?int $folderId = null;
|
||||
|
||||
public string $status = 'all';
|
||||
|
||||
public bool $showTodoForm = false;
|
||||
|
||||
public string $description = '';
|
||||
|
||||
public string $todoStatus = 'open';
|
||||
|
||||
public ?string $dueDate = null;
|
||||
|
||||
public string $notes = '';
|
||||
|
||||
public ?int $formFolderId = null;
|
||||
|
||||
#[Locked]
|
||||
public ?int $confirmingTodoDelete = null;
|
||||
|
||||
public int $limit = self::PER_PAGE;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$folderId = request()->query('folder');
|
||||
|
||||
if ($folderId === null || $folderId === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$folderId = (int) $folderId;
|
||||
|
||||
if (Folder::query()->forUser(auth()->id())->whereKey($folderId)->exists()) {
|
||||
$this->folderId = $folderId;
|
||||
}
|
||||
}
|
||||
|
||||
public function updatedSearch(): void
|
||||
{
|
||||
$this->limit = self::PER_PAGE;
|
||||
}
|
||||
|
||||
public function updatedFolderId(): void
|
||||
{
|
||||
$this->folderId = $this->folderId === null || $this->folderId === '' ? null : (int) $this->folderId;
|
||||
|
||||
$this->limit = self::PER_PAGE;
|
||||
}
|
||||
|
||||
public function updatedStatus(): void
|
||||
{
|
||||
$this->limit = self::PER_PAGE;
|
||||
}
|
||||
|
||||
public function openCreateForm(?int $folderId = null): void
|
||||
{
|
||||
$this->reset('editingTodoId', 'description', 'todoStatus', 'dueDate', 'notes', 'formFolderId');
|
||||
$this->resetErrorBag();
|
||||
|
||||
if ($folderId !== null && $this->folderTree->contains(fn ($node) => $node['folder']->id === $folderId)) {
|
||||
$this->formFolderId = $folderId;
|
||||
} elseif ($this->folderId !== null) {
|
||||
$this->formFolderId = $this->folderId;
|
||||
}
|
||||
|
||||
$this->showTodoForm = true;
|
||||
}
|
||||
|
||||
public function openEditForm(int $todoId): void
|
||||
{
|
||||
$todo = $this->todoForUser($todoId);
|
||||
|
||||
$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;
|
||||
|
||||
$this->resetErrorBag();
|
||||
$this->showTodoForm = true;
|
||||
}
|
||||
|
||||
public function saveTodo(): void
|
||||
{
|
||||
$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())],
|
||||
]);
|
||||
|
||||
$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,
|
||||
];
|
||||
|
||||
if ($this->editingTodoId !== null) {
|
||||
$this->todoForUser($this->editingTodoId)->update($data);
|
||||
} else {
|
||||
Todo::create($data + [
|
||||
'user_id' => auth()->id(),
|
||||
'position' => Todo::nextPositionFor(auth()->user()),
|
||||
]);
|
||||
}
|
||||
|
||||
$this->reset('showTodoForm', 'editingTodoId', 'description', 'todoStatus', 'dueDate', 'notes', 'formFolderId');
|
||||
}
|
||||
|
||||
public function toggleComplete(int $todoId): void
|
||||
{
|
||||
$todo = $this->todoForUser($todoId);
|
||||
|
||||
$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
|
||||
{
|
||||
$this->todoForUser($todoId);
|
||||
|
||||
$this->confirmingTodoDelete = $todoId;
|
||||
$this->modal('confirm-todo-delete')->show();
|
||||
}
|
||||
|
||||
public function deleteTodo(): void
|
||||
{
|
||||
$this->todoForUser($this->confirmingTodoDelete)->delete();
|
||||
|
||||
$this->confirmingTodoDelete = null;
|
||||
$this->modal('confirm-todo-delete')->close();
|
||||
}
|
||||
|
||||
public function resetFilters(): void
|
||||
{
|
||||
$this->reset('search', 'folderId', 'status');
|
||||
$this->limit = self::PER_PAGE;
|
||||
}
|
||||
|
||||
public function loadMore(): void
|
||||
{
|
||||
$this->limit = min(
|
||||
(int) $this->filteredTodoQuery()->count(),
|
||||
$this->limit + self::PER_PAGE
|
||||
);
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function folderTree(): Collection
|
||||
{
|
||||
return Folder::treeForUser(auth()->id());
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function filterFolderScope(): array
|
||||
{
|
||||
if ($this->folderId === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->descendantIds($this->folderId);
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function hasActiveFilters(): bool
|
||||
{
|
||||
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 totalCount(): int
|
||||
{
|
||||
return (int) $this->filteredTodoQuery()->count();
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function hasMore(): bool
|
||||
{
|
||||
return $this->todos->count() < $this->totalCount;
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function orderedTodoIds(): array
|
||||
{
|
||||
return $this->filteredTodoQuery()->priority()->pluck('id')->all();
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function todos(): Collection
|
||||
{
|
||||
return $this->filteredTodoQuery()
|
||||
->with('folder.parent')
|
||||
->priority()
|
||||
->limit($this->limit)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function moveTodo(int $todoId, string $direction): void
|
||||
{
|
||||
$this->todoForUser($todoId);
|
||||
|
||||
$ids = $this->orderedTodoIds;
|
||||
$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->orderedTodoIds;
|
||||
$currentIndex = array_search($todoId, $ids, true);
|
||||
|
||||
if ($currentIndex === false || $ids === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->reorderTodo($todoId, $ids, $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())
|
||||
->when(
|
||||
$this->search !== '',
|
||||
fn (Builder $query) => $query->where('description', 'like', '%'.$this->search.'%')
|
||||
)
|
||||
->when(
|
||||
$this->folderId !== null,
|
||||
fn (Builder $query) => $query->whereIn('folder_id', $this->filterFolderScope)
|
||||
)
|
||||
->when($this->status, function (Builder $query) {
|
||||
return match ($this->status) {
|
||||
'open' => $query->active(),
|
||||
'completed' => $query->completed(),
|
||||
'overdue' => $query->overdue(),
|
||||
'all', '' => $query,
|
||||
default => $query->where('status', $this->status)->incomplete(),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private function descendantIds(int $folderId): array
|
||||
{
|
||||
$ids = [$folderId];
|
||||
|
||||
foreach ($this->folderTree->where('folder.parent_id', $folderId)->values() as $child) {
|
||||
$ids = [...$ids, ...$this->descendantIds($child['folder']->id)];
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
private function todoForUser(int $todoId): Todo
|
||||
{
|
||||
return Todo::query()->forUser(auth()->id())->findOrFail($todoId);
|
||||
}
|
||||
}; ?>
|
||||
|
||||
<div class="flex h-full w-full flex-1 flex-col gap-6">
|
||||
<div class="flex flex-wrap items-center justify-between gap-4">
|
||||
<div>
|
||||
<flux:heading size="xl">{{ __('Todos') }}</flux:heading>
|
||||
<flux:text class="mt-1">Browse and reorder every todo.</flux:text>
|
||||
</div>
|
||||
|
||||
<flux:button
|
||||
variant="primary"
|
||||
wire:click="openCreateForm"
|
||||
data-test="add-todo-button"
|
||||
>
|
||||
{{ __('New Todo') }}
|
||||
</flux:button>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
@foreach ($this->statusFilters as $value => $label)
|
||||
<flux:button
|
||||
size="sm"
|
||||
:variant="$status === $value ? 'primary' : 'ghost'"
|
||||
wire:click="$set('status', '{{ $value }}')"
|
||||
:data-test="'status-' . $value"
|
||||
>
|
||||
{{ __($label) }}
|
||||
</flux:button>
|
||||
@endforeach
|
||||
|
||||
<flux:spacer />
|
||||
|
||||
<flux:input
|
||||
size="sm"
|
||||
type="search"
|
||||
icon="magnifying-glass"
|
||||
wire:model.live.debounce.300ms="search"
|
||||
placeholder="{{ __('Search todos…') }}"
|
||||
class="w-full sm:w-64"
|
||||
data-test="search-input"
|
||||
/>
|
||||
|
||||
<flux:select size="sm" wire:model.live="folderId" class="w-full sm:w-56" data-test="folder-filter">
|
||||
<flux:select.option value="">{{ __('All folders') }}</flux:select.option>
|
||||
@foreach ($this->folderTree as $node)
|
||||
<flux:select.option :value="$node['folder']->id">{{ str_repeat('— ', $node['depth']) }}{{ $node['folder']->name }}</flux:select.option>
|
||||
@endforeach
|
||||
</flux:select>
|
||||
|
||||
@if ($this->hasActiveFilters)
|
||||
<flux:button size="sm" variant="danger" icon="x-mark" wire:click="resetFilters" class="shrink-0">
|
||||
{{ __('Clear') }}
|
||||
</flux:button>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<flux:card>
|
||||
<flux:table>
|
||||
<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 align="end" width="10rem">{{ __('Actions') }}</flux:table.column>
|
||||
</flux:table.columns>
|
||||
|
||||
<flux:table.rows wire:sort="handleSort">
|
||||
@forelse ($this->todos as $todo)
|
||||
<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"
|
||||
:title="$todo->completed_at ? __('Mark as not done') : __('Mark as done')"
|
||||
wire:click="toggleComplete({{ $todo->id }})"
|
||||
data-test="toggle-complete-{{ $todo->id }}"
|
||||
/>
|
||||
</flux:table.cell>
|
||||
|
||||
<flux:table.cell :variant="$todo->completed_at ? 'strong' : 'default'" data-test="todo-description-{{ $todo->id }}">
|
||||
<span @class(['line-through text-zinc-400' => $todo->completed_at !== null])>{{ $todo->description }}</span>
|
||||
@if ($todo->notes)
|
||||
<flux:text size="sm" class="mt-1 block max-w-md truncate text-zinc-500">{{ $todo->notes }}</flux:text>
|
||||
@endif
|
||||
</flux:table.cell>
|
||||
|
||||
<flux:table.cell>
|
||||
<flux:badge size="sm" :color="$todo->status->badgeColor()" data-test="todo-status-{{ $todo->id }}">
|
||||
{{ $todo->status->label() }}
|
||||
</flux:badge>
|
||||
</flux:table.cell>
|
||||
|
||||
<flux:table.cell class="text-zinc-500">
|
||||
<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>
|
||||
@if ($todo->completed_at)
|
||||
<flux:badge size="sm" color="zinc">{{ $todo->due_date?->format('M j, Y') ?? __('—') }}</flux:badge>
|
||||
@elseif ($todo->due_date?->isPast())
|
||||
<flux:badge size="sm" color="red">{{ $todo->due_date->format('M j, Y') }}</flux:badge>
|
||||
@elseif ($todo->due_date?->isToday())
|
||||
<flux:badge size="sm" color="amber">{{ __('Today') }} · {{ $todo->due_date->format('M j') }}</flux:badge>
|
||||
@else
|
||||
<flux:text>{{ $todo->due_date?->format('M j, Y') ?? __('No due date') }}</flux:text>
|
||||
@endif
|
||||
</flux:table.cell>
|
||||
|
||||
<flux:table.cell class="text-zinc-500" data-test="todo-created-{{ $todo->id }}">
|
||||
{{ $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"
|
||||
icon="pencil-square"
|
||||
:title="__('Edit todo')"
|
||||
wire:click="openEditForm({{ $todo->id }})"
|
||||
data-test="edit-todo-{{ $todo->id }}"
|
||||
/>
|
||||
<flux:button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
icon="trash"
|
||||
:title="__('Delete todo')"
|
||||
wire:click="confirmTodoDelete({{ $todo->id }})"
|
||||
data-test="delete-todo-{{ $todo->id }}"
|
||||
/>
|
||||
</div>
|
||||
</flux:table.cell>
|
||||
</flux:table.row>
|
||||
@empty
|
||||
<flux:table.row>
|
||||
<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>
|
||||
@endforelse
|
||||
</flux:table.rows>
|
||||
</flux:table>
|
||||
</flux:card>
|
||||
|
||||
<div class="flex flex-col items-center gap-3">
|
||||
<div class="text-sm text-zinc-500" data-test="todo-count">
|
||||
{{ trans_choice('Showing :count of :total todos', $this->todos->count(), [
|
||||
'count' => $this->todos->count(),
|
||||
'total' => $this->totalCount,
|
||||
]) }}
|
||||
</div>
|
||||
|
||||
@if ($this->hasMore)
|
||||
<div
|
||||
x-data
|
||||
x-init="$nextTick(() => {
|
||||
const el = $refs.loadMore;
|
||||
if (! el) return;
|
||||
|
||||
const observer = new IntersectionObserver(([entry]) => {
|
||||
if (entry.isIntersecting && ! window.__mtLoadMore) {
|
||||
window.__mtLoadMore = true;
|
||||
$wire.loadMore().finally(() => { window.__mtLoadMore = false; });
|
||||
}
|
||||
}, { rootMargin: '200px' });
|
||||
|
||||
observer.observe(el);
|
||||
})"
|
||||
class="flex items-center justify-center gap-2 py-4 text-sm text-zinc-500"
|
||||
data-test="load-more"
|
||||
>
|
||||
<div x-ref="loadMore" class="flex items-center gap-2">
|
||||
<flux:icon.loading class="size-4 animate-spin" />
|
||||
<span>{{ __('Loading more…') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<flux:modal wire:model.self="showTodoForm" class="md:w-xl">
|
||||
<form wire:submit="saveTodo" class="space-y-6">
|
||||
<div>
|
||||
<flux:heading size="lg">{{ $editingTodoId === null ? __('New todo') : __('Edit todo') }}</flux:heading>
|
||||
<flux:text class="mt-2">{{ __('Add a task with a description and folder. A due date is optional.') }}</flux:text>
|
||||
</div>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>{{ __('Description') }}</flux:label>
|
||||
<flux:input
|
||||
wire:model="description"
|
||||
type="text"
|
||||
autofocus
|
||||
placeholder="{{ __('What needs to be done?') }}"
|
||||
data-test="description-input"
|
||||
/>
|
||||
<flux:error name="description" />
|
||||
</flux:field>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>{{ __('Status') }}</flux:label>
|
||||
<flux:select wire:model="todoStatus" data-test="status-select">
|
||||
@foreach (TodoStatus::cases() as $status)
|
||||
<flux:select.option :value="$status->value">{{ $status->label() }}</flux:select.option>
|
||||
@endforeach
|
||||
</flux:select>
|
||||
<flux:error name="todoStatus" />
|
||||
</flux:field>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>{{ __('Due date') }}</flux:label>
|
||||
<flux:input wire:model="dueDate" type="date" data-test="due-date-input" />
|
||||
<flux:error name="dueDate" />
|
||||
</flux:field>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>{{ __('Notes') }}</flux:label>
|
||||
<flux:textarea
|
||||
wire:model="notes"
|
||||
rows="3"
|
||||
placeholder="{{ __('Add any extra details…') }}"
|
||||
data-test="notes-input"
|
||||
/>
|
||||
<flux:error name="notes" />
|
||||
</flux:field>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>{{ __('Folder') }}</flux:label>
|
||||
<flux:select wire:model="formFolderId" data-test="folder-select">
|
||||
<flux:select.option value="">{{ __('Select a folder…') }}</flux:select.option>
|
||||
@foreach ($this->folderTree as $node)
|
||||
<flux:select.option :value="$node['folder']->id">{{ str_repeat('— ', $node['depth']) }}{{ $node['folder']->name }}</flux:select.option>
|
||||
@endforeach
|
||||
</flux:select>
|
||||
<flux:error name="formFolderId" />
|
||||
</flux:field>
|
||||
|
||||
<div class="flex justify-end gap-3">
|
||||
<flux:modal.close>
|
||||
<flux:button variant="ghost">{{ __('Cancel') }}</flux:button>
|
||||
</flux:modal.close>
|
||||
<flux:button type="submit" variant="primary">{{ __('Save todo') }}</flux:button>
|
||||
</div>
|
||||
</form>
|
||||
</flux:modal>
|
||||
|
||||
<flux:modal name="confirm-todo-delete" class="md:w-lg">
|
||||
<div class="space-y-6">
|
||||
<div>
|
||||
<flux:heading size="lg">{{ __('Delete todo?') }}</flux:heading>
|
||||
<flux:text class="mt-2">{{ __('This todo will be permanently deleted. This action cannot be undone.') }}</flux:text>
|
||||
</div>
|
||||
<div class="flex justify-end gap-3">
|
||||
<flux:modal.close>
|
||||
<flux:button variant="ghost">{{ __('Cancel') }}</flux:button>
|
||||
</flux:modal.close>
|
||||
<flux:button variant="danger" wire:click="deleteTodo">{{ __('Delete') }}</flux:button>
|
||||
</div>
|
||||
</div>
|
||||
</flux:modal>
|
||||
</div>
|
||||
Reference in New Issue
Block a user