Skip to content

Commit a7c4d14

Browse files
committed
feat:(LAR-165) add filter to thread
feat:(LAR-165) add filter to thread feat:(LAR-180) update paginate article feat:(LAR-165) add filter for popular topics fix:(LAR-165) fix phpstan error feat:(LAR-149) add no reply filter feat:(LAR-165) add filter to thread feat:(LAR-165) add filter to thread en fix lint
1 parent b46c1c1 commit a7c4d14

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

app/Livewire/Pages/Articles/Index.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public function render(): View
3333
->published()
3434
->notPinned()
3535
->forLocale($this->locale)
36-
->simplePaginate(20),
36+
->simplePaginate(21),
37+
3738
'tags' => Tag::query()->whereHas('articles', function ($query): void {
3839
$query->published();
3940
})->orderBy('name')->get(),

app/Livewire/Pages/Forum/Index.php

+27-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ final class Index extends Component
3939
#[Url(as: 'follow')]
4040
public ?string $subscribe = null;
4141

42+
public bool $popular = true;
43+
4244
public ?Channel $currentChannel = null;
4345

4446
public string $search = '';
@@ -54,6 +56,18 @@ public function mount(): void
5456
$this->locale = config('app.locale');
5557
}
5658

59+
protected function applyPopular(Builder $query): Builder
60+
{
61+
if ($this->popular) {
62+
return $query // @phpstan-ignore-line
63+
->withCount('replies')
64+
->orderByDesc('replies_count')
65+
->OrderByViews();
66+
}
67+
68+
return $query;
69+
}
70+
5771
#[On('channelUpdated')]
5872
public function reloadThreads(?int $channelId): void
5973
{
@@ -140,13 +154,23 @@ protected function applySubscribe(Builder $query): Builder
140154

141155
protected function applyUnAnswer(Builder $query): Builder
142156
{
157+
if ($this->unAnswered) {
158+
return $query->whereDoesntHave('replies');
159+
}
160+
143161
return $query;
144162
}
145163

164+
protected function applySorting(Builder $query): Builder
165+
{
166+
return $this->popular
167+
? $this->applyPopular($query)
168+
: $query->orderByDesc('created_at');
169+
}
170+
146171
public function render(): View
147172
{
148-
$query = Thread::with(['channels', 'user'])
149-
->orderByDesc('created_at');
173+
$query = Thread::with(['channels', 'user']);
150174

151175
$query = $this->applyChannel($query);
152176
$query = $this->applySearch($query);
@@ -155,6 +179,7 @@ public function render(): View
155179
$query = $this->applyAuthor($query);
156180
$query = $this->applySubscribe($query);
157181
$query = $this->applyUnAnswer($query);
182+
$query = $this->applySorting($query);
158183

159184
$threads = $query
160185
->scopes('withViewsCount')

resources/views/layouts/forum.blade.php

-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
:href="route('forum.index', ['popular' => true])"
4343
:active="request()->getUri() === route('forum.index', ['popular' => true])"
4444
icon="untitledui-heart"
45-
class="hidden"
4645
>
4746
{{ __('pages/forum.navigation.popular') }}
4847
</x-nav.forum-link>
@@ -64,7 +63,6 @@ class="hidden"
6463
:href="route('forum.index', ['no-replies' => true])"
6564
:active="request()->getUri() === route('forum.index', ['no-replies' => true])"
6665
icon="untitledui-message-x-square"
67-
class="hidden"
6866
>
6967
{{ __('pages/forum.navigation.no_reply') }}
7068
</x-nav.forum-link>

resources/views/livewire/pages/articles/index.blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class="flex size-8 items-center justify-center rounded-full text-gray-400 transi
119119
@endforeach
120120
</div>
121121

122-
<div class="mt-4">
122+
<div class="mt-10">
123123
{{ $articles->links() }}
124124
</div>
125125
</x-container>

0 commit comments

Comments
 (0)