Skip to content

Commit

Permalink
feat: disabled default local for seo improve and eager loading model … (
Browse files Browse the repository at this point in the history
  • Loading branch information
mckenziearts authored Jan 18, 2025
1 parent 4ae7639 commit 621cee1
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 37 deletions.
1 change: 0 additions & 1 deletion app/Actions/Forum/CreateThreadAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ public function execute(array $formValues): Thread

return $thread;
});

}
}
5 changes: 0 additions & 5 deletions app/Livewire/Pages/Articles/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ final class Index extends Component
use WithoutUrlPagination;
use WithPagination;

public function mount(): void
{
$this->locale = config('app.locale');
}

public function render(): View
{
return view('livewire.pages.articles.index', [
Expand Down
5 changes: 0 additions & 5 deletions app/Livewire/Pages/Discussions/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ final class Index extends Component

public string $sortBy = 'recent';

public function mount(): void
{
$this->locale = config('app.locale');
}

public function validSort(string $sort): bool
{
return in_array($sort, [
Expand Down
4 changes: 1 addition & 3 deletions app/Livewire/Pages/Forum/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public function mount(): void
if ($this->channel) {
$this->currentChannel = Channel::findBySlug($this->channel);
}

$this->locale = config('app.locale');
}

protected function applyPopular(Builder $query): Builder
Expand Down Expand Up @@ -171,7 +169,7 @@ protected function applySorting(Builder $query): Builder

public function render(): View
{
$query = Thread::with(['channels', 'user', 'user.media'])
$query = Thread::with(['channels', 'channels.parent', 'user', 'user.media'])
->withCount('replies');

$query = $this->applyChannel($query);
Expand Down
3 changes: 2 additions & 1 deletion app/Livewire/Pages/Forum/Leaderboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function render(): View
callback: fn () => $leaders
),
'startPosition' => $startPosition,
]);
])
->title(__('pages/forum.navigation.leaderboard'));
}
}
4 changes: 2 additions & 2 deletions app/Models/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ public static function feed(User $user, int $take = 50): Collection
public static function latestFeed(User $user, int $take = 10): Collection
{
return self::where('user_id', $user->id)
->latest()
->with('subject')
->take($take)
->latest()
->limit($take)
->orderByDesc('created_at')
->get();
}
Expand Down
6 changes: 5 additions & 1 deletion app/Models/Traits/HasLocaleScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ trait HasLocaleScope
{
public function scopeForLocale(Builder $query, ?string $locale): Builder
{
return $query->where('locale', $locale);
if ($locale) {
return $query->where('locale', $locale);
}

return $query;
}
}
24 changes: 13 additions & 11 deletions resources/views/components/discussions/overview.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@props([
'discussion',
'withAuthor' => true,
])

<div class="py-6">
Expand Down Expand Up @@ -27,24 +28,25 @@

<div class="mt-4 sm:flex sm:justify-between">
<div class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300">
<x-user.avatar
:user="$discussion->user"
class="size-6"
span="-right-1 -top-1 ring-1 size-4"
/>
<span>{{ __('global.posted_by') }}</span>
<div class="flex items-center gap-2">
@if ($withAuthor)
<div class="flex items-center gap-2">
<x-user.avatar
:user="$discussion->user"
class="size-6"
span="-right-1 -top-1 ring-1 size-4"
/>
</div>
<x-link
:href="route('profile', $discussion->user)"
class="text-gray-700 dark:text-gray-300 font-medium hover:underline"
>
{{ $discussion->user->name }}
</x-link>
<span aria-hidden="true">&middot;</span>
<time class="truncate text-sm text-gray-500 dark:text-gray-400" datetime="{{ $discussion->created_at }}">
{{ $discussion->created_at->diffForHumans() }}
</time>
</div>
@endif
<time class="truncate text-sm text-gray-500 dark:text-gray-400" datetime="{{ $discussion->created_at }}">
{{ $discussion->created_at->diffForHumans() }}
</time>
</div>
<div class="hidden space-x-3 sm:flex sm:items-center">
@if ($discussion->getReactionsSummary()->isNotEmpty())
Expand Down
16 changes: 10 additions & 6 deletions resources/views/components/forum/thread.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@props([
'thread',
'withAuthor' => true,
])

<article class="rounded-xl p-4 bg-white ring-1 ring-gray-200/50 transition duration-200 ease-in-out dark:bg-gray-800 dark:ring-white/10 dark:hover:bg-white/10 lg:p-5" aria-labelledby="{{ $thread->slug }}">
Expand Down Expand Up @@ -29,12 +30,15 @@ class="inline-flex items-center rounded-xl gap-1 px-2 py-0.5 font-medium bg-prim

<div class="mt-6 flex justify-between space-x-8">
<div class="flex items-center gap-2">
<x-link :href="route('profile', $thread->user)" class="group inline-flex items-center gap-1 shrink-0">
<x-user.avatar :user="$thread->user" class="size-6" />
<span class="font-medium text-sm text-gray-700 group-hover:underline dark:text-gray-300">
{{ '@' . $thread->user->username }}
</span>
</x-link>
@if ($withAuthor)
<x-link :href="route('profile', $thread->user)" class="group inline-flex items-center gap-1 shrink-0">
<x-user.avatar :user="$thread->user" class="size-6" />
<span class="font-medium text-sm text-gray-700 group-hover:underline dark:text-gray-300">
{{ '@' . $thread->user->username }}
</span>
</x-link>
@endif

<span class="flex items-center text-xs text-gray-500 flex-wrap gap-1 dark:text-gray-400">
<span class="hidden lg:inline">{{ __('global.ask') }}</span>
<time datetime="{{ $thread->created_at }}">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/user/discussions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@if ($discussions->isNotEmpty())
<div class="relative -mt-6 divide-y divide-gray-200 dark:divide-white/20">
@foreach ($discussions as $discussion)
<x-discussions.overview :discussion="$discussion" />
<x-discussions.overview :discussion="$discussion" :with-author="false" />
@endforeach
</div>
@else
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/user/threads.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@if ($threads->isNotEmpty())
<div class="space-y-4">
@foreach ($threads as $thread)
<x-forum.thread :thread="$thread" wire:key="{{ $thread->slug }}" />
<x-forum.thread :thread="$thread" wire:key="{{ $thread->slug }}" :with-author="false" />
@endforeach
</div>
@else
Expand Down

0 comments on commit 621cee1

Please sign in to comment.