Skip to content

feat:(LAR-165) add filter for popular topics #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/Livewire/Pages/Articles/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function render(): View
->published()
->notPinned()
->forLocale($this->locale)
->simplePaginate(20),
->simplePaginate(21),

'tags' => Tag::query()->whereHas('articles', function ($query): void {
$query->published();
})->orderBy('name')->get(),
Expand Down
30 changes: 28 additions & 2 deletions app/Livewire/Pages/Forum/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ final class Index extends Component
#[Url(as: 'follow')]
public ?string $subscribe = null;

#[Url]
public ?string $popular = null;

public ?Channel $currentChannel = null;

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

protected function applyPopular(Builder $query): Builder
{
if ($this->popular) {
return $query // @phpstan-ignore-line
->withCount('replies')
->orderByDesc('replies_count')
->OrderByViews();
}

return $query;
}

#[On('channelUpdated')]
public function reloadThreads(?int $channelId): void
{
Expand Down Expand Up @@ -140,13 +155,23 @@ protected function applySubscribe(Builder $query): Builder

protected function applyUnAnswer(Builder $query): Builder
{
if ($this->unAnswered) {
return $query->whereDoesntHave('replies');
}

return $query;
}

protected function applySorting(Builder $query): Builder
{
return $this->popular
? $this->applyPopular($query)
: $query->orderByDesc('created_at');
}

public function render(): View
{
$query = Thread::with(['channels', 'user'])
->orderByDesc('created_at');
$query = Thread::with(['channels', 'user']);

$query = $this->applyChannel($query);
$query = $this->applySearch($query);
Expand All @@ -155,6 +180,7 @@ public function render(): View
$query = $this->applyAuthor($query);
$query = $this->applySubscribe($query);
$query = $this->applyUnAnswer($query);
$query = $this->applySorting($query);

$threads = $query
->scopes('withViewsCount')
Expand Down
2 changes: 0 additions & 2 deletions resources/views/layouts/forum.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
:href="route('forum.index', ['popular' => true])"
:active="request()->getUri() === route('forum.index', ['popular' => true])"
icon="untitledui-heart"
class="hidden"
>
{{ __('pages/forum.navigation.popular') }}
</x-nav.forum-link>
Expand All @@ -64,7 +63,6 @@ class="hidden"
:href="route('forum.index', ['no-replies' => true])"
:active="request()->getUri() === route('forum.index', ['no-replies' => true])"
icon="untitledui-message-x-square"
class="hidden"
>
{{ __('pages/forum.navigation.no_reply') }}
</x-nav.forum-link>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/livewire/pages/articles/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class="flex size-8 items-center justify-center rounded-full text-gray-400 transi
@endforeach
</div>

<div class="mt-4">
<div class="mt-10">
{{ $articles->links() }}
</div>
</x-container>
Expand Down
Loading