mirror of
https://github.com/sp-tarkov/forge.git
synced 2025-02-13 04:30:41 -05:00
update moderation options control
to only take in data values
This commit is contained in:
parent
570742dcba
commit
021e76c2c0
@ -2,18 +2,22 @@
|
||||
|
||||
namespace App\Livewire\Mod;
|
||||
|
||||
use App\Models\ModeratedModel;
|
||||
use App\Models\Mod;
|
||||
use App\Models\ModVersion;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Livewire\Attributes\On;
|
||||
use Livewire\Component;
|
||||
|
||||
class ModerationActionButton extends Component
|
||||
{
|
||||
public ModeratedModel $moderatedObject;
|
||||
public ?string $moderatedObjectId = null;
|
||||
|
||||
public string $guid = '';
|
||||
|
||||
public string $actionType;
|
||||
|
||||
public string $targetType = '';
|
||||
|
||||
public bool $allowActions = false;
|
||||
|
||||
public bool $isRunning = false;
|
||||
@ -41,17 +45,57 @@ class ModerationActionButton extends Component
|
||||
#[On('startAction.{guid}')]
|
||||
public function invokeAction(): void
|
||||
{
|
||||
if ($this->moderatedObjectId == null || $this->moderatedObjectId == '') {
|
||||
Log::info('Failed: no ID specified.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Log::info("Object ID: $this->moderatedObjectId");
|
||||
|
||||
if ($this->targetType !== 'mod' && $this->targetType !== 'modVersion') {
|
||||
Log::info('Failed: invalid target type.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($this->targetType) {
|
||||
case 'mod':
|
||||
$moderatedObject = Mod::where('id', '=', $this->moderatedObjectId)->first();
|
||||
break;
|
||||
|
||||
case 'modVersion':
|
||||
$moderatedObject = ModVersion::where('id', '=', $this->moderatedObjectId)->first();
|
||||
break;
|
||||
|
||||
default:
|
||||
Log::info('Failed: invalid target type.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($moderatedObject == null) {
|
||||
Log::info('Failed: moderated object is null');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($this->actionType) {
|
||||
case 'delete':
|
||||
|
||||
$this->moderatedObject->delete();
|
||||
$moderatedObject->delete();
|
||||
break;
|
||||
|
||||
case 'enable':
|
||||
case 'disable':
|
||||
|
||||
$this->moderatedObject->toggleDisabled();
|
||||
$moderatedObject->toggleDisabled();
|
||||
break;
|
||||
|
||||
default:
|
||||
Log::info('Failed: invalid action type.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->js('window.location.reload()');
|
||||
|
@ -2,12 +2,17 @@
|
||||
|
||||
namespace App\Livewire\Mod;
|
||||
|
||||
use App\Models\ModeratedModel;
|
||||
use Livewire\Component;
|
||||
|
||||
class ModerationOptions extends Component
|
||||
{
|
||||
public ModeratedModel $moderatedObject;
|
||||
public string $objectId;
|
||||
|
||||
public string $targetType;
|
||||
|
||||
public bool $disabled;
|
||||
|
||||
public string $displayName;
|
||||
|
||||
public bool $showDeleteDialog = false;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div class="text-blue-600">
|
||||
<div>
|
||||
<x-dropdown alignment="right" contentClasses="py-1 rounded-full bg-gray-200 dark:bg-gray-800">
|
||||
<x-slot name="trigger">
|
||||
<button class="relative text-blue-400 dark:text-blue-500 hover:text-blue-600 dark:hover:text-blue-700">
|
||||
@ -14,7 +14,7 @@
|
||||
<button wire:click.prevent="confirmDisable" class="p-2 h-full w-full text-blue-500 dark:text-blue-500 bg-gray-200 dark:bg-gray-800 hover:text-blue-400 dark:hover:text-blue-400">
|
||||
<div class="flex">
|
||||
<span class="pr-2">
|
||||
@if ($this->moderatedObject->disabled)
|
||||
@if ($this->disabled)
|
||||
{{-- Icon (circle with checkmark)--}}
|
||||
<svg width="24" height="24" fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M12 2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2Zm3.22 6.97-4.47 4.47-1.97-1.97a.75.75 0 0 0-1.06 1.06l2.5 2.5a.75.75 0 0 0 1.06 0l5-5a.75.75 0 1 0-1.06-1.06Z" />
|
||||
@ -26,7 +26,7 @@
|
||||
</svg>
|
||||
@endif
|
||||
</span>
|
||||
{{$this->moderatedObject->disabled ? __('Enable') : __('Disable') }}
|
||||
{{$this->disabled ? __('Enable') : __('Disable') }}
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
@ -52,13 +52,13 @@
|
||||
@push('modals')
|
||||
<x-dialog-modal wire:model="showDisableDialog">
|
||||
<x-slot name="title">
|
||||
<h2 class="text-2xl">{{__('Confirm')}} {{__($this->moderatedObject->disabled ? 'Enable' : 'Disable')}}</h2>
|
||||
<h2 class="text-2xl">{{__('Confirm')}} {{__($this->disabled ? 'Enable' : 'Disable')}}</h2>
|
||||
</x-slot>
|
||||
<x-slot name="content">
|
||||
<p>Are you sure you want to {{__($this->moderatedObject->disabled ? 'enable' : 'disable')}} '{{$this->moderatedObject->getFriendlyName()}}'?</p>
|
||||
<p>Are you sure you want to {{__($this->disabled ? 'enable' : 'disable')}} '{{$this->displayName}}'?</p>
|
||||
</x-slot>
|
||||
<x-slot name="footer">
|
||||
<livewire:mod.moderation-action-button actionType="{{ $this->moderatedObject->disabled ? 'enable' : 'disable' }}" :moderatedObject="$moderatedObject" />
|
||||
<livewire:mod.moderation-action-button actionType="{{ $this->disabled ? 'enable' : 'disable' }}" :targetType="$targetType" :moderatedObjectId="$objectId" />
|
||||
</x-slot>
|
||||
</x-dialog-modal>
|
||||
@endpush
|
||||
@ -69,10 +69,10 @@
|
||||
<h2 class="text-2xl">{{ __('Confirm') }} {{ __('Delete') }}</h2>
|
||||
</x-slot>
|
||||
<x-slot name="content">
|
||||
<p>Are you sure you want to {{__('delete')}} '{{$this->moderatedObject->getFriendlyName()}}'?</p>
|
||||
<p>Are you sure you want to {{__('delete')}} '{{$this->displayName}}'?</p>
|
||||
</x-slot>
|
||||
<x-slot name="footer">
|
||||
<livewire:mod.moderation-action-button actionType='delete' :moderatedObject="$moderatedObject" />
|
||||
<livewire:mod.moderation-action-button actionType='delete' :targetType="$targetType" :moderatedObjectId="$objectId" />
|
||||
</x-slot>
|
||||
</x-dialog-modal>
|
||||
@endpush
|
||||
|
@ -13,7 +13,7 @@
|
||||
<div class="relative p-4 sm:p-6 text-center sm:text-left bg-white dark:bg-gray-950 rounded-xl shadow-md dark:shadow-gray-950 drop-shadow-2xl">
|
||||
@if (auth()->check() && auth()->user()->isModOrAdmin())
|
||||
<div class="absolute top-0 right-0 z-50 m-2">
|
||||
<livewire:mod.moderation-options :moderatedObject="$mod" />
|
||||
<livewire:mod.moderation-options :objectId="$mod->id" targetType="mod" :displayName="$mod->name" :disabled="$mod->disabled" />
|
||||
</div>
|
||||
@endif
|
||||
@if ($mod->featured && !$mod->disabled)
|
||||
@ -112,7 +112,7 @@
|
||||
<div class="pb-6 border-b-2 border-gray-200 dark:border-gray-800">
|
||||
@if (auth()->check() && auth()->user()->isModOrAdmin())
|
||||
<div class="absolute top-0 right-0 z-50 m-2">
|
||||
<livewire:mod.moderation-options :moderatedObject="$version" />
|
||||
<livewire:mod.moderation-options :objectId="$version->id" targetType="modVersion" :displayName="$version->version" :disabled="$version->disabled" />
|
||||
</div>
|
||||
@endif
|
||||
<div class="flex items-center justify-between">
|
||||
|
Loading…
x
Reference in New Issue
Block a user