2025-09-02 11:25:28 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Livewire\Pages;
|
|
|
|
|
|
|
|
use Livewire\Component;
|
|
|
|
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
|
|
|
use App\Models\RoomSession;
|
|
|
|
use App\Models\OrderedSong;
|
|
|
|
|
|
|
|
class OrderedSongList extends Component
|
|
|
|
{
|
2025-09-04 18:12:15 +08:00
|
|
|
public $roomSession;
|
2025-09-02 11:25:28 +08:00
|
|
|
|
|
|
|
public EloquentCollection $playing ;
|
|
|
|
public EloquentCollection $nextSong ;
|
|
|
|
public EloquentCollection $finished ;
|
|
|
|
|
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
|
|
|
$this->playing = new EloquentCollection();
|
|
|
|
$this->nextSong = new EloquentCollection();
|
|
|
|
$this->finished = new EloquentCollection();
|
2025-09-04 18:12:15 +08:00
|
|
|
$this->roomSession = request()->roomSession;
|
|
|
|
$this->refreshSongs();
|
2025-09-02 11:25:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function refreshSongs()
|
|
|
|
{
|
2025-09-04 18:12:15 +08:00
|
|
|
$dbSession = $this->roomSession->refreshValid();
|
|
|
|
if (!$dbSession) {
|
|
|
|
session()->forget('room_code');
|
|
|
|
return $this->redirect(route('welcome'), navigate: true);
|
2025-09-02 11:25:28 +08:00
|
|
|
}
|
2025-09-04 18:12:15 +08:00
|
|
|
$this->playing = OrderedSong::forSession($this->roomSession->id)->playing()->get();
|
|
|
|
$this->nextSong = OrderedSong::forSession($this->roomSession->id)->nextSong()->get();
|
|
|
|
$this->finished = OrderedSong::forSession($this->roomSession->id)->finished()->get();
|
2025-09-02 11:25:28 +08:00
|
|
|
}
|
2025-09-04 18:12:15 +08:00
|
|
|
|
2025-09-02 11:25:28 +08:00
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.pages.ordered-song-list', [
|
|
|
|
'playing' => $this->playing,
|
|
|
|
'nextSong' => $this->nextSong,
|
|
|
|
'finished' => $this->finished,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|