Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions app/Livewire/Dashboard/DashboardConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,31 @@ public function selectTargetFormat(string $targetFormat): void
$this->step = 'settings';
}

public function backToUploadSummary(): void
{
if ($this->currentFile === null) {
$this->currentFileId = null;
$this->step = 'upload';

return;
}

$this->resetTargetSelection();
$this->step = 'upload';
}

public function backToFormatStep(): void
{
if ($this->currentFile === null) {
$this->currentFileId = null;
$this->step = 'upload';

return;
}

$this->step = 'format';
}

public function replaceFile(): void
{
$this->resetCurrentUpload();
Expand Down
35 changes: 34 additions & 1 deletion resources/views/livewire/dashboard/dashboard-converter.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
<div>
<x-card variant="elevated">
<x-stepper :steps="['File', 'Format', 'Settings', 'Convert']" :active="$step === 'upload' ? 'File' : 'Format'" class="mb-6" />
@if ($step === 'upload')
@if ($step === 'upload' && $this->currentFile)
@php($file = $this->currentFile)
<div class="flex flex-col gap-4">
<div class="flex items-center justify-between gap-4 rounded-[var(--ca-radius-md)] border border-[var(--ca-border)] bg-white p-4">
<div class="flex items-center gap-3">
<x-file-icon :format="$file->extension" />
<div class="flex flex-col">
<p class="text-sm font-semibold text-[var(--ca-text)]">{{ $file->original_name }}</p>
<p class="text-xs text-[var(--ca-muted)]">
{{ strtoupper($file->extension) }} ·
{{ number_format($file->size_bytes / 1024, 1) }} KB
</p>
</div>
</div>

<div class="flex items-center gap-2">
<x-button variant="secondary" size="sm" wire:click="replaceFile">Replace</x-button>
<x-button variant="ghost" size="sm" wire:click="removeFile">Remove</x-button>
</div>
</div>

<div class="flex justify-end">
<x-button variant="primary" size="sm" wire:click="goToFormatStep">Choose format</x-button>
</div>
</div>
@elseif ($step === 'upload')
<div
x-data="{ isDragging: false }"
x-on:dragover.prevent="isDragging = true"
Expand Down Expand Up @@ -44,6 +69,10 @@ class="flex flex-col items-center justify-center gap-4 rounded-[var(--ca-radius-
@if ($step === 'format' && $this->currentFile)
@php($file = $this->currentFile)
<div class="flex flex-col gap-4">
<div>
<x-button variant="ghost" size="sm" wire:click="backToUploadSummary">← Back</x-button>
</div>

<div class="flex items-center justify-between gap-4 rounded-[var(--ca-radius-md)] border border-[var(--ca-border)] bg-white p-4">
<div class="flex items-center gap-3">
<x-file-icon :format="$file->extension" />
Expand Down Expand Up @@ -108,6 +137,10 @@ class="flex items-start gap-3 rounded-[var(--ca-radius-md)] border border-[var(-
@if ($step === 'settings' && $this->currentFile)
@php($file = $this->currentFile)
<div class="flex flex-col gap-4">
<div>
<x-button variant="ghost" size="sm" wire:click="backToFormatStep">← Back</x-button>
</div>

<div class="rounded-[var(--ca-radius-md)] border border-dashed border-[var(--ca-border)] bg-[var(--ca-surface-muted)]/40 px-6 py-8 text-center">
<p class="text-base font-semibold text-[var(--ca-text)]">
Settings for {{ strtoupper($file->extension) }} to {{ strtoupper($selectedTargetFormat) }}
Expand Down
68 changes: 68 additions & 0 deletions tests/Feature/Livewire/DashboardConverterNavigationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

use App\Livewire\Dashboard\DashboardConverter;
use App\Models\FileRecord;
use App\Models\User;
use Livewire\Livewire;

it('goes back from the format step to the uploaded file summary without removing the file', function () {
$user = User::factory()->create();
$file = FileRecord::factory()->for($user)->create([
'extension' => 'png',
'original_name' => 'image.png',
]);

Livewire::actingAs($user)
->test(DashboardConverter::class)
->set('currentFileId', $file->id)
->call('goToFormatStep')
->call('backToUploadSummary')
->assertSet('step', 'upload')
->assertSet('currentFileId', $file->id)
->assertSee('image.png');

expect(FileRecord::query()->whereKey($file->id)->exists())->toBeTrue();
});

it('resets the selected target format when going back to the upload summary', function () {
$user = User::factory()->create();
$file = FileRecord::factory()->for($user)->create(['extension' => 'png']);

Livewire::actingAs($user)
->test(DashboardConverter::class)
->set('currentFileId', $file->id)
->call('goToFormatStep')
->call('selectTargetFormat', 'jpg')
->assertSet('step', 'settings')
->call('backToUploadSummary')
->assertSet('step', 'upload')
->assertSet('selectedTargetFormat', null);
});

it('goes back from the settings placeholder to the format step preserving the file', function () {
$user = User::factory()->create();
$file = FileRecord::factory()->for($user)->create(['extension' => 'png']);

Livewire::actingAs($user)
->test(DashboardConverter::class)
->set('currentFileId', $file->id)
->call('goToFormatStep')
->call('selectTargetFormat', 'jpg')
->assertSet('step', 'settings')
->call('backToFormatStep')
->assertSet('step', 'format')
->assertSet('currentFileId', $file->id)
->assertSee('Convert PNG to');
});

it('returns to upload when navigating back with a missing file', function () {
$user = User::factory()->create();

Livewire::actingAs($user)
->test(DashboardConverter::class)
->set('currentFileId', 999999)
->set('step', 'format')
->call('backToUploadSummary')
->assertSet('step', 'upload')
->assertSet('currentFileId', null);
});