Replace controller-driven Blade views with full-page Livewire index/show/create flows so Flux tables, toasts, and uploads work natively.
91 lines
2.3 KiB
PHP
91 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Recordings;
|
|
|
|
use App\Models\Recording;
|
|
use Flux\Flux;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\Title;
|
|
use Livewire\Attributes\Url;
|
|
use Livewire\Component;
|
|
use Livewire\WithPagination;
|
|
|
|
#[Layout('layouts.app')]
|
|
#[Title('Recordings')]
|
|
class Index extends Component
|
|
{
|
|
use WithPagination;
|
|
|
|
#[Url(as: 'q', history: true)]
|
|
public string $search = '';
|
|
|
|
public function updatedSearch(): void
|
|
{
|
|
$this->resetPage();
|
|
}
|
|
|
|
public function queuePending(): void
|
|
{
|
|
$queued = 0;
|
|
|
|
Auth::user()->recordings()
|
|
->whereIn('transcription_status', ['pending', 'failed', 'cancelled'])
|
|
->orderBy('id')
|
|
->each(function (Recording $recording) use (&$queued): void {
|
|
if ($recording->hasActiveTranscriptionJob()) {
|
|
return;
|
|
}
|
|
|
|
$recording->queueLocalTranscription();
|
|
$queued++;
|
|
});
|
|
|
|
if ($queued === 0) {
|
|
Flux::toast(text: 'No recordings need transcription right now.', variant: 'danger');
|
|
|
|
return;
|
|
}
|
|
|
|
Flux::toast(
|
|
text: $queued === 1
|
|
? 'Queued 1 recording for transcription.'
|
|
: "Queued {$queued} recordings for transcription.",
|
|
variant: 'success',
|
|
);
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
$user = Auth::user();
|
|
|
|
$user->recordings()
|
|
->whereIn('transcription_status', ['pending', 'processing'])
|
|
->orderBy('id')
|
|
->each(fn (Recording $recording) => $recording->recoverOrphanedTranscription());
|
|
|
|
$query = $user->recordings()->latest();
|
|
|
|
$search = trim($this->search);
|
|
|
|
if ($search !== '') {
|
|
$query->search($search);
|
|
}
|
|
|
|
$recordings = $query->paginate(20);
|
|
|
|
$pendingCount = $user->recordings()
|
|
->whereIn('transcription_status', ['pending', 'failed', 'cancelled'])
|
|
->get()
|
|
->filter(fn (Recording $recording) => ! $recording->hasActiveTranscriptionJob())
|
|
->count();
|
|
|
|
return view('livewire.recordings.index', [
|
|
'recordings' => $recordings,
|
|
'search' => $search,
|
|
'pendingCount' => $pendingCount,
|
|
]);
|
|
}
|
|
}
|