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:
@@ -16,17 +16,23 @@ use Illuminate\Support\Collection;
|
|||||||
* @property int $id
|
* @property int $id
|
||||||
* @property int $user_id
|
* @property int $user_id
|
||||||
* @property string $name
|
* @property string $name
|
||||||
|
* @property string|null $color
|
||||||
* @property int|null $parent_id
|
* @property int|null $parent_id
|
||||||
* @property Folder|null $parent
|
* @property Folder|null $parent
|
||||||
* @property Carbon|null $created_at
|
* @property Carbon|null $created_at
|
||||||
* @property Carbon|null $updated_at
|
* @property Carbon|null $updated_at
|
||||||
*/
|
*/
|
||||||
#[Fillable(['user_id', 'name', 'parent_id'])]
|
#[Fillable(['user_id', 'name', 'parent_id', 'color'])]
|
||||||
class Folder extends Model
|
class Folder extends Model
|
||||||
{
|
{
|
||||||
/** @use HasFactory<FolderFactory> */
|
/** @use HasFactory<FolderFactory> */
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
|
public const COLORS = [
|
||||||
|
'zinc', 'red', 'orange', 'amber', 'green', 'emerald',
|
||||||
|
'sky', 'blue', 'indigo', 'violet', 'fuchsia', 'pink',
|
||||||
|
];
|
||||||
|
|
||||||
/** @return BelongsTo<User, $this> */
|
/** @return BelongsTo<User, $this> */
|
||||||
public function user(): BelongsTo
|
public function user(): BelongsTo
|
||||||
{
|
{
|
||||||
|
|||||||
+32
-1
@@ -18,13 +18,14 @@ use Illuminate\Support\Carbon;
|
|||||||
* @property string $description
|
* @property string $description
|
||||||
* @property string|null $notes
|
* @property string|null $notes
|
||||||
* @property TodoStatus $status
|
* @property TodoStatus $status
|
||||||
|
* @property int|null $position
|
||||||
* @property Carbon|null $due_date
|
* @property Carbon|null $due_date
|
||||||
* @property Carbon|null $completed_at
|
* @property Carbon|null $completed_at
|
||||||
* @property Folder $folder
|
* @property Folder $folder
|
||||||
* @property Carbon|null $created_at
|
* @property Carbon|null $created_at
|
||||||
* @property Carbon|null $updated_at
|
* @property Carbon|null $updated_at
|
||||||
*/
|
*/
|
||||||
#[Fillable(['user_id', 'folder_id', 'description', 'notes', 'status', 'due_date', 'completed_at'])]
|
#[Fillable(['user_id', 'folder_id', 'description', 'notes', 'status', 'position', 'due_date', 'completed_at'])]
|
||||||
class Todo extends Model
|
class Todo extends Model
|
||||||
{
|
{
|
||||||
/** @use HasFactory<TodoFactory> */
|
/** @use HasFactory<TodoFactory> */
|
||||||
@@ -101,6 +102,7 @@ class Todo extends Model
|
|||||||
return $query->incomplete()->whereNotIn('status', [
|
return $query->incomplete()->whereNotIn('status', [
|
||||||
TodoStatus::Cancelled->value,
|
TodoStatus::Cancelled->value,
|
||||||
TodoStatus::Deferred->value,
|
TodoStatus::Deferred->value,
|
||||||
|
TodoStatus::Completed->value,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,4 +127,33 @@ class Todo extends Model
|
|||||||
{
|
{
|
||||||
return $query->active()->whereDate('due_date', today());
|
return $query->active()->whereDate('due_date', today());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopePriority(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query
|
||||||
|
->orderByRaw('completed_at IS NOT NULL')
|
||||||
|
->orderByRaw('position IS NULL')
|
||||||
|
->orderBy('position')
|
||||||
|
->orderByDesc('id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the position to assign to a new todo so it appears at the top of the
|
||||||
|
* priority order for the given user.
|
||||||
|
*/
|
||||||
|
public static function nextPositionFor(User|int $user): int
|
||||||
|
{
|
||||||
|
$min = static::query()->forUser($user)->min('position');
|
||||||
|
|
||||||
|
return $min === null ? 1 : $min - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of days between creation and completion, or null when the
|
||||||
|
* todo has not been completed.
|
||||||
|
*/
|
||||||
|
public function daysToComplete(): ?int
|
||||||
|
{
|
||||||
|
return $this->completed_at === null ? null : $this->created_at->diffInDays($this->completed_at);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -10,6 +10,7 @@ enum TodoStatus: string
|
|||||||
case Blocked = 'blocked';
|
case Blocked = 'blocked';
|
||||||
case Cancelled = 'cancelled';
|
case Cancelled = 'cancelled';
|
||||||
case Deferred = 'deferred';
|
case Deferred = 'deferred';
|
||||||
|
case Completed = 'completed';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the human-friendly label for the status.
|
* Get the human-friendly label for the status.
|
||||||
@@ -23,6 +24,7 @@ enum TodoStatus: string
|
|||||||
self::Blocked => 'Blocked',
|
self::Blocked => 'Blocked',
|
||||||
self::Cancelled => 'Cancelled',
|
self::Cancelled => 'Cancelled',
|
||||||
self::Deferred => 'Deferred',
|
self::Deferred => 'Deferred',
|
||||||
|
self::Completed => 'Completed',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,6 +40,7 @@ enum TodoStatus: string
|
|||||||
self::Blocked => 'red',
|
self::Blocked => 'red',
|
||||||
self::Cancelled => 'zinc',
|
self::Cancelled => 'zinc',
|
||||||
self::Deferred => 'purple',
|
self::Deferred => 'purple',
|
||||||
|
self::Completed => 'emerald',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,6 +49,6 @@ enum TodoStatus: string
|
|||||||
*/
|
*/
|
||||||
public function isTerminal(): bool
|
public function isTerminal(): bool
|
||||||
{
|
{
|
||||||
return in_array($this, [self::Cancelled, self::Deferred], true);
|
return in_array($this, [self::Cancelled, self::Deferred, self::Completed], true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class FolderFactory extends Factory
|
|||||||
return [
|
return [
|
||||||
'user_id' => User::factory(),
|
'user_id' => User::factory(),
|
||||||
'name' => fake()->unique()->words(2, true),
|
'name' => fake()->unique()->words(2, true),
|
||||||
|
'color' => fake()->optional()->randomElement(Folder::COLORS),
|
||||||
'parent_id' => null,
|
'parent_id' => null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('todos', function (Blueprint $table) {
|
||||||
|
$table->integer('position')->nullable()->after('status');
|
||||||
|
$table->index(['user_id', 'position']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('todos', function (Blueprint $table) {
|
||||||
|
$table->dropIndex(['user_id', 'position']);
|
||||||
|
$table->dropColumn('position');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('folders', function (Blueprint $table) {
|
||||||
|
$table->string('color', 20)->nullable()->after('name');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('folders', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('color');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -5,6 +5,7 @@ namespace Database\Seeders;
|
|||||||
use App\Models\Folder;
|
use App\Models\Folder;
|
||||||
use App\Models\Todo;
|
use App\Models\Todo;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\TodoStatus;
|
||||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
@@ -19,11 +20,14 @@ class DatabaseSeeder extends Seeder
|
|||||||
{
|
{
|
||||||
$this->call(BaseDatabaseSeeder::class);
|
$this->call(BaseDatabaseSeeder::class);
|
||||||
|
|
||||||
$user = User::factory()->create([
|
$user = User::updateOrCreate(
|
||||||
'name' => 'Test User',
|
['email' => 'test@example.com'],
|
||||||
'email' => 'test@example.com',
|
[
|
||||||
'is_admin' => true,
|
'name' => 'Test User',
|
||||||
]);
|
'password' => 'password',
|
||||||
|
'is_admin' => true,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
$work = $this->createTopLevelFolder($user, 'Work');
|
$work = $this->createTopLevelFolder($user, 'Work');
|
||||||
$business = $this->createTopLevelFolder($user, 'Business');
|
$business = $this->createTopLevelFolder($user, 'Business');
|
||||||
@@ -63,29 +67,45 @@ class DatabaseSeeder extends Seeder
|
|||||||
$foldersByName = $folders->keyBy(fn (Folder $folder) => $folder->name);
|
$foldersByName = $folders->keyBy(fn (Folder $folder) => $folder->name);
|
||||||
|
|
||||||
foreach ($samples as [$description, $folderName, $daysFromToday, $status]) {
|
foreach ($samples as [$description, $folderName, $daysFromToday, $status]) {
|
||||||
$todo = Todo::factory()->recycle($user)->create([
|
$todo = Todo::firstOrCreate(
|
||||||
'folder_id' => $foldersByName[$folderName]->id,
|
['user_id' => $user->id, 'folder_id' => $foldersByName[$folderName]->id, 'description' => $description],
|
||||||
'description' => $description,
|
['status' => TodoStatus::Open],
|
||||||
'due_date' => $daysFromToday === null ? null : today()->addDays($daysFromToday),
|
);
|
||||||
]);
|
|
||||||
|
if ($daysFromToday === null) {
|
||||||
|
$todo->update(['due_date' => null]);
|
||||||
|
} else {
|
||||||
|
$todo->update(['due_date' => today()->addDays($daysFromToday)]);
|
||||||
|
}
|
||||||
|
|
||||||
if ($status === 'overdue') {
|
if ($status === 'overdue') {
|
||||||
$todo->update(['due_date' => today()->subDays(3)]);
|
$todo->update(['due_date' => today()->subDays(3)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($status === 'completed') {
|
if ($status === 'completed') {
|
||||||
$todo->update(['completed_at' => now()->subDay()]);
|
$todo->update([
|
||||||
|
'status' => TodoStatus::Completed,
|
||||||
|
'completed_at' => now()->subDay(),
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$todo->update(['completed_at' => null]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createTopLevelFolder(User $user, string $name): Folder
|
private function createTopLevelFolder(User $user, string $name): Folder
|
||||||
{
|
{
|
||||||
return Folder::factory()->recycle($user)->create(['name' => $name]);
|
return Folder::firstOrCreate(
|
||||||
|
['user_id' => $user->id, 'name' => $name, 'parent_id' => null],
|
||||||
|
['color' => fake()->optional()->randomElement(Folder::COLORS)],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createChildFolder(Folder $parent, string $name): Folder
|
private function createChildFolder(Folder $parent, string $name): Folder
|
||||||
{
|
{
|
||||||
return Folder::factory()->childOf($parent)->create(['name' => $name]);
|
return Folder::firstOrCreate(
|
||||||
|
['user_id' => $parent->user_id, 'name' => $name, 'parent_id' => $parent->id],
|
||||||
|
['color' => fake()->optional()->randomElement(Folder::COLORS)],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Update deployment script for mytodos.
|
||||||
|
# Run from the repository root on the server:
|
||||||
|
# ./deploy.sh
|
||||||
|
#
|
||||||
|
# Pulls the latest code, installs dependencies, runs the new migrations
|
||||||
|
# (status + position on todos, color on folders), and refreshes the
|
||||||
|
# admin user via BaseDatabaseSeeder. DatabaseSeeder (demo data) is
|
||||||
|
# intentionally NOT run in production.
|
||||||
|
|
||||||
|
APP_DIR="${APP_DIR:-$(pwd)}"
|
||||||
|
|
||||||
|
echo "==> Deploying mytodos update in ${APP_DIR}"
|
||||||
|
|
||||||
|
cd "${APP_DIR}"
|
||||||
|
|
||||||
|
echo "==> Pulling latest code"
|
||||||
|
git pull --ff-only origin main
|
||||||
|
|
||||||
|
echo "==> Installing PHP dependencies"
|
||||||
|
composer install --no-dev --prefer-dist --optimize-autoloader
|
||||||
|
|
||||||
|
echo "==> Installing and building frontend assets"
|
||||||
|
if [ -f package-lock.json ]; then
|
||||||
|
npm ci --no-audit --no-fund
|
||||||
|
else
|
||||||
|
npm install --no-audit --no-fund
|
||||||
|
fi
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
echo "==> Running new migrations"
|
||||||
|
php artisan migrate --force
|
||||||
|
|
||||||
|
echo "==> Seeding base data (admin user)"
|
||||||
|
php artisan db:seed --class=BaseDatabaseSeeder --force
|
||||||
|
|
||||||
|
echo "==> Caching configuration"
|
||||||
|
php artisan config:cache
|
||||||
|
php artisan route:cache
|
||||||
|
php artisan view:cache
|
||||||
|
|
||||||
|
echo "==> Restarting queue workers"
|
||||||
|
php artisan queue:restart
|
||||||
|
|
||||||
|
echo "==> Update deployed successfully"
|
||||||
+9
-2
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 25 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 334 KiB |
@@ -1,8 +1 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 42" {{ $attributes }}>
|
<img src="{{ asset('mytodos_main_logo.svg') }}" alt="{{ config('app.name', 'Laravel') }}" {{ $attributes->merge(['class' => 'max-w-full']) }} />
|
||||||
<path
|
|
||||||
fill="currentColor"
|
|
||||||
fill-rule="evenodd"
|
|
||||||
clip-rule="evenodd"
|
|
||||||
d="M17.2 5.633 8.6.855 0 5.633v26.51l16.2 9 16.2-9v-8.442l7.6-4.223V9.856l-8.6-4.777-8.6 4.777V18.3l-5.6 3.111V5.633ZM38 18.301l-5.6 3.11v-6.157l5.6-3.11V18.3Zm-1.06-7.856-5.54 3.078-5.54-3.079 5.54-3.078 5.54 3.079ZM24.8 18.3v-6.157l5.6 3.111v6.158L24.8 18.3Zm-1 1.732 5.54 3.078-13.14 7.302-5.54-3.078 13.14-7.3v-.002Zm-16.2 7.89 7.6 4.222V38.3L2 30.966V7.92l5.6 3.111v16.892ZM8.6 9.3 3.06 6.222 8.6 3.143l5.54 3.08L8.6 9.3Zm21.8 15.51-13.2 7.334V38.3l13.2-7.334v-6.156ZM9.6 11.034l5.6-3.11v14.6l-5.6 3.11v-14.6Z"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 714 B After Width: | Height: | Size: 144 B |
@@ -0,0 +1,44 @@
|
|||||||
|
@props(['model' => null])
|
||||||
|
|
||||||
|
@php
|
||||||
|
$swatches = [
|
||||||
|
'zinc' => 'bg-zinc-400',
|
||||||
|
'red' => 'bg-red-500',
|
||||||
|
'orange' => 'bg-orange-500',
|
||||||
|
'amber' => 'bg-amber-500',
|
||||||
|
'green' => 'bg-green-500',
|
||||||
|
'emerald' => 'bg-emerald-500',
|
||||||
|
'sky' => 'bg-sky-500',
|
||||||
|
'blue' => 'bg-blue-500',
|
||||||
|
'indigo' => 'bg-indigo-500',
|
||||||
|
'violet' => 'bg-violet-500',
|
||||||
|
'fuchsia' => 'bg-fuchsia-500',
|
||||||
|
'pink' => 'bg-pink-500',
|
||||||
|
];
|
||||||
|
|
||||||
|
$selected = 'ring-2 ring-zinc-900/80 ring-offset-2 ring-offset-white dark:ring-zinc-100/80 dark:ring-offset-zinc-900';
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
<div x-data="{ color: @entangle($model) }" class="flex flex-wrap items-center gap-2" role="radiogroup" aria-label="{{ __('Color') }}">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex size-6 items-center justify-center rounded-full border border-zinc-300 text-zinc-500 hover:bg-zinc-100 dark:border-zinc-600 dark:text-zinc-400 dark:hover:bg-zinc-800"
|
||||||
|
@click="color = ''"
|
||||||
|
:class="color === '' || color === null ? '{{ $selected }}' : ''"
|
||||||
|
:title="`{{ __('No color') }}`"
|
||||||
|
data-test="color-option-none"
|
||||||
|
>
|
||||||
|
<flux:icon.x-mark variant="micro" />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
@foreach ($swatches as $name => $class)
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="size-6 shrink-0 rounded-full border border-black/10 {{ $class }}"
|
||||||
|
@click="color = '{{ $name }}'"
|
||||||
|
:class="color === '{{ $name }}' ? '{{ $selected }}' : ''"
|
||||||
|
:title="`{{ $name }}`"
|
||||||
|
data-test="color-option-{{ $name }}"
|
||||||
|
></button>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
@props(['color' => null])
|
||||||
|
|
||||||
|
@php
|
||||||
|
$classes = match ($color) {
|
||||||
|
'zinc' => 'bg-zinc-400',
|
||||||
|
'red' => 'bg-red-500',
|
||||||
|
'orange' => 'bg-orange-500',
|
||||||
|
'amber' => 'bg-amber-500',
|
||||||
|
'green' => 'bg-green-500',
|
||||||
|
'emerald' => 'bg-emerald-500',
|
||||||
|
'sky' => 'bg-sky-500',
|
||||||
|
'blue' => 'bg-blue-500',
|
||||||
|
'indigo' => 'bg-indigo-500',
|
||||||
|
'violet' => 'bg-violet-500',
|
||||||
|
'fuchsia' => 'bg-fuchsia-500',
|
||||||
|
'pink' => 'bg-pink-500',
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
@if ($classes)
|
||||||
|
<span {{ $attributes->merge(['class' => "inline-block size-2.5 shrink-0 rounded-full {$classes}"]) }} aria-hidden="true"></span>
|
||||||
|
@endif
|
||||||
@@ -13,6 +13,9 @@
|
|||||||
<flux:navbar.item icon="layout-grid" :href="route('dashboard')" :current="request()->routeIs('dashboard')" wire:navigate>
|
<flux:navbar.item icon="layout-grid" :href="route('dashboard')" :current="request()->routeIs('dashboard')" wire:navigate>
|
||||||
{{ __('Dashboard') }}
|
{{ __('Dashboard') }}
|
||||||
</flux:navbar.item>
|
</flux:navbar.item>
|
||||||
|
<flux:navbar.item icon="check-circle" :href="route('todos')" :current="request()->routeIs('todos')" wire:navigate>
|
||||||
|
{{ __('Todos') }}
|
||||||
|
</flux:navbar.item>
|
||||||
<flux:navbar.item icon="folder" :href="route('folders')" :current="request()->routeIs('folders')" wire:navigate>
|
<flux:navbar.item icon="folder" :href="route('folders')" :current="request()->routeIs('folders')" wire:navigate>
|
||||||
{{ __('Folders') }}
|
{{ __('Folders') }}
|
||||||
</flux:navbar.item>
|
</flux:navbar.item>
|
||||||
@@ -59,6 +62,9 @@
|
|||||||
<flux:sidebar.item icon="layout-grid" :href="route('dashboard')" :current="request()->routeIs('dashboard')" wire:navigate>
|
<flux:sidebar.item icon="layout-grid" :href="route('dashboard')" :current="request()->routeIs('dashboard')" wire:navigate>
|
||||||
{{ __('Dashboard') }}
|
{{ __('Dashboard') }}
|
||||||
</flux:sidebar.item>
|
</flux:sidebar.item>
|
||||||
|
<flux:sidebar.item icon="check-circle" :href="route('todos')" :current="request()->routeIs('todos')" wire:navigate>
|
||||||
|
{{ __('Todos') }}
|
||||||
|
</flux:sidebar.item>
|
||||||
<flux:sidebar.item icon="folder" :href="route('folders')" :current="request()->routeIs('folders')" wire:navigate>
|
<flux:sidebar.item icon="folder" :href="route('folders')" :current="request()->routeIs('folders')" wire:navigate>
|
||||||
{{ __('Folders') }}
|
{{ __('Folders') }}
|
||||||
</flux:sidebar.item>
|
</flux:sidebar.item>
|
||||||
|
|||||||
@@ -15,6 +15,9 @@
|
|||||||
<flux:sidebar.item icon="home" :href="route('dashboard')" :current="request()->routeIs('dashboard')" wire:navigate>
|
<flux:sidebar.item icon="home" :href="route('dashboard')" :current="request()->routeIs('dashboard')" wire:navigate>
|
||||||
{{ __('Dashboard') }}
|
{{ __('Dashboard') }}
|
||||||
</flux:sidebar.item>
|
</flux:sidebar.item>
|
||||||
|
<flux:sidebar.item icon="check-circle" :href="route('todos')" :current="request()->routeIs('todos')" wire:navigate>
|
||||||
|
{{ __('Todos') }}
|
||||||
|
</flux:sidebar.item>
|
||||||
<flux:sidebar.item icon="folder" :href="route('folders')" :current="request()->routeIs('folders')" wire:navigate>
|
<flux:sidebar.item icon="folder" :href="route('folders')" :current="request()->routeIs('folders')" wire:navigate>
|
||||||
{{ __('Folders') }}
|
{{ __('Folders') }}
|
||||||
</flux:sidebar.item>
|
</flux:sidebar.item>
|
||||||
@@ -31,16 +34,6 @@
|
|||||||
|
|
||||||
<flux:spacer />
|
<flux:spacer />
|
||||||
|
|
||||||
<flux:sidebar.nav>
|
|
||||||
<flux:sidebar.item icon="folder-git-2" href="https://github.com/laravel/livewire-starter-kit" target="_blank">
|
|
||||||
{{ __('Repository') }}
|
|
||||||
</flux:sidebar.item>
|
|
||||||
|
|
||||||
<flux:sidebar.item icon="book-open-text" href="https://laravel.com/docs/starter-kits#livewire" target="_blank">
|
|
||||||
{{ __('Documentation') }}
|
|
||||||
</flux:sidebar.item>
|
|
||||||
</flux:sidebar.nav>
|
|
||||||
|
|
||||||
<x-desktop-user-menu class="hidden lg:block" :name="auth()->user()->name" />
|
<x-desktop-user-menu class="hidden lg:block" :name="auth()->user()->name" />
|
||||||
</flux:sidebar>
|
</flux:sidebar>
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,18 @@
|
|||||||
@include('partials.head')
|
@include('partials.head')
|
||||||
</head>
|
</head>
|
||||||
<body class="min-h-screen bg-white antialiased dark:bg-linear-to-b dark:from-neutral-950 dark:to-neutral-900">
|
<body class="min-h-screen bg-white antialiased dark:bg-linear-to-b dark:from-neutral-950 dark:to-neutral-900">
|
||||||
<div class="bg-background flex min-h-svh flex-col items-center justify-center gap-6 p-6 md:p-10">
|
<div class="bg-background flex min-h-svh flex-col items-center justify-start gap-6 p-6 md:p-10">
|
||||||
<div class="flex w-full max-w-sm flex-col gap-2">
|
<div class="flex w-full max-w-sm flex-col gap-2">
|
||||||
<a href="{{ route('home') }}" class="flex flex-col items-center gap-2 font-medium" wire:navigate>
|
<a href="{{ route('home') }}" class="flex flex-col items-center gap-2 font-medium" wire:navigate>
|
||||||
<span class="flex h-9 w-9 mb-1 items-center justify-center rounded-md">
|
@if (Route::is('login'))
|
||||||
<x-app-logo-icon class="size-9 fill-current text-black dark:text-white" />
|
<span class="flex mb-1 items-center justify-center rounded-md">
|
||||||
</span>
|
<x-app-logo-icon class="size-20 fill-current text-black dark:text-white sm:size-28" width="112" height="112" />
|
||||||
|
</span>
|
||||||
|
@else
|
||||||
|
<span class="flex h-9 w-9 mb-1 items-center justify-center rounded-md">
|
||||||
|
<x-app-logo-icon class="size-9 fill-current text-black dark:text-white" />
|
||||||
|
</span>
|
||||||
|
@endif
|
||||||
<span class="sr-only">{{ config('app.name', 'Laravel') }}</span>
|
<span class="sr-only">{{ config('app.name', 'Laravel') }}</span>
|
||||||
</a>
|
</a>
|
||||||
<div class="flex flex-col gap-6">
|
<div class="flex flex-col gap-6">
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Builder;
|
|||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Livewire\Attributes\Computed;
|
use Livewire\Attributes\Computed;
|
||||||
use Livewire\Attributes\Locked;
|
use Livewire\Attributes\Locked;
|
||||||
@@ -18,6 +19,8 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
{
|
{
|
||||||
use WithPagination;
|
use WithPagination;
|
||||||
|
|
||||||
|
private const PER_PAGE = 10;
|
||||||
|
|
||||||
#[Locked]
|
#[Locked]
|
||||||
public ?int $editingTodoId = null;
|
public ?int $editingTodoId = null;
|
||||||
|
|
||||||
@@ -124,7 +127,10 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
if ($this->editingTodoId !== null) {
|
if ($this->editingTodoId !== null) {
|
||||||
$this->todoForUser($this->editingTodoId)->update($data);
|
$this->todoForUser($this->editingTodoId)->update($data);
|
||||||
} else {
|
} 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');
|
$this->reset('showTodoForm', 'editingTodoId', 'description', 'todoStatus', 'dueDate', 'notes', 'formFolderId');
|
||||||
@@ -134,9 +140,15 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
{
|
{
|
||||||
$todo = $this->todoForUser($todoId);
|
$todo = $this->todoForUser($todoId);
|
||||||
|
|
||||||
$todo->update([
|
$data = ['completed_at' => $todo->completed_at === null ? now() : null];
|
||||||
'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
|
public function confirmTodoDelete(int $todoId): void
|
||||||
@@ -237,10 +249,79 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
|
|
||||||
#[Computed]
|
#[Computed]
|
||||||
public function todos(): LengthAwarePaginator
|
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()
|
return Todo::query()
|
||||||
->forUser(auth()->id())
|
->forUser(auth()->id())
|
||||||
->with('folder.parent')
|
|
||||||
->when(
|
->when(
|
||||||
$this->search !== '',
|
$this->search !== '',
|
||||||
fn (Builder $query) => $query->where('description', 'like', '%'.$this->search.'%')
|
fn (Builder $query) => $query->where('description', 'like', '%'.$this->search.'%')
|
||||||
@@ -257,12 +338,7 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
'all', '' => $query,
|
'all', '' => $query,
|
||||||
default => $query->where('status', $this->status)->incomplete(),
|
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
|
private function descendantIds(int $folderId): array
|
||||||
@@ -311,7 +387,7 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
</flux:callout>
|
</flux:callout>
|
||||||
@endif
|
@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:card size="sm">
|
||||||
<flux:heading size="sm" class="text-zinc-500">{{ __('Open') }}</flux:heading>
|
<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>
|
<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:card>
|
||||||
<flux:table :paginate="$this->todos">
|
<flux:table :paginate="$this->todos">
|
||||||
<flux:table.columns>
|
<flux:table.columns>
|
||||||
|
<flux:table.column width="3rem"></flux:table.column>
|
||||||
<flux:table.column width="3rem">{{ __('Done') }}</flux:table.column>
|
<flux:table.column width="3rem">{{ __('Done') }}</flux:table.column>
|
||||||
<flux:table.column>{{ __('Description') }}</flux:table.column>
|
<flux:table.column>{{ __('Description') }}</flux:table.column>
|
||||||
<flux:table.column>{{ __('Status') }}</flux:table.column>
|
<flux:table.column>{{ __('Status') }}</flux:table.column>
|
||||||
<flux:table.column>{{ __('Folder') }}</flux:table.column>
|
<flux:table.column>{{ __('Folder') }}</flux:table.column>
|
||||||
<flux:table.column>{{ __('Due') }}</flux:table.column>
|
<flux:table.column>{{ __('Due') }}</flux:table.column>
|
||||||
<flux:table.column>{{ __('Created') }}</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.columns>
|
||||||
|
|
||||||
<flux:table.rows>
|
<flux:table.rows wire:sort="handleSort">
|
||||||
@forelse ($this->todos as $todo)
|
@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:table.cell class="py-0">
|
||||||
<flux:checkbox
|
<flux:checkbox
|
||||||
:checked="$todo->completed_at !== null"
|
:checked="$todo->completed_at !== null"
|
||||||
@@ -437,7 +521,10 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
</flux:table.cell>
|
</flux:table.cell>
|
||||||
|
|
||||||
<flux:table.cell class="text-zinc-500">
|
<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>
|
||||||
|
|
||||||
<flux:table.cell>
|
<flux:table.cell>
|
||||||
@@ -456,8 +543,49 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
{{ $todo->created_at->format('M j, Y') }}
|
{{ $todo->created_at->format('M j, Y') }}
|
||||||
</flux:table.cell>
|
</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">
|
<flux:table.cell class="py-0">
|
||||||
<div class="flex justify-end gap-1">
|
<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
|
<flux:button
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
@@ -479,7 +607,7 @@ new #[Title('Dashboard')] class extends Component
|
|||||||
</flux:table.row>
|
</flux:table.row>
|
||||||
@empty
|
@empty
|
||||||
<flux:table.row>
|
<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:text>{{ __('No todos match your filters.') }}</flux:text>
|
||||||
</flux:table.cell>
|
</flux:table.cell>
|
||||||
</flux:table.row>
|
</flux:table.row>
|
||||||
|
|||||||
@@ -15,11 +15,15 @@ new #[Title('Folders')] class extends Component
|
|||||||
{
|
{
|
||||||
public string $newFolderName = '';
|
public string $newFolderName = '';
|
||||||
|
|
||||||
|
public string $newFolderColor = '';
|
||||||
|
|
||||||
#[Locked]
|
#[Locked]
|
||||||
public ?int $creatingChildOf = null;
|
public ?int $creatingChildOf = null;
|
||||||
|
|
||||||
public string $newChildName = '';
|
public string $newChildName = '';
|
||||||
|
|
||||||
|
public string $newChildColor = '';
|
||||||
|
|
||||||
#[Locked]
|
#[Locked]
|
||||||
public ?int $renamingFolderId = null;
|
public ?int $renamingFolderId = null;
|
||||||
|
|
||||||
@@ -28,6 +32,14 @@ new #[Title('Folders')] class extends Component
|
|||||||
#[Locked]
|
#[Locked]
|
||||||
public ?int $confirmingFolderDelete = null;
|
public ?int $confirmingFolderDelete = null;
|
||||||
|
|
||||||
|
#[Locked]
|
||||||
|
public ?int $expandedFolderId = null;
|
||||||
|
|
||||||
|
#[Locked]
|
||||||
|
public ?int $colorEditingFolderId = null;
|
||||||
|
|
||||||
|
public string $colorDraft = '';
|
||||||
|
|
||||||
public bool $showTodoForm = false;
|
public bool $showTodoForm = false;
|
||||||
|
|
||||||
#[Locked]
|
#[Locked]
|
||||||
@@ -45,15 +57,17 @@ new #[Title('Folders')] class extends Component
|
|||||||
{
|
{
|
||||||
$validated = $this->validate([
|
$validated = $this->validate([
|
||||||
'newFolderName' => $this->folderNameRules(parentId: null),
|
'newFolderName' => $this->folderNameRules(parentId: null),
|
||||||
|
'newFolderColor' => $this->folderColorRules(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Folder::create([
|
Folder::create([
|
||||||
'user_id' => auth()->id(),
|
'user_id' => auth()->id(),
|
||||||
'name' => $validated['newFolderName'],
|
'name' => $validated['newFolderName'],
|
||||||
|
'color' => filled($validated['newFolderColor']) ? $validated['newFolderColor'] : null,
|
||||||
'parent_id' => null,
|
'parent_id' => null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->reset('newFolderName');
|
$this->reset('newFolderName', 'newFolderColor');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function startChildCreate(int $folderId): void
|
public function startChildCreate(int $folderId): void
|
||||||
@@ -61,13 +75,13 @@ new #[Title('Folders')] class extends Component
|
|||||||
$this->folderForUser($folderId);
|
$this->folderForUser($folderId);
|
||||||
|
|
||||||
$this->creatingChildOf = $folderId;
|
$this->creatingChildOf = $folderId;
|
||||||
$this->reset('newChildName');
|
$this->reset('newChildName', 'newChildColor');
|
||||||
$this->resetErrorBag('newChildName');
|
$this->resetErrorBag('newChildName', 'newChildColor');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cancelChildCreate(): void
|
public function cancelChildCreate(): void
|
||||||
{
|
{
|
||||||
$this->reset('creatingChildOf', 'newChildName');
|
$this->reset('creatingChildOf', 'newChildName', 'newChildColor');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createChildFolder(): void
|
public function createChildFolder(): void
|
||||||
@@ -76,15 +90,17 @@ new #[Title('Folders')] class extends Component
|
|||||||
|
|
||||||
$validated = $this->validate([
|
$validated = $this->validate([
|
||||||
'newChildName' => $this->folderNameRules(parentId: $this->creatingChildOf),
|
'newChildName' => $this->folderNameRules(parentId: $this->creatingChildOf),
|
||||||
|
'newChildColor' => $this->folderColorRules(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Folder::create([
|
Folder::create([
|
||||||
'user_id' => auth()->id(),
|
'user_id' => auth()->id(),
|
||||||
'name' => $validated['newChildName'],
|
'name' => $validated['newChildName'],
|
||||||
|
'color' => filled($validated['newChildColor']) ? $validated['newChildColor'] : null,
|
||||||
'parent_id' => $this->creatingChildOf,
|
'parent_id' => $this->creatingChildOf,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->reset('creatingChildOf', 'newChildName');
|
$this->reset('creatingChildOf', 'newChildName', 'newChildColor');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function startRename(int $folderId): void
|
public function startRename(int $folderId): void
|
||||||
@@ -124,12 +140,70 @@ new #[Title('Folders')] class extends Component
|
|||||||
|
|
||||||
public function deleteFolder(): void
|
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->confirmingFolderDelete = null;
|
||||||
$this->modal('confirm-folder-delete')->close();
|
$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
|
public function startTodoCreate(int $folderId): void
|
||||||
{
|
{
|
||||||
$this->folderForUser($folderId);
|
$this->folderForUser($folderId);
|
||||||
@@ -158,6 +232,7 @@ new #[Title('Folders')] class extends Component
|
|||||||
'status' => TodoStatus::from($validated['todoStatus']),
|
'status' => TodoStatus::from($validated['todoStatus']),
|
||||||
'due_date' => filled($validated['todoDueDate']) ? Carbon::parse($validated['todoDueDate']) : null,
|
'due_date' => filled($validated['todoDueDate']) ? Carbon::parse($validated['todoDueDate']) : null,
|
||||||
'notes' => filled($validated['todoNotes']) ? $validated['todoNotes'] : null,
|
'notes' => filled($validated['todoNotes']) ? $validated['todoNotes'] : null,
|
||||||
|
'position' => Todo::nextPositionFor(auth()->user()),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->reset('showTodoForm', 'todoFolderId', 'todoDescription', 'todoStatus', 'todoDueDate', 'todoNotes');
|
$this->reset('showTodoForm', 'todoFolderId', 'todoDescription', 'todoStatus', 'todoDueDate', 'todoNotes');
|
||||||
@@ -201,6 +276,14 @@ new #[Title('Folders')] class extends Component
|
|||||||
->countBy();
|
->countBy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, mixed>
|
||||||
|
*/
|
||||||
|
private function folderColorRules(): array
|
||||||
|
{
|
||||||
|
return ['nullable', 'string', 'max:20', Rule::in([...Folder::COLORS, ''])];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<int, mixed>
|
* @return array<int, mixed>
|
||||||
*/
|
*/
|
||||||
@@ -250,6 +333,12 @@ new #[Title('Folders')] class extends Component
|
|||||||
<flux:error name="newFolderName" />
|
<flux:error name="newFolderName" />
|
||||||
</div>
|
</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">
|
<flux:button variant="primary" type="submit" icon="plus" data-test="add-folder-button">
|
||||||
{{ __('Add folder') }}
|
{{ __('Add folder') }}
|
||||||
</flux:button>
|
</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">
|
<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)
|
@forelse ($this->folderTree as $node)
|
||||||
<div class="p-4" :style="'margin-left: {{ $node['depth'] * 1.5 }}rem'">
|
<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)
|
@if ($renamingFolderId === $node['folder']->id)
|
||||||
<form wire:submit="saveRename" class="flex flex-1 flex-wrap items-center gap-3">
|
<form wire:submit="saveRename" class="flex flex-1 flex-wrap items-center gap-3">
|
||||||
<flux:input
|
<flux:input
|
||||||
@@ -280,17 +377,39 @@ new #[Title('Folders')] class extends Component
|
|||||||
<flux:error name="renameName" />
|
<flux:error name="renameName" />
|
||||||
</form>
|
</form>
|
||||||
@else
|
@else
|
||||||
<flux:heading size="sm" class="truncate" data-test="folder-name-{{ $node['folder']->id }}">
|
<div class="flex min-w-0 items-center gap-2">
|
||||||
{{ $node['folder']->name }}
|
<x-folder-dot :color="$node['folder']->color" data-test="folder-dot-{{ $node['folder']->id }}" />
|
||||||
</flux:heading>
|
<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') }}
|
{{ $this->openCounts->get($node['folder']->id, 0) }} {{ __('open') }}
|
||||||
</flux:badge>
|
</flux:badge>
|
||||||
|
|
||||||
<flux:spacer />
|
<flux:spacer />
|
||||||
|
|
||||||
<div class="flex items-center gap-1">
|
<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:tooltip :content="__('View todos')">
|
||||||
<flux:button
|
<flux:button
|
||||||
size="sm"
|
size="sm"
|
||||||
@@ -341,6 +460,36 @@ new #[Title('Folders')] class extends Component
|
|||||||
@endif
|
@endif
|
||||||
</div>
|
</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)
|
@if ($creatingChildOf === $node['folder']->id)
|
||||||
<form wire:submit="createChildFolder" class="mt-3 flex flex-wrap items-end gap-3">
|
<form wire:submit="createChildFolder" class="mt-3 flex flex-wrap items-end gap-3">
|
||||||
<div class="min-w-64 flex-1">
|
<div class="min-w-64 flex-1">
|
||||||
@@ -353,6 +502,11 @@ new #[Title('Folders')] class extends Component
|
|||||||
/>
|
/>
|
||||||
<flux:error name="newChildName" />
|
<flux:error name="newChildName" />
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<flux:label size="sm">{{ __('Color') }}</flux:label>
|
||||||
|
<x-color-picker model="newChildColor" />
|
||||||
|
<flux:error name="newChildColor" />
|
||||||
|
</div>
|
||||||
<div class="flex gap-2">
|
<div class="flex gap-2">
|
||||||
<flux:button size="sm" variant="primary" type="submit" icon="plus" data-test="add-child-button">
|
<flux:button size="sm" variant="primary" type="submit" icon="plus" data-test="add-child-button">
|
||||||
{{ __('Add') }}
|
{{ __('Add') }}
|
||||||
@@ -444,6 +598,30 @@ new #[Title('Folders')] class extends Component
|
|||||||
</form>
|
</form>
|
||||||
</flux:modal>
|
</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">
|
<flux:modal name="confirm-folder-delete" class="md:w-lg">
|
||||||
<div class="space-y-6">
|
<div class="space-y-6">
|
||||||
<div>
|
<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>
|
||||||
File diff suppressed because one or more lines are too long
@@ -6,6 +6,7 @@ Route::view('/', 'welcome')->name('home');
|
|||||||
|
|
||||||
Route::middleware(['auth', 'verified'])->group(function () {
|
Route::middleware(['auth', 'verified'])->group(function () {
|
||||||
Route::livewire('dashboard', 'pages::dashboard')->name('dashboard');
|
Route::livewire('dashboard', 'pages::dashboard')->name('dashboard');
|
||||||
|
Route::livewire('todos', 'pages::todos')->name('todos');
|
||||||
Route::livewire('folders', 'pages::folders')->name('folders');
|
Route::livewire('folders', 'pages::folders')->name('folders');
|
||||||
Route::livewire('admin/notes-limits', 'pages::admin.notes-limits')->name('admin.notes-limits');
|
Route::livewire('admin/notes-limits', 'pages::admin.notes-limits')->name('admin.notes-limits');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -331,12 +331,42 @@ test('users can mark a todo done and reopen it', function () {
|
|||||||
->assertSet('todoCounts.completed', 1);
|
->assertSet('todoCounts.completed', 1);
|
||||||
|
|
||||||
expect($todo->fresh()->completed_at)->not->toBeNull();
|
expect($todo->fresh()->completed_at)->not->toBeNull();
|
||||||
|
expect($todo->fresh()->status)->toBe(TodoStatus::Completed);
|
||||||
|
|
||||||
Livewire::test('pages::dashboard')
|
Livewire::test('pages::dashboard')
|
||||||
->call('toggleComplete', $todo->id)
|
->call('toggleComplete', $todo->id)
|
||||||
->assertSet('todoCounts.completed', 0);
|
->assertSet('todoCounts.completed', 0);
|
||||||
|
|
||||||
expect($todo->fresh()->completed_at)->toBeNull();
|
expect($todo->fresh()->completed_at)->toBeNull();
|
||||||
|
expect($todo->fresh()->status)->toBe(TodoStatus::Open);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an in-progress todo is marked completed when checked', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
$todo = Todo::factory()->recycle($user)->for($folder)->withStatus(TodoStatus::InProgress)->create(['description' => 'Draft plan']);
|
||||||
|
|
||||||
|
Livewire::test('pages::dashboard')
|
||||||
|
->call('toggleComplete', $todo->id);
|
||||||
|
|
||||||
|
expect($todo->fresh()->completed_at)->not->toBeNull();
|
||||||
|
expect($todo->fresh()->status)->toBe(TodoStatus::Completed);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('checking an on-hold todo does not overwrite its status', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
$todo = Todo::factory()->recycle($user)->for($folder)->withStatus(TodoStatus::OnHold)->create(['description' => 'Waiting for signoff']);
|
||||||
|
|
||||||
|
Livewire::test('pages::dashboard')
|
||||||
|
->call('toggleComplete', $todo->id);
|
||||||
|
|
||||||
|
expect($todo->fresh()->completed_at)->not->toBeNull();
|
||||||
|
expect($todo->fresh()->status)->toBe(TodoStatus::OnHold);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('completed todos render with strikethrough styling', function () {
|
test('completed todos render with strikethrough styling', function () {
|
||||||
@@ -355,6 +385,29 @@ test('completed todos render with strikethrough styling', function () {
|
|||||||
->assertDontSeeHtml('line-through text-zinc-400">Pending task');
|
->assertDontSeeHtml('line-through text-zinc-400">Pending task');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('completed todos show their completion date and days to completion', function () {
|
||||||
|
$this->travelTo('2026-09-10 09:00:00');
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
$todo = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Shipped feature']);
|
||||||
|
|
||||||
|
$this->travelTo('2026-09-18 09:00:00');
|
||||||
|
|
||||||
|
Livewire::test('pages::dashboard')
|
||||||
|
->call('toggleComplete', $todo->id);
|
||||||
|
|
||||||
|
$todo->refresh();
|
||||||
|
|
||||||
|
expect($todo->daysToComplete())->toBe(8);
|
||||||
|
|
||||||
|
Livewire::test('pages::dashboard')
|
||||||
|
->assertSee('Sep 18, 2026')
|
||||||
|
->assertSee('Completed in 8 days');
|
||||||
|
});
|
||||||
|
|
||||||
test('users can delete a todo', function () {
|
test('users can delete a todo', function () {
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
$this->actingAs($user);
|
$this->actingAs($user);
|
||||||
@@ -432,3 +485,137 @@ test('users cannot create todos in another user folders', function () {
|
|||||||
|
|
||||||
$this->assertDatabaseCount('todos', 0);
|
$this->assertDatabaseCount('todos', 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('new todos are added to the top of the priority order', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
|
||||||
|
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Older todo', 'position' => 2]);
|
||||||
|
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Middle todo', 'position' => 1]);
|
||||||
|
|
||||||
|
Livewire::test('pages::dashboard')
|
||||||
|
->call('openCreateForm')
|
||||||
|
->set('description', 'Newest todo')
|
||||||
|
->set('formFolderId', $folder->id)
|
||||||
|
->call('saveTodo');
|
||||||
|
|
||||||
|
$newest = Todo::where('description', 'Newest todo')->firstOrFail();
|
||||||
|
|
||||||
|
expect($newest->position)->toBe(0);
|
||||||
|
|
||||||
|
Livewire::test('pages::dashboard')
|
||||||
|
->assertSeeInOrder(['Newest todo', 'Middle todo', 'Older todo']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users can move a todo up in the priority order', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
|
||||||
|
$first = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'First todo', 'position' => 0]);
|
||||||
|
$second = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Second todo', 'position' => 1]);
|
||||||
|
$third = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Third todo', 'position' => 2]);
|
||||||
|
|
||||||
|
Livewire::test('pages::dashboard')
|
||||||
|
->call('moveTodo', $third->id, 'up');
|
||||||
|
|
||||||
|
expect($first->fresh()->position)->toBe(0);
|
||||||
|
expect($second->fresh()->position)->toBe(2);
|
||||||
|
expect($third->fresh()->position)->toBe(1);
|
||||||
|
|
||||||
|
Livewire::test('pages::dashboard')
|
||||||
|
->assertSeeInOrder(['First todo', 'Third todo', 'Second todo']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users can move a todo down in the priority order', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
|
||||||
|
$first = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'First todo', 'position' => 0]);
|
||||||
|
$second = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Second todo', 'position' => 1]);
|
||||||
|
|
||||||
|
Livewire::test('pages::dashboard')
|
||||||
|
->call('moveTodo', $first->id, 'down');
|
||||||
|
|
||||||
|
expect($first->fresh()->position)->toBe(1);
|
||||||
|
expect($second->fresh()->position)->toBe(0);
|
||||||
|
|
||||||
|
Livewire::test('pages::dashboard')
|
||||||
|
->assertSeeInOrder(['Second todo', 'First todo']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('moving the first todo up does nothing', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
|
||||||
|
$first = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'First todo', 'position' => 0]);
|
||||||
|
$second = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Second todo', 'position' => 1]);
|
||||||
|
|
||||||
|
Livewire::test('pages::dashboard')
|
||||||
|
->call('moveTodo', $first->id, 'up');
|
||||||
|
|
||||||
|
expect($first->fresh()->position)->toBe(0);
|
||||||
|
expect($second->fresh()->position)->toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users can drag a todo to a new position', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
|
||||||
|
$first = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'First todo', 'position' => 0]);
|
||||||
|
$second = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Second todo', 'position' => 1]);
|
||||||
|
$third = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Third todo', 'position' => 2]);
|
||||||
|
|
||||||
|
Livewire::test('pages::dashboard')
|
||||||
|
->call('handleSort', $first->id, 2);
|
||||||
|
|
||||||
|
expect($first->fresh()->position)->toBe(2);
|
||||||
|
expect($second->fresh()->position)->toBe(0);
|
||||||
|
expect($third->fresh()->position)->toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('dragging accounts for the pagination offset', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
|
||||||
|
$todos = collect(range(1, 12))
|
||||||
|
->map(fn (int $n) => Todo::factory()->recycle($user)->for($folder)->create([
|
||||||
|
'description' => 'Todo '.$n,
|
||||||
|
'position' => $n - 1,
|
||||||
|
]));
|
||||||
|
|
||||||
|
$todoEleven = $todos->get(10);
|
||||||
|
$todoTwelve = $todos->get(11);
|
||||||
|
|
||||||
|
Livewire::withQueryParams(['page' => 2])
|
||||||
|
->test('pages::dashboard')
|
||||||
|
->assertSee('Todo 12')
|
||||||
|
->call('handleSort', $todoTwelve->id, 0);
|
||||||
|
|
||||||
|
expect($todoEleven->fresh()->position)->toBe(11);
|
||||||
|
expect($todoTwelve->fresh()->position)->toBe(10);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('completed todos sort last regardless of their position', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
|
||||||
|
Todo::factory()->recycle($user)->for($folder)->completed()->create(['description' => 'Finished task', 'position' => 0]);
|
||||||
|
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Pending task', 'position' => 1]);
|
||||||
|
|
||||||
|
Livewire::test('pages::dashboard')
|
||||||
|
->assertSeeInOrder(['Pending task', 'Finished task']);
|
||||||
|
});
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Folder;
|
||||||
|
use App\Models\Todo;
|
||||||
|
use App\Models\User;
|
||||||
|
use Database\Seeders\DatabaseSeeder;
|
||||||
|
|
||||||
|
use function Pest\Laravel\seed;
|
||||||
|
|
||||||
|
test('full seeding creates the test user, folders and todos', function () {
|
||||||
|
seed(DatabaseSeeder::class);
|
||||||
|
|
||||||
|
expect(User::where('email', 'test@example.com')->count())->toBe(1)
|
||||||
|
->and(Folder::count())->toBe(9)
|
||||||
|
->and(Todo::count())->toBe(8);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('full seeding is idempotent', function () {
|
||||||
|
seed(DatabaseSeeder::class);
|
||||||
|
seed(DatabaseSeeder::class);
|
||||||
|
|
||||||
|
expect(User::where('email', 'test@example.com')->count())->toBe(1)
|
||||||
|
->and(Folder::count())->toBe(9)
|
||||||
|
->and(Todo::count())->toBe(8);
|
||||||
|
});
|
||||||
@@ -4,6 +4,7 @@ use App\Models\Folder;
|
|||||||
use App\Models\Todo;
|
use App\Models\Todo;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\TodoStatus;
|
use App\TodoStatus;
|
||||||
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
use Livewire\Livewire;
|
use Livewire\Livewire;
|
||||||
|
|
||||||
test('guests are redirected to the login page', function () {
|
test('guests are redirected to the login page', function () {
|
||||||
@@ -241,3 +242,214 @@ test('a todo description is required when adding from the folders page', functio
|
|||||||
|
|
||||||
$this->assertDatabaseCount('todos', 0);
|
$this->assertDatabaseCount('todos', 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('clicking the open badge expands the open todos in the folder', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
Todo::factory()->recycle($user)->for($work)->create(['description' => 'Open task', 'due_date' => today()->addDays(2)]);
|
||||||
|
Todo::factory()->recycle($user)->for($work)->completed()->create(['description' => 'Done task']);
|
||||||
|
|
||||||
|
Livewire::test('pages::folders')
|
||||||
|
->call('toggleExpandFolder', $work->id)
|
||||||
|
->assertSet('expandedFolderId', $work->id)
|
||||||
|
->assertSee('Open task')
|
||||||
|
->assertDontSee('Done task');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('clicking the open badge again collapses the folder todos', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
Todo::factory()->recycle($user)->for($work)->create(['description' => 'Open task', 'due_date' => today()->addDays(2)]);
|
||||||
|
|
||||||
|
Livewire::test('pages::folders')
|
||||||
|
->call('toggleExpandFolder', $work->id)
|
||||||
|
->call('toggleExpandFolder', $work->id)
|
||||||
|
->assertSet('expandedFolderId', null)
|
||||||
|
->assertDontSee('Open task');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('only the clicked folder is expanded at a time', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
$personal = Folder::factory()->for($user)->create(['name' => 'Personal']);
|
||||||
|
Todo::factory()->recycle($user)->for($work)->create(['description' => 'Work task', 'due_date' => today()->addDays(2)]);
|
||||||
|
Todo::factory()->recycle($user)->for($personal)->create(['description' => 'Personal task', 'due_date' => today()->addDays(2)]);
|
||||||
|
|
||||||
|
Livewire::test('pages::folders')
|
||||||
|
->call('toggleExpandFolder', $work->id)
|
||||||
|
->call('toggleExpandFolder', $personal->id)
|
||||||
|
->assertSet('expandedFolderId', $personal->id)
|
||||||
|
->assertDontSee('Work task')
|
||||||
|
->assertSee('Personal task');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users can move a todo to another folder from the folders page', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
$personal = Folder::factory()->for($user)->create(['name' => 'Personal']);
|
||||||
|
$todo = Todo::factory()->recycle($user)->for($work)->create(['description' => 'Move me', 'due_date' => today()->addDay()]);
|
||||||
|
|
||||||
|
Livewire::test('pages::folders')
|
||||||
|
->call('toggleExpandFolder', $work->id)
|
||||||
|
->call('moveTodoToFolder', $todo->id, $personal->id);
|
||||||
|
|
||||||
|
expect($todo->fresh()->folder_id)->toBe($personal->id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users cannot move a todo to another user folder', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
$todo = Todo::factory()->recycle($user)->for($work)->create(['description' => 'Mine', 'due_date' => today()->addDay()]);
|
||||||
|
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$foreign = Folder::factory()->for($owner)->create(['name' => 'Foreign']);
|
||||||
|
|
||||||
|
$this->expectException(ModelNotFoundException::class);
|
||||||
|
|
||||||
|
Livewire::test('pages::folders')
|
||||||
|
->call('moveTodoToFolder', $todo->id, $foreign->id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users cannot move another user todo', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$ownerFolder = Folder::factory()->for($owner)->create(['name' => 'Owner Folder']);
|
||||||
|
$ownerTodo = Todo::factory()->recycle($owner)->for($ownerFolder)->create(['description' => 'Owner secret', 'due_date' => today()->addDay()]);
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
|
||||||
|
$this->expectException(ModelNotFoundException::class);
|
||||||
|
|
||||||
|
Livewire::test('pages::folders')
|
||||||
|
->call('moveTodoToFolder', $ownerTodo->id, $work->id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users can create a top-level folder with a color', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
Livewire::test('pages::folders')
|
||||||
|
->set('newFolderName', 'Work')
|
||||||
|
->set('newFolderColor', 'blue')
|
||||||
|
->call('createTopLevelFolder')
|
||||||
|
->assertSet('newFolderColor', '');
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('folders', [
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'name' => 'Work',
|
||||||
|
'color' => 'blue',
|
||||||
|
'parent_id' => null,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users can create a sub-folder with a color', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$work = Folder::factory()->for($user)->create(['name' => 'Work', 'color' => null]);
|
||||||
|
|
||||||
|
Livewire::test('pages::folders')
|
||||||
|
->call('startChildCreate', $work->id)
|
||||||
|
->set('newChildName', 'Acme Corp')
|
||||||
|
->set('newChildColor', 'emerald')
|
||||||
|
->call('createChildFolder')
|
||||||
|
->assertSet('newChildColor', '');
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('folders', [
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'name' => 'Acme Corp',
|
||||||
|
'color' => 'emerald',
|
||||||
|
'parent_id' => $work->id,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an invalid folder color is rejected', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
Livewire::test('pages::folders')
|
||||||
|
->set('newFolderName', 'Work')
|
||||||
|
->set('newFolderColor', 'neon')
|
||||||
|
->call('createTopLevelFolder')
|
||||||
|
->assertHasErrors('newFolderColor');
|
||||||
|
|
||||||
|
$this->assertDatabaseCount('folders', 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the folder color dot is shown on the folders page', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$work = Folder::factory()->for($user)->create(['name' => 'Work', 'color' => 'indigo']);
|
||||||
|
|
||||||
|
Livewire::test('pages::folders')
|
||||||
|
->assertSee("data-test=\"folder-dot-{$work->id}\"", false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the color picker offers the palette options', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
Livewire::test('pages::folders')
|
||||||
|
->assertSee('color-option-none', false)
|
||||||
|
->assertSee('color-option-blue', false)
|
||||||
|
->assertSee('color-option-pink', false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users can choose a color for an existing folder', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$work = Folder::factory()->for($user)->create(['name' => 'Work', 'color' => null]);
|
||||||
|
|
||||||
|
Livewire::test('pages::folders')
|
||||||
|
->call('startColorEdit', $work->id)
|
||||||
|
->assertSet('colorDraft', '')
|
||||||
|
->set('colorDraft', 'violet')
|
||||||
|
->call('saveFolderColor')
|
||||||
|
->assertSet('colorEditingFolderId', null);
|
||||||
|
|
||||||
|
expect($work->fresh()->color)->toBe('violet');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users can clear the color of an existing folder', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$work = Folder::factory()->for($user)->create(['name' => 'Work', 'color' => 'amber']);
|
||||||
|
|
||||||
|
Livewire::test('pages::folders')
|
||||||
|
->call('startColorEdit', $work->id)
|
||||||
|
->assertSet('colorDraft', 'amber')
|
||||||
|
->set('colorDraft', '')
|
||||||
|
->call('saveFolderColor');
|
||||||
|
|
||||||
|
expect($work->fresh()->color)->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an invalid color is rejected when editing a folder', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$work = Folder::factory()->for($user)->create(['name' => 'Work', 'color' => null]);
|
||||||
|
|
||||||
|
Livewire::test('pages::folders')
|
||||||
|
->call('startColorEdit', $work->id)
|
||||||
|
->set('colorDraft', 'neon')
|
||||||
|
->call('saveFolderColor')
|
||||||
|
->assertHasErrors('colorDraft');
|
||||||
|
|
||||||
|
expect($work->fresh()->color)->toBeNull();
|
||||||
|
});
|
||||||
|
|||||||
@@ -0,0 +1,251 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Folder;
|
||||||
|
use App\Models\Todo;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\TodoStatus;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
test('guests are redirected to the login page', function () {
|
||||||
|
$response = $this->get(route('todos'));
|
||||||
|
$response->assertRedirect(route('login'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('authenticated users can visit the todos page', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$response = $this->get(route('todos'));
|
||||||
|
$response->assertOk();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users only see their own todos', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$ownerFolder = Folder::factory()->for($owner)->create(['name' => 'Owner Folder']);
|
||||||
|
Todo::factory()->recycle($owner)->for($ownerFolder)->create(['description' => 'Owner secret', 'due_date' => today()->addDay()]);
|
||||||
|
|
||||||
|
$intruder = User::factory()->create();
|
||||||
|
$this->actingAs($intruder);
|
||||||
|
|
||||||
|
Livewire::test('pages::todos')
|
||||||
|
->assertDontSee('Owner secret')
|
||||||
|
->assertDontSee('Owner Folder');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the todos page loads a limited batch and has more to load', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
|
||||||
|
collect(range(1, 60))
|
||||||
|
->each(fn (int $n) => Todo::factory()->recycle($user)->for($folder)->create([
|
||||||
|
'description' => 'Todo '.$n,
|
||||||
|
'position' => $n - 1,
|
||||||
|
]));
|
||||||
|
|
||||||
|
Livewire::test('pages::todos')
|
||||||
|
->assertSet('limit', 50)
|
||||||
|
->assertSet('hasMore', true)
|
||||||
|
->assertSee('Todo 1')
|
||||||
|
->assertDontSee('Todo 51');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('loadMore appends the next batch until nothing remains', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
|
||||||
|
collect(range(1, 120))
|
||||||
|
->each(fn (int $n) => Todo::factory()->recycle($user)->for($folder)->create([
|
||||||
|
'description' => 'Todo '.$n,
|
||||||
|
'position' => $n - 1,
|
||||||
|
]));
|
||||||
|
|
||||||
|
Livewire::test('pages::todos')
|
||||||
|
->call('loadMore')
|
||||||
|
->assertSet('limit', 100)
|
||||||
|
->assertSee('Todo 51')
|
||||||
|
->assertDontSee('Todo 101')
|
||||||
|
->call('loadMore')
|
||||||
|
->assertSet('limit', 120)
|
||||||
|
->assertSee('Todo 120')
|
||||||
|
->assertSet('hasMore', false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('loadMore does not exceed the total number of todos', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
|
||||||
|
collect(range(1, 20))
|
||||||
|
->each(fn (int $n) => Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Todo '.$n]));
|
||||||
|
|
||||||
|
Livewire::test('pages::todos')
|
||||||
|
->call('loadMore')
|
||||||
|
->assertSet('limit', 20)
|
||||||
|
->assertSet('hasMore', false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('changing a filter resets the loaded batch', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Todo', 'due_date' => today()->addDay()]);
|
||||||
|
|
||||||
|
Livewire::test('pages::todos')
|
||||||
|
->call('loadMore')
|
||||||
|
->set('status', 'open')
|
||||||
|
->assertSet('limit', 50);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the todos page filters by status', function () {
|
||||||
|
$this->travelTo('2026-09-18 09:00:00');
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
|
||||||
|
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Open task', 'due_date' => today()->addDays(5)]);
|
||||||
|
Todo::factory()->recycle($user)->for($folder)->overdue()->create(['description' => 'Overdue task']);
|
||||||
|
Todo::factory()->recycle($user)->for($folder)->completed()->create(['description' => 'Done task']);
|
||||||
|
|
||||||
|
Livewire::test('pages::todos')
|
||||||
|
->set('status', 'overdue')
|
||||||
|
->assertDontSee('Open task')
|
||||||
|
->assertSee('Overdue task')
|
||||||
|
->assertDontSee('Done task');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users can create a todo from the todos page', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
|
||||||
|
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Older todo', 'position' => 2]);
|
||||||
|
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Middle todo', 'position' => 1]);
|
||||||
|
|
||||||
|
Livewire::test('pages::todos')
|
||||||
|
->call('openCreateForm')
|
||||||
|
->set('description', 'Write proposal')
|
||||||
|
->set('formFolderId', $folder->id)
|
||||||
|
->call('saveTodo')
|
||||||
|
->assertSet('showTodoForm', false);
|
||||||
|
|
||||||
|
$todo = Todo::where('description', 'Write proposal')->firstOrFail();
|
||||||
|
expect($todo->position)->toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users can mark a todo done and reopen it', function () {
|
||||||
|
$this->travelTo('2026-09-18 09:00:00');
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
$todo = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Buy milk', 'due_date' => today()->addDays(2)]);
|
||||||
|
|
||||||
|
Livewire::test('pages::todos')
|
||||||
|
->call('toggleComplete', $todo->id);
|
||||||
|
|
||||||
|
expect($todo->fresh()->completed_at)->not->toBeNull();
|
||||||
|
expect($todo->fresh()->status)->toBe(TodoStatus::Completed);
|
||||||
|
|
||||||
|
Livewire::test('pages::todos')
|
||||||
|
->call('toggleComplete', $todo->id);
|
||||||
|
|
||||||
|
expect($todo->fresh()->completed_at)->toBeNull();
|
||||||
|
expect($todo->fresh()->status)->toBe(TodoStatus::Open);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users can drag a todo to a new position without a pagination offset', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
|
||||||
|
$todos = collect(range(1, 60))
|
||||||
|
->map(fn (int $n) => Todo::factory()->recycle($user)->for($folder)->create([
|
||||||
|
'description' => 'Todo '.$n,
|
||||||
|
'position' => $n - 1,
|
||||||
|
]));
|
||||||
|
|
||||||
|
Livewire::test('pages::todos')
|
||||||
|
->call('loadMore')
|
||||||
|
->call('handleSort', $todos->get(30)->id, 0);
|
||||||
|
|
||||||
|
expect($todos->get(30)->fresh()->position)->toBe(0);
|
||||||
|
expect($todos->get(0)->fresh()->position)->toBe(1);
|
||||||
|
expect($todos->get(29)->fresh()->position)->toBe(30);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users can move a todo up in the priority order', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
|
||||||
|
$first = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'First todo', 'position' => 0]);
|
||||||
|
$second = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Second todo', 'position' => 1]);
|
||||||
|
$third = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Third todo', 'position' => 2]);
|
||||||
|
|
||||||
|
Livewire::test('pages::todos')
|
||||||
|
->call('moveTodo', $third->id, 'up');
|
||||||
|
|
||||||
|
expect($first->fresh()->position)->toBe(0);
|
||||||
|
expect($second->fresh()->position)->toBe(2);
|
||||||
|
expect($third->fresh()->position)->toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users can delete a todo', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
$todo = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Delete me']);
|
||||||
|
|
||||||
|
Livewire::test('pages::todos')
|
||||||
|
->call('confirmTodoDelete', $todo->id)
|
||||||
|
->call('deleteTodo');
|
||||||
|
|
||||||
|
expect(Todo::find($todo->id))->toBeNull();
|
||||||
|
$this->assertDatabaseCount('todos', 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users do not see another user todos', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$ownerFolder = Folder::factory()->for($owner)->create(['name' => 'Owner Folder']);
|
||||||
|
Todo::factory()->recycle($owner)->for($ownerFolder)->create(['description' => 'Owner secret', 'due_date' => today()->addDay()]);
|
||||||
|
|
||||||
|
$intruder = User::factory()->create();
|
||||||
|
$this->actingAs($intruder);
|
||||||
|
|
||||||
|
Livewire::test('pages::todos')
|
||||||
|
->assertDontSee('Owner secret');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('completed todos show their completion date and days to completion', function () {
|
||||||
|
$this->travelTo('2026-09-10 09:00:00');
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||||
|
$todo = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Shipped feature']);
|
||||||
|
|
||||||
|
$this->travelTo('2026-09-18 09:00:00');
|
||||||
|
|
||||||
|
Livewire::test('pages::todos')
|
||||||
|
->call('toggleComplete', $todo->id);
|
||||||
|
|
||||||
|
$todo->refresh();
|
||||||
|
|
||||||
|
Livewire::test('pages::todos')
|
||||||
|
->assertSee('Sep 18, 2026')
|
||||||
|
->assertSee('Completed in 8 days');
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user