2024-12-02 16:20:16 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Livewire\Mod;
|
|
|
|
|
|
|
|
use App\Models\ModeratedModel;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class ModerationActionButton extends Component
|
|
|
|
{
|
|
|
|
public ModeratedModel $moderatedObject;
|
|
|
|
|
|
|
|
public string $actionType;
|
|
|
|
|
|
|
|
public bool $allowActions = false;
|
|
|
|
|
|
|
|
public bool $isRunning = false;
|
|
|
|
|
|
|
|
protected $listeners = ['refreshComponent' => '$refresh'];
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
$this->allowActions = ! $this->isRunning;
|
|
|
|
|
|
|
|
return view('livewire.mod.moderation-action-button');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function runActionEvent(): void
|
|
|
|
{
|
|
|
|
$this->isRunning = true;
|
2024-12-02 20:16:47 -05:00
|
|
|
$this->js('setTimeout(function() { $wire.invokeAction(); }, 500)');
|
2024-12-02 16:20:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function invokeAction(): void
|
|
|
|
{
|
|
|
|
switch ($this->actionType) {
|
|
|
|
case 'delete':
|
|
|
|
|
|
|
|
$this->moderatedObject->delete();
|
2024-12-02 20:16:47 -05:00
|
|
|
break;
|
2024-12-02 16:20:16 -05:00
|
|
|
|
|
|
|
case 'enable':
|
|
|
|
case 'disable':
|
|
|
|
|
|
|
|
$this->moderatedObject->toggleDisabled();
|
2024-12-02 20:16:47 -05:00
|
|
|
break;
|
2024-12-02 16:20:16 -05:00
|
|
|
}
|
2024-12-02 20:16:47 -05:00
|
|
|
|
|
|
|
$this->js('window.location.reload()');
|
2024-12-02 16:20:16 -05:00
|
|
|
}
|
|
|
|
}
|