first commit;
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-09-17 23:01:26 -07:00
commit 1e8ae3d1e5
137 changed files with 24339 additions and 0 deletions
+410
View File
@@ -0,0 +1,410 @@
<?php
use App\Models\Folder;
use App\Models\Todo;
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('Folders')] class extends Component
{
public string $newFolderName = '';
#[Locked]
public ?int $creatingChildOf = null;
public string $newChildName = '';
#[Locked]
public ?int $renamingFolderId = null;
public string $renameName = '';
#[Locked]
public ?int $confirmingFolderDelete = null;
public bool $showTodoForm = false;
#[Locked]
public ?int $todoFolderId = null;
public string $todoDescription = '';
public ?string $todoDueDate = null;
public string $todoNotes = '';
public function createTopLevelFolder(): void
{
$validated = $this->validate([
'newFolderName' => $this->folderNameRules(parentId: null),
]);
Folder::create([
'user_id' => auth()->id(),
'name' => $validated['newFolderName'],
'parent_id' => null,
]);
$this->reset('newFolderName');
}
public function startChildCreate(int $folderId): void
{
$this->folderForUser($folderId);
$this->creatingChildOf = $folderId;
$this->reset('newChildName');
$this->resetErrorBag('newChildName');
}
public function cancelChildCreate(): void
{
$this->reset('creatingChildOf', 'newChildName');
}
public function createChildFolder(): void
{
$this->folderForUser($this->creatingChildOf);
$validated = $this->validate([
'newChildName' => $this->folderNameRules(parentId: $this->creatingChildOf),
]);
Folder::create([
'user_id' => auth()->id(),
'name' => $validated['newChildName'],
'parent_id' => $this->creatingChildOf,
]);
$this->reset('creatingChildOf', 'newChildName');
}
public function startRename(int $folderId): void
{
$folder = $this->folderForUser($folderId);
$this->renamingFolderId = $folder->id;
$this->renameName = $folder->name;
$this->resetErrorBag('renameName');
}
public function cancelRename(): void
{
$this->reset('renamingFolderId', 'renameName');
}
public function saveRename(): void
{
$folder = $this->folderForUser($this->renamingFolderId);
$validated = $this->validate([
'renameName' => $this->folderNameRules(parentId: $folder->parent_id, ignoreId: $folder->id),
]);
$folder->update(['name' => $validated['renameName']]);
$this->reset('renamingFolderId', 'renameName');
}
public function confirmFolderDelete(int $folderId): void
{
$this->folderForUser($folderId);
$this->confirmingFolderDelete = $folderId;
$this->modal('confirm-folder-delete')->show();
}
public function deleteFolder(): void
{
$this->folderForUser($this->confirmingFolderDelete)->delete();
$this->confirmingFolderDelete = null;
$this->modal('confirm-folder-delete')->close();
}
public function startTodoCreate(int $folderId): void
{
$this->folderForUser($folderId);
$this->todoFolderId = $folderId;
$this->reset('todoDescription', 'todoDueDate', 'todoNotes');
$this->resetErrorBag('todoDescription', 'todoDueDate', 'todoNotes');
$this->showTodoForm = true;
}
public function saveFolderTodo(): void
{
$folder = $this->folderForUser($this->todoFolderId ?? 0);
$validated = $this->validate([
'todoDescription' => ['required', 'string', 'max:255'],
'todoDueDate' => ['nullable', 'date'],
'todoNotes' => ['nullable', 'string', 'max:'.auth()->user()->notesLimit()],
]);
Todo::create([
'user_id' => auth()->id(),
'folder_id' => $folder->id,
'description' => $validated['todoDescription'],
'due_date' => filled($validated['todoDueDate']) ? Carbon::parse($validated['todoDueDate']) : null,
'notes' => filled($validated['todoNotes']) ? $validated['todoNotes'] : null,
]);
$this->reset('showTodoForm', 'todoFolderId', 'todoDescription', 'todoDueDate', 'todoNotes');
}
#[Computed]
public function folderTree(): Collection
{
return Folder::treeForUser(auth()->id());
}
#[Computed]
public function openCounts(): Collection
{
return Todo::query()
->forUser(auth()->id())
->incomplete()
->pluck('folder_id')
->countBy();
}
/**
* @return array<int, mixed>
*/
private function folderNameRules(?int $parentId = null, ?int $ignoreId = null): array
{
return [
'required',
'string',
'max:255',
Rule::unique('folders', 'name')
->ignore($ignoreId)
->where(fn ($query) => $query
->where('user_id', auth()->id())
->where('parent_id', $parentId)),
];
}
private function folderForUser(int $folderId): Folder
{
return Folder::query()->forUser(auth()->id())->findOrFail($folderId);
}
}; ?>
<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">{{ __('Folders') }}</flux:heading>
<flux:text class="mt-1">{{ __('Organize your todos into a top-level and nested folder hierarchy.') }}</flux:text>
</div>
</div>
@if ($this->folderTree->isEmpty())
<flux:callout variant="warning" icon="folder">
{{ __('No folders yet. Create your first top-level folder below.') }}
</flux:callout>
@endif
<flux:card>
<form wire:submit="createTopLevelFolder" class="flex flex-wrap items-end gap-3">
<div class="min-w-64 flex-1">
<flux:label>{{ __('New top-level folder') }}</flux:label>
<flux:input
wire:model="newFolderName"
placeholder="{{ __('e.g. Work, Business, Personal') }}"
data-test="new-folder-input"
/>
<flux:error name="newFolderName" />
</div>
<flux:button variant="primary" type="submit" icon="plus" data-test="add-folder-button">
{{ __('Add folder') }}
</flux:button>
</form>
</flux:card>
<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 }}">
@if ($renamingFolderId === $node['folder']->id)
<form wire:submit="saveRename" class="flex flex-1 flex-wrap items-center gap-3">
<flux:input
wire:model="renameName"
size="sm"
class="min-w-48 flex-1"
autofocus
data-test="rename-input"
/>
<div class="flex gap-2">
<flux:button size="sm" type="submit" variant="primary" icon="check" data-test="save-rename-button">
{{ __('Save') }}
</flux:button>
<flux:button size="sm" variant="ghost" wire:click="cancelRename">
{{ __('Cancel') }}
</flux:button>
</div>
<flux:error name="renameName" />
</form>
@else
<flux:heading size="sm" class="truncate" data-test="folder-name-{{ $node['folder']->id }}">
{{ $node['folder']->name }}
</flux:heading>
<flux:badge size="sm" color="blue">
{{ $this->openCounts->get($node['folder']->id, 0) }} {{ __('open') }}
</flux:badge>
<flux:spacer />
<div class="flex items-center gap-1">
<flux:tooltip :content="__('View todos')">
<flux:button
size="sm"
variant="ghost"
icon="magnifying-glass"
:href="route('dashboard', ['folder' => $node['folder']->id])"
wire:navigate
data-test="view-todos-{{ $node['folder']->id }}"
/>
</flux:tooltip>
<flux:tooltip :content="__('Add todo')">
<flux:button
size="sm"
variant="ghost"
icon="document-plus"
wire:click="startTodoCreate({{ $node['folder']->id }})"
data-test="add-todo-{{ $node['folder']->id }}"
/>
</flux:tooltip>
<flux:tooltip :content="__('Add sub-folder')">
<flux:button
size="sm"
variant="ghost"
icon="folder-plus"
wire:click="startChildCreate({{ $node['folder']->id }})"
data-test="add-child-{{ $node['folder']->id }}"
/>
</flux:tooltip>
<flux:tooltip :content="__('Rename')">
<flux:button
size="sm"
variant="ghost"
icon="pencil-square"
wire:click="startRename({{ $node['folder']->id }})"
data-test="rename-folder-{{ $node['folder']->id }}"
/>
</flux:tooltip>
<flux:tooltip :content="__('Delete')">
<flux:button
size="sm"
variant="ghost"
icon="trash"
wire:click="confirmFolderDelete({{ $node['folder']->id }})"
data-test="delete-folder-{{ $node['folder']->id }}"
/>
</flux:tooltip>
</div>
@endif
</div>
@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">
<flux:label size="sm">{{ __('Sub-folder of') }} {{ $node['folder']->name }}</flux:label>
<flux:input
wire:model="newChildName"
size="sm"
placeholder="{{ __('Sub-folder name') }}"
data-test="new-child-input"
/>
<flux:error name="newChildName" />
</div>
<div class="flex gap-2">
<flux:button size="sm" variant="primary" type="submit" icon="plus" data-test="add-child-button">
{{ __('Add') }}
</flux:button>
<flux:button size="sm" variant="ghost" wire:click="cancelChildCreate">
{{ __('Cancel') }}
</flux:button>
</div>
</form>
@endif
</div>
@empty
<div class="p-8">
<flux:text align="center" class="text-sm text-zinc-500">{{ __('No folders to display.') }}</flux:text>
</div>
@endforelse
</div>
<flux:modal wire:model.self="showTodoForm" class="md:w-xl">
<form wire:submit="saveFolderTodo" class="space-y-6">
<div>
<flux:heading size="lg">{{ __('Add todo') }}</flux:heading>
<flux:text class="mt-2">{{ __('Add a task with a description. A due date is optional.') }}</flux:text>
</div>
<flux:field>
<flux:label>{{ __('Description') }}</flux:label>
<flux:input
wire:model="todoDescription"
type="text"
autofocus
placeholder="{{ __('What needs to be done?') }}"
data-test="todo-description-input"
/>
<flux:error name="todoDescription" />
</flux:field>
<flux:field>
<flux:label>{{ __('Due date') }}</flux:label>
<flux:input wire:model="todoDueDate" type="date" data-test="todo-due-date-input" />
<flux:error name="todoDueDate" />
</flux:field>
<flux:field>
<flux:label>{{ __('Notes') }}</flux:label>
<flux:textarea
wire:model="todoNotes"
rows="3"
placeholder="{{ __('Add any extra details…') }}"
data-test="todo-notes-input"
/>
<flux:error name="todoNotes" />
</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">{{ __('Add todo') }}</flux:button>
</div>
</form>
</flux:modal>
<flux:modal name="confirm-folder-delete" class="md:w-lg">
<div class="space-y-6">
<div>
<flux:heading size="lg">{{ __('Delete folder?') }}</flux:heading>
<flux:text class="mt-2">
{{ __('Deleting a folder also deletes its sub-folders and every todo inside them. 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="deleteFolder" data-test="confirm-delete-folder">
{{ __('Delete folder') }}
</flux:button>
</div>
</div>
</flux:modal>
</div>