Skip to content

Commit 83258c4

Browse files
committed
✨ mise en place du listing des discussions
1 parent e68e8df commit 83258c4

File tree

20 files changed

+287
-124
lines changed

20 files changed

+287
-124
lines changed

app/Http/Controllers/DiscussionController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function show(Discussion $discussion)
3131
->twitterSite('laravelcm')
3232
->withUrl();
3333

34-
return view('discussions.show', compact('discussion'));
34+
return view('discussions.show', ['discussion' => $discussion->load('tags')]);
3535
}
3636

3737
public function create()

app/Http/Livewire/Articles/Browse.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,18 @@
55
use App\Models\Article;
66
use App\Models\Tag;
77
use App\Traits\WithInfiniteScroll;
8+
use App\Traits\WithTags;
89
use Livewire\Component;
910

1011
class Browse extends Component
1112
{
12-
use WithInfiniteScroll;
13-
14-
public string $sortBy = 'recent';
15-
public ?string $tag = null;
13+
use WithInfiniteScroll, WithTags;
1614

1715
protected $queryString = [
1816
'tag' => ['except' => ''],
1917
'sortBy' => ['except' => 'recent'],
2018
];
2119

22-
public function toggleTag($tag): void
23-
{
24-
$this->tag = $this->tag !== $tag && $this->tagExists($tag) ? $tag : null;
25-
}
26-
27-
public function sortBy($sort): void
28-
{
29-
$this->sortBy = $this->validSort($sort) ? $sort : 'recent';
30-
}
31-
32-
public function tagExists($tag): bool
33-
{
34-
return Tag::where('slug', $tag)->exists();
35-
}
36-
3720
public function validSort($sort): bool
3821
{
3922
return in_array($sort, [

app/Http/Livewire/Discussions/Browse.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,51 @@
22

33
namespace App\Http\Livewire\Discussions;
44

5+
use App\Models\Discussion;
6+
use App\Models\Tag;
7+
use App\Traits\WithInfiniteScroll;
8+
use App\Traits\WithTags;
59
use Livewire\Component;
610

711
class Browse extends Component
812
{
13+
use WithInfiniteScroll, WithTags;
14+
15+
protected $queryString = [
16+
'tag' => ['except' => ''],
17+
'sortBy' => ['except' => 'recent'],
18+
];
19+
20+
public function validSort($sort): bool
21+
{
22+
return in_array($sort, [
23+
'recent',
24+
'popular',
25+
'active',
26+
]);
27+
}
28+
929
public function render()
1030
{
11-
return view('livewire.discussions.browse');
31+
$discussions = Discussion::with('tags')
32+
->withCount('replies')
33+
->notPinned();
34+
35+
$tags = Tag::whereJsonContains('concerns', ['discussion'])->orderBy('name')->get();
36+
37+
$selectedTag = Tag::where('name', $this->tag)->first();
38+
39+
if ($this->tag) {
40+
$discussions->forTag($this->tag);
41+
}
42+
43+
$discussions->{$this->sortBy}();
44+
45+
return view('livewire.discussions.browse', [
46+
'discussions' => $discussions->paginate($this->perPage),
47+
'tags' => $tags,
48+
'selectedTag' => $selectedTag,
49+
'selectedSortBy' => $this->sortBy,
50+
]);
1251
}
1352
}

app/Http/Livewire/Reactions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class Reactions extends Component
1414

1515
public Model $model;
1616
public bool $withPlaceHolder = true;
17+
public bool $withBackground = true;
18+
public string $direction = 'right';
1719

1820
public function userReacted(string $reaction)
1921
{

app/Models/Discussion.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class Discussion extends Model implements ReactableInterface, ReplyInterface, Su
6161
* @var array
6262
*/
6363
protected $with = [
64-
'tags',
6564
'author',
6665
];
6766

app/Traits/WithTags.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace App\Traits;
4+
5+
use App\Models\Tag;
6+
7+
trait WithTags {
8+
public ?string $tag = null;
9+
public string $sortBy = 'recent';
10+
11+
public function toggleTag($tag): void
12+
{
13+
$this->tag = $this->tag !== $tag && $this->tagExists($tag) ? $tag : null;
14+
}
15+
16+
public function sortBy($sort): void
17+
{
18+
$this->sortBy = $this->validSort($sort) ? $sort : 'recent';
19+
}
20+
21+
public function tagExists($tag): bool
22+
{
23+
return Tag::where('slug', $tag)->exists();
24+
}
25+
}

public/css/app.css

Lines changed: 37 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4331,6 +4331,9 @@ select {
43314331
.bottom-0 {
43324332
bottom: 0px;
43334333
}
4334+
.-right-1 {
4335+
right: -0.25rem;
4336+
}
43344337
.-top-3 {
43354338
top: -0.75rem;
43364339
}
@@ -4346,9 +4349,6 @@ select {
43464349
.-bottom-0\.5 {
43474350
bottom: -0.125rem;
43484351
}
4349-
.-right-1 {
4350-
right: -0.25rem;
4351-
}
43524352
.-bottom-0 {
43534353
bottom: 0px;
43544354
}
@@ -4389,6 +4389,14 @@ select {
43894389
margin-left: auto;
43904390
margin-right: auto;
43914391
}
4392+
.mx-2 {
4393+
margin-left: 0.5rem;
4394+
margin-right: 0.5rem;
4395+
}
4396+
.mx-0 {
4397+
margin-left: 0px;
4398+
margin-right: 0px;
4399+
}
43924400
.mx-1\.5 {
43934401
margin-left: 0.375rem;
43944402
margin-right: 0.375rem;
@@ -4397,10 +4405,6 @@ select {
43974405
margin-left: 0.25rem;
43984406
margin-right: 0.25rem;
43994407
}
4400-
.mx-2 {
4401-
margin-left: 0.5rem;
4402-
margin-right: 0.5rem;
4403-
}
44044408
.my-8 {
44054409
margin-top: 2rem;
44064410
margin-bottom: 2rem;
@@ -4417,10 +4421,6 @@ select {
44174421
margin-top: 2.5rem;
44184422
margin-bottom: 2.5rem;
44194423
}
4420-
.mx-0 {
4421-
margin-left: 0px;
4422-
margin-right: 0px;
4423-
}
44244424
.-mx-4 {
44254425
margin-left: -1rem;
44264426
margin-right: -1rem;
@@ -4486,6 +4486,9 @@ select {
44864486
.-ml-1 {
44874487
margin-left: -0.25rem;
44884488
}
4489+
.mr-1 {
4490+
margin-right: 0.25rem;
4491+
}
44894492
.ml-1\.5 {
44904493
margin-left: 0.375rem;
44914494
}
@@ -4495,9 +4498,6 @@ select {
44954498
.mr-1\.5 {
44964499
margin-right: 0.375rem;
44974500
}
4498-
.mr-1 {
4499-
margin-right: 0.25rem;
4500-
}
45014501
.mt-4 {
45024502
margin-top: 1rem;
45034503
}
@@ -5117,16 +5117,16 @@ select {
51175117
margin-right: calc(2rem * var(--tw-space-x-reverse));
51185118
margin-left: calc(2rem * calc(1 - var(--tw-space-x-reverse)));
51195119
}
5120-
.space-y-5 > :not([hidden]) ~ :not([hidden]) {
5121-
--tw-space-y-reverse: 0;
5122-
margin-top: calc(1.25rem * calc(1 - var(--tw-space-y-reverse)));
5123-
margin-bottom: calc(1.25rem * var(--tw-space-y-reverse));
5124-
}
51255120
.space-y-16 > :not([hidden]) ~ :not([hidden]) {
51265121
--tw-space-y-reverse: 0;
51275122
margin-top: calc(4rem * calc(1 - var(--tw-space-y-reverse)));
51285123
margin-bottom: calc(4rem * var(--tw-space-y-reverse));
51295124
}
5125+
.space-y-5 > :not([hidden]) ~ :not([hidden]) {
5126+
--tw-space-y-reverse: 0;
5127+
margin-top: calc(1.25rem * calc(1 - var(--tw-space-y-reverse)));
5128+
margin-bottom: calc(1.25rem * var(--tw-space-y-reverse));
5129+
}
51305130
.space-x-6 > :not([hidden]) ~ :not([hidden]) {
51315131
--tw-space-x-reverse: 0;
51325132
margin-right: calc(1.5rem * var(--tw-space-x-reverse));
@@ -5164,10 +5164,6 @@ select {
51645164
--tw-divide-opacity: 1;
51655165
border-color: rgba(228, 228, 231, var(--tw-divide-opacity));
51665166
}
5167-
.divide-gray-200 > :not([hidden]) ~ :not([hidden]) {
5168-
--tw-divide-opacity: 1;
5169-
border-color: rgba(229, 231, 235, var(--tw-divide-opacity));
5170-
}
51715167
.self-start {
51725168
align-self: flex-start;
51735169
}
@@ -5267,15 +5263,15 @@ select {
52675263
.rounded-tl-sm {
52685264
border-top-left-radius: 0.125rem;
52695265
}
5266+
.rounded-tl {
5267+
border-top-left-radius: 0.25rem;
5268+
}
52705269
.rounded-tr-lg {
52715270
border-top-right-radius: 0.5rem;
52725271
}
52735272
.rounded-br-lg {
52745273
border-bottom-right-radius: 0.5rem;
52755274
}
5276-
.rounded-tl {
5277-
border-top-left-radius: 0.25rem;
5278-
}
52795275
.border {
52805276
border-width: 1px;
52815277
}
@@ -5701,6 +5697,14 @@ select {
57015697
padding-left: 0px;
57025698
padding-right: 0px;
57035699
}
5700+
.px-0\.5 {
5701+
padding-left: 0.125rem;
5702+
padding-right: 0.125rem;
5703+
}
5704+
.py-px {
5705+
padding-top: 1px;
5706+
padding-bottom: 1px;
5707+
}
57045708
.px-3\.5 {
57055709
padding-left: 0.875rem;
57065710
padding-right: 0.875rem;
@@ -5713,14 +5717,6 @@ select {
57135717
padding-top: 0.625rem;
57145718
padding-bottom: 0.625rem;
57155719
}
5716-
.px-0\.5 {
5717-
padding-left: 0.125rem;
5718-
padding-right: 0.125rem;
5719-
}
5720-
.py-px {
5721-
padding-top: 1px;
5722-
padding-bottom: 1px;
5723-
}
57245720
.pr-2 {
57255721
padding-right: 0.5rem;
57265722
}
@@ -5832,6 +5828,9 @@ select {
58325828
.pt-12 {
58335829
padding-top: 3rem;
58345830
}
5831+
.pb-6 {
5832+
padding-bottom: 1.5rem;
5833+
}
58355834
.text-left {
58365835
text-align: left;
58375836
}
@@ -6176,10 +6175,6 @@ select {
61766175
--tw-text-opacity: 1;
61776176
color: rgba(127, 29, 29, var(--tw-text-opacity));
61786177
}
6179-
.text-gray-900 {
6180-
--tw-text-opacity: 1;
6181-
color: rgba(17, 24, 39, var(--tw-text-opacity));
6182-
}
61836178
.underline {
61846179
text-decoration: underline;
61856180
}
@@ -6731,11 +6726,6 @@ html {
67316726
background-color: rgba(24, 24, 27, var(--tw-bg-opacity));
67326727
}
67336728

6734-
.hover\:bg-gray-50:hover {
6735-
--tw-bg-opacity: 1;
6736-
background-color: rgba(249, 250, 251, var(--tw-bg-opacity));
6737-
}
6738-
67396729
.hover\:text-skin-inverted-muted:hover {
67406730
--tw-text-opacity: 1;
67416731
color: rgba(var(--color-text-inverted-muted), var(--tw-text-opacity));
@@ -9093,30 +9083,10 @@ html {
90939083
grid-column: span 10 / span 10;
90949084
}
90959085

9096-
.lg\:col-start-9 {
9097-
grid-column-start: 9;
9098-
}
9099-
9100-
.lg\:col-start-8 {
9101-
grid-column-start: 8;
9102-
}
9103-
91049086
.lg\:col-start-10 {
91059087
grid-column-start: 10;
91069088
}
91079089

9108-
.lg\:col-end-12 {
9109-
grid-column-end: 12;
9110-
}
9111-
9112-
.lg\:col-end-13 {
9113-
grid-column-end: 13;
9114-
}
9115-
9116-
.lg\:col-end-auto {
9117-
grid-column-end: auto;
9118-
}
9119-
91209090
.lg\:mx-0 {
91219091
margin-left: 0px;
91229092
margin-right: 0px;
@@ -9235,6 +9205,10 @@ html {
92359205
justify-content: flex-end;
92369206
}
92379207

9208+
.lg\:justify-between {
9209+
justify-content: space-between;
9210+
}
9211+
92389212
.lg\:gap-6 {
92399213
gap: 1.5rem;
92409214
}

resources/views/articles/show.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
@if ($article->tags->isNotEmpty())
8686
<div class="flex items-center space-x-2">
8787
@foreach ($article->tags as $tag)
88-
<x-articles.tag :tag="$tag" />
88+
<x-tag :tag="$tag" />
8989
@endforeach
9090
</div>
9191
@endif

resources/views/components/articles/filter.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class="{{ $selectedSortBy === 'recent' ? 'bg-skin-link text-skin-inverted': 'tex
1313
<path clip-rule="evenodd" d="M3.61 12c0 6.937 2.098 9.25 8.391 9.25 6.294 0 8.391-2.313 8.391-9.25 0-6.937-2.097-9.25-8.391-9.25C5.708 2.75 3.61 5.063 3.61 12z" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
1414
</svg>
1515
<span class="truncate">
16-
Récents
16+
Récent
1717
</span>
1818
</button>
1919

0 commit comments

Comments
 (0)