-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [LAR-150] add forum leaderboard page (#289)
- Loading branch information
1 parent
5d1f6b9
commit abf60ae
Showing
29 changed files
with
419 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Livewire\Pages\Forum; | ||
|
||
use App\Models\User; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Database\Eloquent\Collection; | ||
use Illuminate\Support\Facades\Cache; | ||
use Livewire\Attributes\Layout; | ||
use Livewire\Component; | ||
|
||
#[Layout('layouts.forum')] | ||
final class Leaderboard extends Component | ||
{ | ||
public function render(): View | ||
{ | ||
$startPosition = 1; | ||
$leaders = collect(); | ||
|
||
/** @var Collection $leaderboard */ | ||
$leaderboard = User::mostSolutionsInLastDays(365) | ||
->take(30) | ||
->get() | ||
->reject(fn ($leaderboard) => $leaderboard->solutions_count === 0); // @phpstan-ignore-line | ||
|
||
if ($leaderboard->count() > 3) { | ||
$leaders = $leaderboard->slice(0, 3); | ||
$startPosition = 4; | ||
} | ||
|
||
return view('livewire.pages.forum.leaderboard', [ | ||
'members' => Cache::remember( | ||
key: 'members', | ||
ttl: now()->addWeek(), | ||
callback: fn () => $leaderboard->reject( | ||
fn (User $user) => in_array($user->id, $leaders->pluck('id')->toArray()) // @phpstan-ignore-line | ||
) | ||
), | ||
'leaders' => Cache::remember( | ||
key: 'leaders', | ||
ttl: now()->addWeek(), | ||
callback: fn () => $leaders | ||
), | ||
'startPosition' => $startPosition, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#leaderboard { | ||
*, *::before, *::after { | ||
box-sizing: border-box; | ||
transform-style: preserve-3d; | ||
} | ||
|
||
.leaderboard { | ||
place-items: center; | ||
transform: perspective(400px); | ||
transform-style: preserve-3d; | ||
} | ||
|
||
.leaderboard > .stage { | ||
@apply relative w-full rounded-t-lg; | ||
transform: rotateX(70deg); | ||
} | ||
|
||
.leaderboard > .stage > .stage-front { | ||
@apply absolute w-full rounded-b-lg origin-top top-full; | ||
transform: rotateX(-80deg); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
@props([ | ||
'user', | ||
'position', | ||
]) | ||
|
||
@php | ||
$icon = match ($position) { | ||
1 => 'icon.trophies.first', | ||
2 => 'icon.trophies.second', | ||
3 => 'icon.trophies.third', | ||
default => 'phosphor-trophy-duotone', | ||
}; | ||
$ranking = match ($position) { | ||
1 => __('global.first_place'), | ||
2 => __('global.second_place'), | ||
3 => __('global.third_place'), | ||
default => 'N/A', | ||
}; | ||
$color = match ($position) { | ||
1 => 'success', | ||
2 => 'warning', | ||
3 => 'danger', | ||
default => 'gray', | ||
}; | ||
@endphp | ||
|
||
<div class="bg-white divide-y divide-gray-200 rounded-lg ring-1 ring-gray-200 dark:bg-gray-800 dark:ring-white/10 dark:divide-white/10"> | ||
<div class="flex gap-4 p-4"> | ||
<div class="relative flex-1 flex items-center gap-2"> | ||
<x-filament::badge :color="$color" class="absolute -top-7 !rounded-full"> | ||
{{ $ranking }} | ||
</x-filament::badge> | ||
<x-user.avatar :user="$user" class="size-7" /> | ||
<div class="text-sm truncate"> | ||
<h5 class="font-medium text-gray-900 truncate dark:text-white"> | ||
{{ $user->name }} | ||
</h5> | ||
<span class="text-gray-500 dark:text-gray-400"> | ||
{{ '@' . $user->username }} | ||
</span> | ||
</div> | ||
</div> | ||
<div> | ||
<x-dynamic-component :component="$icon" class="size-10" aria-hidden="true" /> | ||
</div> | ||
</div> | ||
<div class="flex divide-x divide-gray-200 dark:divide-white/10"> | ||
<div class="flex flex-col px-4 py-2.5"> | ||
<span class="text-xs/4 text-gray-400 capitalize dark:text-gray-500"> | ||
{{ __('global.experience') }} | ||
</span> | ||
<span class="font-medium text-sm text-gray-700 dark:text-gray-300"> | ||
{{ $user->getPoints() }} | ||
</span> | ||
</div> | ||
<div class="flex flex-col px-4 py-2.5"> | ||
<span class="text-xs/4 text-gray-400 capitalize dark:text-gray-500"> | ||
{{ __('global.answers') }} | ||
</span> | ||
<span class="font-medium text-sm text-gray-700 dark:text-gray-300"> | ||
{{ $user->solutions_count }} | ||
</span> | ||
</div> | ||
<div @class([ | ||
'flex flex-col px-4 py-2.5', | ||
'lg:hidden' => $position !== 1, | ||
])> | ||
<span class="text-xs/4 text-gray-400 capitalize dark:text-gray-500"> | ||
{{ __('global.last_active') }} | ||
</span> | ||
|
||
<span class="font-medium text-sm text-gray-700 dark:text-gray-300"> | ||
{{ $user->last_active_at?->diffForHumans() }} | ||
</span> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.