Skip to content

Commit 462632c

Browse files
committed
Add likes to view
1 parent 4d4bed1 commit 462632c

File tree

2 files changed

+55
-32
lines changed

2 files changed

+55
-32
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<div class="thread-info-likes">
2+
@if (Auth::guest())
3+
@if($likeable->likes_count)
4+
<div class="text-gray-600 px-4 py-2 border-r inline-block">
5+
<span class="text-2xl mr-1">👍</span>
6+
{{ $likeable->likes_count }}
7+
</div>
8+
@endif
9+
@else
10+
@if (! $likeable->isLikedBy(auth()->user()))
11+
<form action="{{ route(...$like) }}" method="post">
12+
@csrf
13+
@method('put')
14+
<button type="submit" class="text-green-dark px-4 py-2 border-r">
15+
<span class="text-2xl mr-1">👍</span>
16+
{{ $likeable->likes_count }}
17+
</button>
18+
</form>
19+
@else
20+
<form action="{{ route(...$unlike) }}" method="post">
21+
@csrf
22+
@method('delete')
23+
<button type="submit" class="text-green-dark px-4 py-2 border-r">
24+
<span class="text-2xl mr-1">👍</span>
25+
{{ $likeable->likes_count }}
26+
</button>
27+
</form>
28+
@endif
29+
@endif
30+
</div>

resources/views/forum/threads/show.blade.php

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@
1818
<div class="container mx-auto px-4 pt-4">
1919
<div class="flex flex-wrap">
2020
<div class="w-full md:w-3/4 md:pr-3">
21-
<div class="reply bg-white p-4 border rounded">
22-
<div>
23-
<reply :content="{{ json_encode(md_to_html($thread->body())) }}"/>
24-
</div>
25-
26-
<div class="flex flex-col md:flex-row md:items-center text-sm pt-5 border-t mt-4">
21+
<div class="reply bg-white border rounded">
22+
<div class="flex flex-col md:flex-row md:items-center text-sm p-4 border-b">
2723
<div class="flex mb-4 md:mb-0">
2824
@include('forum.threads.info.avatar', ['user' => $thread->author()])
2925

@@ -35,7 +31,16 @@
3531

3632
@include('forum.threads.info.tags')
3733
</div>
38-
34+
<div class="p-4">
35+
<reply :content="{{ json_encode(md_to_html($thread->body())) }}"/>
36+
</div>
37+
<div class="border-t">
38+
@include('forum.threads.info.likes', [
39+
'like'=> ['threads.like', $thread->slug()],
40+
'unlike' => ['threads.unlike', $thread->slug()],
41+
'likeable' => $thread
42+
])
43+
</div>
3944
</div>
4045

4146
<div class="mt-4">
@@ -51,12 +56,9 @@
5156
</div>
5257
@endif
5358

54-
<div class="p-4">
55-
<div>
56-
<reply :content="{{ json_encode(md_to_html($reply->body())) }}"/>
57-
</div>
58-
<div class="flex flex-col md:flex-row md:items-center text-sm pt-5 border-t mt-4">
59-
<div class="flex flex-wrap mb-4 md:mb-0 justify-between w-full">
59+
<div>
60+
<div class="flex flex-col md:flex-row md:items-center text-sm p-4 border-b">
61+
<div class="flex flex-wrap mb-4 md:mb-0 justify-between w-full items-center">
6062
<div class="flex">
6163
@include('forum.threads.info.avatar', ['user' => $reply->author()])
6264

@@ -108,26 +110,17 @@
108110
</div>
109111
</div>
110112
</div>
111-
@endcan
112-
<div class="thread-info-likes">
113-
@if(!$reply->isLikedBy(auth()->user()))
114-
{{ Form::open(['route' => ['replies.like', $reply], 'method' => 'PUT']) }}
115-
<span>{{$reply->likes_count}}</span>
116-
{{ Form::submit('like', ['class' => 'btn btn-xs btn-success']) }}
117-
{{ Form::close() }}
118-
@else
119-
{{ Form::open(['route' => ['replies.dislike', $reply], 'method' => 'DELETE']) }}
120-
<span>{{$reply->likes_count}}</span>
121-
{{ Form::submit('dislike', ['class' => 'btn btn-xs btn-danger']) }}
122-
{{ Form::close() }}
123-
@endif
124-
</div>
125-
@endcan
126-
@auth
127-
<div class="thread-info-likes">
128-
<like></like>
113+
<div class="p-4">
114+
<reply :content="{{ json_encode(md_to_html($reply->body())) }}"/>
115+
</div>
116+
<div class="border-t">
117+
@include('forum.threads.info.likes', [
118+
'like'=> ['replies.like', $reply],
119+
'unlike' => ['replies.unlike', $reply],
120+
'likeable' => $reply
121+
])
129122
</div>
130-
@endauth
123+
</div>
131124
</div>
132125

133126
@include('_partials._delete_modal', [

0 commit comments

Comments
 (0)