updated folder colors, reordering, new todo page, updated sidebar
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-09-21 00:33:10 -07:00
parent df016dad14
commit f8fc561602
25 changed files with 1980 additions and 264 deletions
+189 -11
View File
@@ -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>