Skip to content

Commit 621cee1

Browse files
authored
feat: disabled default local for seo improve and eager loading model … (#323)
1 parent 4ae7639 commit 621cee1

File tree

11 files changed

+35
-37
lines changed

11 files changed

+35
-37
lines changed

app/Actions/Forum/CreateThreadAction.php

-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@ public function execute(array $formValues): Thread
2424

2525
return $thread;
2626
});
27-
2827
}
2928
}

app/Livewire/Pages/Articles/Index.php

-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ final class Index extends Component
1919
use WithoutUrlPagination;
2020
use WithPagination;
2121

22-
public function mount(): void
23-
{
24-
$this->locale = config('app.locale');
25-
}
26-
2722
public function render(): View
2823
{
2924
return view('livewire.pages.articles.index', [

app/Livewire/Pages/Discussions/Index.php

-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ final class Index extends Component
2626

2727
public string $sortBy = 'recent';
2828

29-
public function mount(): void
30-
{
31-
$this->locale = config('app.locale');
32-
}
33-
3429
public function validSort(string $sort): bool
3530
{
3631
return in_array($sort, [

app/Livewire/Pages/Forum/Index.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ public function mount(): void
5353
if ($this->channel) {
5454
$this->currentChannel = Channel::findBySlug($this->channel);
5555
}
56-
57-
$this->locale = config('app.locale');
5856
}
5957

6058
protected function applyPopular(Builder $query): Builder
@@ -171,7 +169,7 @@ protected function applySorting(Builder $query): Builder
171169

172170
public function render(): View
173171
{
174-
$query = Thread::with(['channels', 'user', 'user.media'])
172+
$query = Thread::with(['channels', 'channels.parent', 'user', 'user.media'])
175173
->withCount('replies');
176174

177175
$query = $this->applyChannel($query);

app/Livewire/Pages/Forum/Leaderboard.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function render(): View
4444
callback: fn () => $leaders
4545
),
4646
'startPosition' => $startPosition,
47-
]);
47+
])
48+
->title(__('pages/forum.navigation.leaderboard'));
4849
}
4950
}

app/Models/Activity.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ public static function feed(User $user, int $take = 50): Collection
7676
public static function latestFeed(User $user, int $take = 10): Collection
7777
{
7878
return self::where('user_id', $user->id)
79-
->latest()
8079
->with('subject')
81-
->take($take)
80+
->latest()
81+
->limit($take)
8282
->orderByDesc('created_at')
8383
->get();
8484
}

app/Models/Traits/HasLocaleScope.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ trait HasLocaleScope
1010
{
1111
public function scopeForLocale(Builder $query, ?string $locale): Builder
1212
{
13-
return $query->where('locale', $locale);
13+
if ($locale) {
14+
return $query->where('locale', $locale);
15+
}
16+
17+
return $query;
1418
}
1519
}

resources/views/components/discussions/overview.blade.php

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@props([
22
'discussion',
3+
'withAuthor' => true,
34
])
45

56
<div class="py-6">
@@ -27,24 +28,25 @@
2728

2829
<div class="mt-4 sm:flex sm:justify-between">
2930
<div class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300">
30-
<x-user.avatar
31-
:user="$discussion->user"
32-
class="size-6"
33-
span="-right-1 -top-1 ring-1 size-4"
34-
/>
35-
<span>{{ __('global.posted_by') }}</span>
36-
<div class="flex items-center gap-2">
31+
@if ($withAuthor)
32+
<div class="flex items-center gap-2">
33+
<x-user.avatar
34+
:user="$discussion->user"
35+
class="size-6"
36+
span="-right-1 -top-1 ring-1 size-4"
37+
/>
38+
</div>
3739
<x-link
3840
:href="route('profile', $discussion->user)"
3941
class="text-gray-700 dark:text-gray-300 font-medium hover:underline"
4042
>
4143
{{ $discussion->user->name }}
4244
</x-link>
4345
<span aria-hidden="true">&middot;</span>
44-
<time class="truncate text-sm text-gray-500 dark:text-gray-400" datetime="{{ $discussion->created_at }}">
45-
{{ $discussion->created_at->diffForHumans() }}
46-
</time>
47-
</div>
46+
@endif
47+
<time class="truncate text-sm text-gray-500 dark:text-gray-400" datetime="{{ $discussion->created_at }}">
48+
{{ $discussion->created_at->diffForHumans() }}
49+
</time>
4850
</div>
4951
<div class="hidden space-x-3 sm:flex sm:items-center">
5052
@if ($discussion->getReactionsSummary()->isNotEmpty())

resources/views/components/forum/thread.blade.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@props([
22
'thread',
3+
'withAuthor' => true,
34
])
45

56
<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 }}">
@@ -29,12 +30,15 @@ class="inline-flex items-center rounded-xl gap-1 px-2 py-0.5 font-medium bg-prim
2930

3031
<div class="mt-6 flex justify-between space-x-8">
3132
<div class="flex items-center gap-2">
32-
<x-link :href="route('profile', $thread->user)" class="group inline-flex items-center gap-1 shrink-0">
33-
<x-user.avatar :user="$thread->user" class="size-6" />
34-
<span class="font-medium text-sm text-gray-700 group-hover:underline dark:text-gray-300">
35-
{{ '@' . $thread->user->username }}
36-
</span>
37-
</x-link>
33+
@if ($withAuthor)
34+
<x-link :href="route('profile', $thread->user)" class="group inline-flex items-center gap-1 shrink-0">
35+
<x-user.avatar :user="$thread->user" class="size-6" />
36+
<span class="font-medium text-sm text-gray-700 group-hover:underline dark:text-gray-300">
37+
{{ '@' . $thread->user->username }}
38+
</span>
39+
</x-link>
40+
@endif
41+
3842
<span class="flex items-center text-xs text-gray-500 flex-wrap gap-1 dark:text-gray-400">
3943
<span class="hidden lg:inline">{{ __('global.ask') }}</span>
4044
<time datetime="{{ $thread->created_at }}">

resources/views/components/user/discussions.blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@if ($discussions->isNotEmpty())
77
<div class="relative -mt-6 divide-y divide-gray-200 dark:divide-white/20">
88
@foreach ($discussions as $discussion)
9-
<x-discussions.overview :discussion="$discussion" />
9+
<x-discussions.overview :discussion="$discussion" :with-author="false" />
1010
@endforeach
1111
</div>
1212
@else

resources/views/components/user/threads.blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@if ($threads->isNotEmpty())
77
<div class="space-y-4">
88
@foreach ($threads as $thread)
9-
<x-forum.thread :thread="$thread" wire:key="{{ $thread->slug }}" />
9+
<x-forum.thread :thread="$thread" wire:key="{{ $thread->slug }}" :with-author="false" />
1010
@endforeach
1111
</div>
1212
@else

0 commit comments

Comments
 (0)