Skip to content

Commit 5fffb9c

Browse files
committed
feat:(LAR-180) update paginate article
feat:(LAR-165) add filter for popular topics
1 parent f5b692c commit 5fffb9c

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

app/Livewire/Pages/Articles/Index.php

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

app/Livewire/Pages/Forum/Index.php

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

42+
#[Url(as: 'popular')]
43+
public ?string $popular = null;
44+
4245
public ?Channel $currentChannel = null;
4346

4447
public string $search = '';
@@ -54,6 +57,18 @@ public function mount(): void
5457
$this->locale = config('app.locale');
5558
}
5659

60+
protected function applyPopular(Builder $query): Builder
61+
{
62+
if ($this->popular) {
63+
return $query
64+
->withCount('replies')
65+
->orderByDesc('replies_count')
66+
->OrderByViews(); // @phpstan-ignore-line
67+
}
68+
69+
return $query;
70+
}
71+
5772
#[On('channelUpdated')]
5873
public function reloadThreads(?int $channelId): void
5974
{
@@ -145,8 +160,7 @@ protected function applyUnAnswer(Builder $query): Builder
145160

146161
public function render(): View
147162
{
148-
$query = Thread::with(['channels', 'user'])
149-
->orderByDesc('created_at');
163+
$query = Thread::with(['channels', 'user']);
150164

151165
$query = $this->applyChannel($query);
152166
$query = $this->applySearch($query);
@@ -155,6 +169,7 @@ public function render(): View
155169
$query = $this->applyAuthor($query);
156170
$query = $this->applySubscribe($query);
157171
$query = $this->applyUnAnswer($query);
172+
$query = $this->applySorting($query);
158173

159174
$threads = $query
160175
->scopes('withViewsCount')
@@ -165,4 +180,11 @@ public function render(): View
165180
])
166181
->title(__('pages/forum.channel_title', ['channel' => isset($this->currentChannel) ? ' ~ '.$this->currentChannel->name : '']));
167182
}
183+
184+
private function applySorting(Builder $query): Builder
185+
{
186+
return $this->popular
187+
? $this->applyPopular($query)
188+
: $query->orderByDesc('created_at');
189+
}
168190
}

resources/views/layouts/forum.blade.php

-1
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>

0 commit comments

Comments
 (0)