mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-02-22 12:49:43 -06:00
fix: forum post likes
This commit is contained in:
@@ -23,10 +23,13 @@ class DislikeButton extends Component
|
||||
|
||||
public ?\Illuminate\Contracts\Auth\Authenticatable $user = null;
|
||||
|
||||
final public function mount(Post $post): void
|
||||
public int $dislikesCount;
|
||||
|
||||
final public function mount(Post $post, int $dislikesCount): void
|
||||
{
|
||||
$this->user = auth()->user();
|
||||
$this->post = $post;
|
||||
$this->dislikesCount = $dislikesCount;
|
||||
}
|
||||
|
||||
final public function store(): void
|
||||
@@ -50,6 +53,8 @@ class DislikeButton extends Component
|
||||
$new->dislike = 1;
|
||||
$new->save();
|
||||
|
||||
$this->dislikesCount += 1;
|
||||
|
||||
$this->dispatchBrowserEvent('success', ['type' => 'success', 'message' => 'Your Dislike Was Successfully Applied!']);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,10 +23,13 @@ class LikeButton extends Component
|
||||
|
||||
public ?\Illuminate\Contracts\Auth\Authenticatable $user = null;
|
||||
|
||||
final public function mount(Post $post): void
|
||||
public int $likesCount;
|
||||
|
||||
final public function mount(Post $post, int $likesCount): void
|
||||
{
|
||||
$this->user = auth()->user();
|
||||
$this->post = $post;
|
||||
$this->likesCount = $likesCount;
|
||||
}
|
||||
|
||||
final public function store(): void
|
||||
@@ -50,6 +53,8 @@ class LikeButton extends Component
|
||||
$new->like = 1;
|
||||
$new->save();
|
||||
|
||||
$this->likesCount += 1;
|
||||
|
||||
$this->dispatchBrowserEvent('success', ['type' => 'success', 'message' => 'Your Like Was Successfully Applied!']);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,10 +42,7 @@ class TopicPostSearch extends Component
|
||||
return Post::query()
|
||||
->select('posts.*')
|
||||
->with('user', 'user.group', 'user.topics', 'user.posts', 'topic', 'tips')
|
||||
->withCount([
|
||||
'likes' => fn ($query) => $query->where('like', '=', 1),
|
||||
'likes as dislike_count' => fn ($query) => $query->where('dislike', '=', 1),
|
||||
])
|
||||
->withCount(['likes', 'dislikes'])
|
||||
->withSum('tips', 'cost')
|
||||
->where('topic_id', '=', $this->topic->id)
|
||||
->join('topics', 'topics.id', '=', 'posts.topic_id')
|
||||
|
||||
@@ -55,10 +55,10 @@
|
||||
</form>
|
||||
</li>
|
||||
<li class="post__toolbar-item">
|
||||
@livewire('like-button', ['post' => $post], key('like-'.$post->id))
|
||||
@livewire('like-button', ['post' => $post, 'likesCount' => $post->likes_count], key('like-'.$post->id))
|
||||
</li>
|
||||
<li class="post__toolbar-item">
|
||||
@livewire('dislike-button', ['post' => $post], key('dislike-'.$post->id))
|
||||
@livewire('dislike-button', ['post' => $post, 'dislikesCount' => $post->dislikes_count], key('dislike-'.$post->id))
|
||||
</li>
|
||||
<li class="post__toolbar-item">
|
||||
<a
|
||||
|
||||
@@ -8,5 +8,5 @@
|
||||
@else
|
||||
<i class="votes__dislike-icon {{ config('other.font-awesome') }} fa-thumbs-down"></i>
|
||||
@endif
|
||||
<span class="votes__dislike-count">{{ $post->dislike_count }}</span>
|
||||
<span class="votes__dislike-count">{{ $dislikesCount }}</span>
|
||||
</button>
|
||||
|
||||
@@ -8,5 +8,5 @@
|
||||
@else
|
||||
<i class="votes__like-icon {{ config('other.font-awesome') }} fa-thumbs-up"></i>
|
||||
@endif
|
||||
<span class="votes__like-count">{{ $post->likes_count }}</span>
|
||||
<span class="votes__like-count">{{ $likesCount }}</span>
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user