authentikate/app/Livewire/AppInfoModal.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

58 lines
1.2 KiB
PHP

<?php
namespace App\Livewire;
use App\Models\Application;
use Flux\Flux;
use Livewire\Attributes\Computed;
use Livewire\Attributes\On;
use Livewire\Component;
class AppInfoModal extends Component
{
public Application $app;
public ?string $name = '';
public string $query = '';
public ?string $icon = null;
public function mount()
{
$this->loadApp(4);
}
public function updated($prop)
{
if ($prop == "query") {
if (empty($this->query)) {
return null;
}
$s = str($this->query)->kebab()->toString();
$icon = "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/{$s}.webp";
$this->icon = $icon;
}
}
#[On('appinfo')]
public function loadApp($id)
{
$this->app = Application::find($id);
$this->name = $this->app->name;
$this->icon = $this->app->getIconUrl();
}
public function save()
{
$this->app->update([
'name' => $this->name,
'icon' => $this->icon,
]);
$this->dispatch('app-updated', ['id' => $this->app->id]);
}
public function render()
{
return view('livewire.app-info-modal');
}
}