authentikate/app/Livewire/AppContainer.php
Javier Feliz 9746756a44
Some checks failed
linter / quality (push) Successful in 3m5s
tests / ci (push) Failing after 7m35s
App icons and editing
2025-07-27 16:57:02 -04:00

59 lines
1.3 KiB
PHP

<?php
namespace App\Livewire;
use App\Models\Application;
use Flux\Flux;
use Illuminate\Database\Eloquent\Collection;
use Livewire\Attributes\On;
use Livewire\Component;
class AppContainer extends Component
{
public Collection $apps;
public ?Application $confirmDeleteApp;
public function mount()
{
$this->loadApps();
}
public function loadApps()
{
$this->apps = Application::orderBy('id')->get();
}
#[On('app-updated')]
public function handleAppUpdated($id)
{
$new = Application::find($id);
$this->apps = $this->apps->map(fn($app) => $app->id == $id ? $new : $app);
}
public function confirmDelete($id)
{
$this->confirmDeleteApp = $this->apps->where('id', $id)->first();
Flux::modal('delete-app-confirm')->show();
}
public function deleteApp()
{
$this->confirmDeleteApp->delete();
$deletedId = $this->confirmDeleteApp->id;
$this->confirmDeleteApp = null;
$this->apps = $this->apps->filter(fn($app) => $app->id != $deletedId);
Flux::modal('delete-app-confirm')->close();
}
public function cancelDelete()
{
$this->confirmDeleteApp = null;
Flux::modal('delete-app-confirm')->close();
}
public function render()
{
return view('livewire.app-container');
}
}