Skip to content
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

Enhancement: Hashtag trending #619

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
15 changes: 15 additions & 0 deletions app/Livewire/Home/TrendingHashtags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Livewire\Home;

use Livewire\Component;
use App\Queries\Feeds\TrendingHashtags as TrendingHashtagsQuery;

class TrendingHashtags extends Component
nunomaduro marked this conversation as resolved.
Show resolved Hide resolved
{
public function render()
{
$hashtags = (new TrendingHashtagsQuery())->builder()->limit(5)->orderBy('questions_count', 'DESC')->get();
return view('livewire.home.trending-hashtags', ['hashtags' => $hashtags]);
}
}
31 changes: 31 additions & 0 deletions app/Queries/Feeds/TrendingHashtags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace App\Queries\Feeds;

use App\Models\Hashtag;
use Illuminate\Database\Eloquent\Builder;

final readonly class TrendingHashtags
{

/**
* The max days since posted for the trending feed.
*/
private const int MAX_DAYS_SINCE_POSTED = 1;

/**
* Get the query builder for the feed.
*
* @return Builder<Question>
*/
public function builder(): Builder
{
$maxDaysSincePosted = self::MAX_DAYS_SINCE_POSTED;

return Hashtag::query()
->withCount('questions')
->where('created_at', '>=', now()->subDays($maxDaysSincePosted));
amitm13 marked this conversation as resolved.
Show resolved Hide resolved
}
}
1 change: 1 addition & 0 deletions resources/views/home/trending-questions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<div class="w-full max-w-md overflow-hidden rounded-lg px-2 shadow-md sm:px-0">
<x-home-menu></x-home-menu>

<livewire:home.trending-hashtags />
<livewire:home.trending-questions :focus-input="true" />
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/layouts/navigation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<nav>
<div class="{{ $navClasses }}">
<div class="flex h-16 justify-between">
<div class="flex h-16 md:justify-end bg-slate-900/50 backdrop-blur-sm w-full justify-center md:bg-transparent md:backdrop-blur-none">
amitm13 marked this conversation as resolved.
Show resolved Hide resolved
<div
class="flex items-center space-x-2.5"
x-data
Expand Down
5 changes: 5 additions & 0 deletions resources/views/livewire/home/trending-hashtags.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
@foreach ($hashtags as $hashtag)
<a class="bg-slate-600/20 p-4 shadow-2xl backdrop-blur font-medium me-2 py-1 px-2 rounded" href="{{ route('hashtag.show', $hashtag->name) }}">#{{ $hashtag->name }}</a>
amitm13 marked this conversation as resolved.
Show resolved Hide resolved
@endforeach
</div>