Skip to content

Commit

Permalink
feat:(LAR-165) add filter to thread
Browse files Browse the repository at this point in the history
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

feat:(LAR-165) add filter to thread
  • Loading branch information
StevyMarlino committed Jan 8, 2025
1 parent b46c1c1 commit c84a93d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
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

0 comments on commit c84a93d

Please sign in to comment.