diff --git a/app/Livewire/Dashboard/DashboardConverter.php b/app/Livewire/Dashboard/DashboardConverter.php new file mode 100644 index 0000000..16782b3 --- /dev/null +++ b/app/Livewire/Dashboard/DashboardConverter.php @@ -0,0 +1,89 @@ +resetErrorBag(); + $this->uploadError = null; + + $this->validate([ + 'upload' => [ + 'required', + 'file', + 'max:'.UploadedFileRules::MAX_FILE_KILOBYTES, + ], + ], [ + 'upload.max' => 'This file is too large. Max upload size is '.(UploadedFileRules::MAX_FILE_KILOBYTES / 1024).' MB.', + ]); + + try { + $fileRecord = $storeUploadedFile->handle( + user: auth()->user(), + file: $this->upload, + ); + } catch (UnsupportedFileFormatException) { + $this->uploadError = 'This file type is not supported in beta. Upload PNG, JPG, WEBP or PDF.'; + $this->step = 'upload'; + + return; + } catch (FileStorageException) { + $this->uploadError = 'We could not store your file. Please try again.'; + $this->step = 'upload'; + + return; + } + + $this->currentFileId = $fileRecord->id; + $this->step = 'format'; + } + + public function replaceFile(): void + { + $this->resetCurrentUpload(); + } + + public function removeFile(): void + { + $this->resetCurrentUpload(); + } + + private function resetCurrentUpload(): void + { + $this->reset('upload', 'currentFileId', 'uploadError'); + $this->resetErrorBag(); + $this->step = 'upload'; + } + + public function getCurrentFileProperty(): ?FileRecord + { + return $this->currentFileId + ? FileRecord::query()->where('user_id', auth()->id())->find($this->currentFileId) + : null; + } + + public function render() + { + return view('livewire.dashboard.dashboard-converter'); + } +} diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 4b88af4..3cca978 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -6,21 +6,7 @@
Drop your file here
+PNG, JPG, WEBP and PDF supported in beta
+Your files stay private. We delete them after conversion.
+ + @error('upload') +{{ $message }}
+ @enderror + + @if ($uploadError) +{{ $uploadError }}
+ @endif +{{ $file->original_name }}
++ {{ strtoupper($file->extension) }} · + {{ number_format($file->size_bytes / 1024, 1) }} KB + @php($meta = $file->metadata_json ?? []) + @if (isset($meta['width'], $meta['height'])) + · {{ $meta['width'] }}×{{ $meta['height'] }} + @endif +
+Choose output format
+Target format selection will be added in Phase 7.
+