This commit is contained in:
2026-04-18 14:18:52 +02:00
parent 5b4d3d435e
commit f3e5100d5d
126 changed files with 743 additions and 795 deletions

View File

@@ -1,20 +1,16 @@
<?php
namespace App\Livewire;
use App\Models\User;
use App\Models\Episode;
use App\Models\User;
use App\Notifications\CommentNotification;
use Livewire\Component;
use Illuminate\Support\Str;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Str;
use Livewire\Component;
use Maize\Markable\Models\Like;
class Comment extends Component
@@ -30,21 +26,21 @@ class Comment extends Component
public $liked = false;
public $replyState = [
'body' => ''
'body' => '',
];
public $isEditing = false;
public $editState = [
'body' => ''
'body' => '',
];
protected $listeners = [
'refresh' => '$refresh'
'refresh' => '$refresh',
];
protected $validationAttributes = [
'replyState.body' => 'reply'
'replyState.body' => 'reply',
];
public function updatedIsEditing($isEditing)
@@ -54,7 +50,7 @@ class Comment extends Component
}
$this->editState = [
'body' => $this->comment->body
'body' => $this->comment->body,
];
}
@@ -73,13 +69,14 @@ class Comment extends Component
$this->comment->delete();
$this->dispatch('refresh');
$this->dispatch('refresh');
}
public function postReply()
{
if (!($this->comment->depth() < 2)) {
$this->addError('replyState.body', "Too many sub comments.");
if (! ($this->comment->depth() < 2)) {
$this->addError('replyState.body', 'Too many sub comments.');
return;
}
@@ -91,13 +88,14 @@ class Comment extends Component
$seconds = RateLimiter::availableIn($rateLimitKey);
$this->addError('replyState.body', "Too many comments. Try again in {$seconds} seconds.");
return;
}
RateLimiter::hit($rateLimitKey, $rateLimitMinutes);
$this->validate([
'replyState.body' => 'required'
'replyState.body' => 'required',
]);
$reply = $this->comment->children()->make($this->replyState);
@@ -110,25 +108,25 @@ class Comment extends Component
if ($reply->commentable_type == Episode::class && $user->id !== $reply->parent->user->id) {
$episode = Episode::where('id', $reply->commentable_id)
->firstOrFail();
$url = route('hentai.index', ['title' => $episode->slug]);
$reply->parent->user->notify(
new CommentNotification(
"{$user->name} replied to your comment.",
Str::limit($reply->body, 50),
"{$user->name} replied to your comment.",
Str::limit($reply->body, 50),
"{$url}#comment-{$reply->id}"
)
);
}
$this->replyState = [
'body' => ''
'body' => '',
];
$this->isReplying = false;
$this->dispatch('refresh')->self();
$this->dispatch('refresh')->self();
}
public function like()
@@ -144,6 +142,7 @@ class Comment extends Component
if ($this->liked) {
$this->liked = false;
$this->likeCount--;
return;
}
@@ -163,4 +162,4 @@ class Comment extends Component
{
return view('livewire.comment');
}
}
}