Skip to content

Commit abf60ae

Browse files
authored
feat: [LAR-150] add forum leaderboard page (#289)
1 parent 5d1f6b9 commit abf60ae

File tree

29 files changed

+419
-166
lines changed

29 files changed

+419
-166
lines changed

app/Livewire/Reactions.php renamed to app/Livewire/Components/Reactions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace App\Livewire;
5+
namespace App\Livewire\Components;
66

77
use App\Contracts\ReactableInterface;
88
use App\Models\Reaction;
@@ -40,6 +40,6 @@ public function userReacted(string $reaction): void
4040

4141
public function render(): View
4242
{
43-
return view('livewire.reactions');
43+
return view('livewire.components.reactions');
4444
}
4545
}

app/Livewire/ReportSpam.php renamed to app/Livewire/Components/ReportSpam.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace App\Livewire;
5+
namespace App\Livewire\Components;
66

77
use App\Actions\ReportSpamAction;
88
use App\Contracts\SpamReportableContract;

app/Livewire/Pages/Forum/Index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ final class Index extends Component
2424
use WithoutUrlPagination;
2525
use WithPagination;
2626

27-
#[Url(as: 'channel')]
27+
#[Url]
2828
public ?string $channel = null;
2929

30-
#[Url(as: 'solved')]
30+
#[Url]
3131
public ?string $solved = null;
3232

3333
#[Url(as: 'me')]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Livewire\Pages\Forum;
6+
7+
use App\Models\User;
8+
use Illuminate\Contracts\View\View;
9+
use Illuminate\Database\Eloquent\Collection;
10+
use Illuminate\Support\Facades\Cache;
11+
use Livewire\Attributes\Layout;
12+
use Livewire\Component;
13+
14+
#[Layout('layouts.forum')]
15+
final class Leaderboard extends Component
16+
{
17+
public function render(): View
18+
{
19+
$startPosition = 1;
20+
$leaders = collect();
21+
22+
/** @var Collection $leaderboard */
23+
$leaderboard = User::mostSolutionsInLastDays(365)
24+
->take(30)
25+
->get()
26+
->reject(fn ($leaderboard) => $leaderboard->solutions_count === 0); // @phpstan-ignore-line
27+
28+
if ($leaderboard->count() > 3) {
29+
$leaders = $leaderboard->slice(0, 3);
30+
$startPosition = 4;
31+
}
32+
33+
return view('livewire.pages.forum.leaderboard', [
34+
'members' => Cache::remember(
35+
key: 'members',
36+
ttl: now()->addWeek(),
37+
callback: fn () => $leaderboard->reject(
38+
fn (User $user) => in_array($user->id, $leaders->pluck('id')->toArray()) // @phpstan-ignore-line
39+
)
40+
),
41+
'leaders' => Cache::remember(
42+
key: 'leaders',
43+
ttl: now()->addWeek(),
44+
callback: fn () => $leaders
45+
),
46+
'startPosition' => $startPosition,
47+
]);
48+
}
49+
}

app/Models/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ public function countThreads(): int
420420
public function scopeMostSolutions(Builder $query, ?int $inLastDays = null): Builder
421421
{
422422
return $query->withCount(['replyAble as solutions_count' => function ($query) use ($inLastDays) {
423-
$query->where('replyable_type', 'threads')
423+
$query->where('replyable_type', 'thread')
424424
->join('threads', 'threads.solution_reply_id', '=', 'replies.id');
425425

426426
if ($inLastDays) {

app/View/Composers/TopMembersComposer.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

lang/en/global.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,13 @@
107107
'language' => 'Language',
108108
'french' => 'French',
109109
'english' => 'English',
110+
'experience' => 'Experience',
111+
'last_active' => 'Last active',
112+
'first_place' => '1st place',
113+
'second_place' => '2nd place',
114+
'third_place' => '3rd place',
115+
'ranking_updated' => 'The rankings are updated weekly.',
116+
'place' => 'Place',
117+
'user' => 'User',
110118

111119
];

lang/en/pages/forum.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@
4747
'prevent_text_one' => 'Make sure you\'ve read our',
4848
'rules' => 'rules of conduct',
4949
'prevent_text_two' => 'before replying to this thread.',
50+
'leaderboard_empty' => 'No ranking available',
5051

5152
];

lang/fr/global.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,13 @@
107107
'language' => 'Langue',
108108
'french' => 'Français',
109109
'english' => 'Anglais',
110+
'experience' => 'Expérience',
111+
'last_active' => 'Dernière activité',
112+
'first_place' => '1ere place',
113+
'second_place' => '2e place',
114+
'third_place' => '3e place',
115+
'ranking_updated' => 'Ce classement est mis à jour toutes les semaines.',
116+
'place' => 'Position',
117+
'user' => 'Utilisateur',
118+
110119
];

lang/fr/pages/forum.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@
4747
'prevent_text_one' => 'Assurez-vous d\'avoir lu nos',
4848
'rules' => 'règles de conduite',
4949
'prevent_text_two' => 'avant de répondre à ce thread.',
50+
'leaderboard_empty' => 'Aucun classement disponible',
5051

5152
];

0 commit comments

Comments
 (0)