Skip to content

Commit

Permalink
update moderation options control
Browse files Browse the repository at this point in the history
to only take in data values
  • Loading branch information
waffle-lord committed Dec 9, 2024
1 parent 570742d commit 021e76c
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 16 deletions.
52 changes: 48 additions & 4 deletions app/Livewire/Mod/ModerationActionButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,17 +45,57 @@ public function runActionEvent(): void
#[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()');
Expand Down
9 changes: 7 additions & 2 deletions app/Livewire/Mod/ModerationOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 8 additions & 8 deletions resources/views/livewire/mod/moderation-options.blade.php
Original file line number Diff line number Diff line change
@@ -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">
Expand All @@ -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" />
Expand All @@ -26,7 +26,7 @@
</svg>
@endif
</span>
{{$this->moderatedObject->disabled ? __('Enable') : __('Disable') }}
{{$this->disabled ? __('Enable') : __('Disable') }}
</div>
</button>
</div>
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions resources/views/mod/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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">
Expand Down

0 comments on commit 021e76c

Please sign in to comment.