Skip to content

Commit

Permalink
Use country singleton in more places and clean up styling
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya committed Dec 10, 2024
1 parent 7aca7a3 commit 34535b4
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 54 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/BeatmapsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static function beatmapScores(string $id, ?string $scoreTransformerType,
'type' => $type,
'user' => $currentUser,
]);
$scores = $esFetch->all()->loadMissing(['beatmap', 'user.country', 'processHistory']);
$scores = $esFetch->all()->loadMissing(['beatmap', 'user', 'processHistory']);
$userScore = $esFetch->userBest();
$scoreTransformer = new ScoreTransformer($scoreTransformerType);

Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Forum/TopicsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ public function show($id)

$posts->load([
'lastEditor',
'user.country',
'user.rank',
'user.supporterTagPurchases',
'user.userGroups',
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Controllers/RankingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,14 @@ public function index($mode, $type)

if ($type === 'country') {
$stats = CountryStatistics::where('display', 1)
->with('country')
->where('mode', $modeInt)
->orderBy('performance', 'desc');
} else {
$class = UserStatistics\Model::getClass($mode, $this->params['variant']);
$table = (new $class())->getTable();
$ppColumn = $class::ppColumn();
$stats = $class
::with(['user', 'user.country'])
::with('user')
->where($ppColumn, '>', 0)
->whereHas('user', function ($userQuery) {
$userQuery->default();
Expand Down
1 change: 1 addition & 0 deletions app/Models/DeletedUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class DeletedUser extends User
{
public null $country_acronym = null;
public $user_avatar = null;
public $username = '[deleted user]';

Expand Down
2 changes: 1 addition & 1 deletion app/Models/Multiplayer/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ public function startPlay(User $user, PlaylistItem $playlistItem, int $buildId)

public function topScores()
{
return $this->userHighScores()->forRanking()->with('user.country');
return $this->userHighScores()->forRanking()->with('user');
}

private function assertHostRoomAllowance()
Expand Down
10 changes: 4 additions & 6 deletions app/Models/Spotlight.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,11 @@ public function ranking(string $mode)
// These models will not have the correct table name set on them
// as they get overriden when Laravel hydrates them.
return $this->userStats($mode)
->with(['user', 'user.country'])
->whereHas('user', function ($userQuery) {
$model = new User();
->with('user')
->whereHas('user', fn ($userQuery) =>
$userQuery
->from($model->tableName(true))
->default();
})
->from($userQuery->getModel()->tableName(true))
->default())
->orderBy('ranked_score', 'desc')
->limit(static::SPOTLIGHT_MAX_RESULTS);
}
Expand Down
6 changes: 4 additions & 2 deletions app/Transformers/CountryStatisticsTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ public function transform(CountryStatistics $stat)

public function includeCountry(CountryStatistics $stat)
{
return $stat->country === null
$country = app('countries')->byCode($stat->country_code);

return $country === null
? $this->primitive(null)
: $this->item($stat->country, new CountryTransformer());
: $this->item($country, new CountryTransformer());
}
}
2 changes: 1 addition & 1 deletion resources/css/bem/profile-info.less
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@

&__flags {
display: flex;
gap: 5px;
gap: 10px;
margin-top: 10px;
font-size: 15px; // icon size

Expand Down
6 changes: 6 additions & 0 deletions resources/css/bem/ranking-page-table.less
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
margin-left: 10px;
}

&__flags {
display: inline-flex;
gap: 10px;
font-size: @flag-size-medium; // icon size
}

&__user-link {
display: flex;
align-items: center;
Expand Down
6 changes: 3 additions & 3 deletions resources/views/forum/topics/_post_info.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ class="forum-post-info__row forum-post-info__row--title"
</div>
@endif

@if ($user->country !== null)
@if (($countryAcronym = $user->country_acronym) !== null)
<div class="forum-post-info__row forum-post-info__row--flag">
<a href="{{route('rankings', [
'mode' => default_mode(),
'type' => 'performance',
'country' => $user->country->getKey(),
'country' => $countryAcronym,
])}}">
@include('objects._flag_country', ['country' => $user->country])
@include('objects._flag_country', ['country' => app('countries')->byCode($countryAcronym)])
</a>
</div>
@endif
Expand Down
12 changes: 8 additions & 4 deletions resources/views/multiplayer/rooms/_rankings_table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
</tr>
</thead>
<tbody>
@php
$countries = app('countries');
@endphp
@foreach ([$userScore, ...$scores] as $index => $score)
@if ($score === null)
@continue
Expand All @@ -35,10 +38,11 @@
</td>
<td class="ranking-page-table__column">
<div class="ranking-page-table__user-link">
@include('objects._flag_country', [
'country' => $score->user->country,
'modifiers' => 'medium',
])
<span class="ranking-page-table__flags">
@include('objects._flag_country', [
'country' => $countries->byCode($score->user->country_acronym),
])
</span>
<a
href="{{ route('users.show', ['user' => $score->user_id, 'mode' => $mode ?? null]) }}"
class="ranking-page-table__user-link-text js-usercard"
Expand Down
12 changes: 8 additions & 4 deletions resources/views/rankings/_spotlight_rankings_table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,21 @@
</tr>
</thead>
<tbody>
@php
$countries = app('countries');
@endphp
@foreach ($scores as $index => $score)
<tr class="ranking-page-table__row{{$score->user->isActive() ? '' : ' ranking-page-table__row--inactive'}}">
<td class="ranking-page-table__column ranking-page-table__column--rank">
#{{ $index + 1 }}
</td>
<td class="ranking-page-table__column">
<div class="ranking-page-table__user-link">
@include('objects._flag_country', [
'country' => $score->user->country,
'modifiers' => 'medium',
])
<span class="ranking-page-table__flags">
@include('objects._flag_country', [
'country' => $countries->byCode($score->user->country_acronym),
])
</span>
<a
href="{{ route('users.show', ['user' => $score->user_id, 'mode' => $mode]) }}"
class="ranking-page-table__user-link-text js-usercard"
Expand Down
17 changes: 11 additions & 6 deletions resources/views/rankings/country.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@
</tr>
</thead>
<tbody>
@php
$countries = app('countries');
@endphp
@foreach ($scores as $index => $score)
@php
$country = $countries->byCode($score->country_code);
@endphp
<tr class="ranking-page-table__row">
<td class="ranking-page-table__column ranking-page-table__column--rank">
#{{ $scores->firstItem() + $index }}
Expand All @@ -39,14 +45,13 @@
href="{{route('rankings', [
'mode' => $mode,
'type' => 'performance',
'country' => $score->country->acronym,
'country' => $country->getKey(),
])}}">
@include('objects._flag_country', [
'country' => $score->country->acronym,
'modifiers' => 'medium',
])
<span class="ranking-page-table__flags">
@include('objects._flag_country', ['country' => $country])
</span>
<span class="ranking-page-table__country-link-text">
{{ $score->country->name }}
{{ $country->name }}
</span>
</a>
</div>
Expand Down
12 changes: 8 additions & 4 deletions resources/views/rankings/kudosu.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,21 @@
</tr>
</thead>
<tbody>
@php
$countries = app('countries');
@endphp
@foreach ($scores as $index => $user)
<tr class="{{ class_with_modifiers('ranking-page-table__row', ['inactive' => !$user->isActive()]) }}">
<td class="ranking-page-table__column ranking-page-table__column--rank">
#{{ i18n_number_format($index + $firstScoreRank) }}
</td>
<td class="ranking-page-table__column">
<div class="ranking-page-table__user-link">
@include('objects._flag_country', [
'country' => $user->country_acronym,
'modifiers' => 'medium',
])
<span class="ranking-page-table__flags">
@include('objects._flag_country', [
'country' => $countries->byCode($user->country_acronym),
])
</span>
{!! link_to_user($user, null, '', ['ranking-page-table__user-link-text']) !!}
</div>
</td>
Expand Down
31 changes: 18 additions & 13 deletions resources/views/rankings/performance.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
</tr>
</thead>
<tbody>
@php
$countries = app('countries');
@endphp
@foreach ($scores as $index => $score)
<tr class="ranking-page-table__row{{$score->user->isActive() ? '' : ' ranking-page-table__row--inactive'}}">
<td class="ranking-page-table__column ranking-page-table__column--rank">
Expand Down Expand Up @@ -108,19 +111,21 @@ class="{{ class_with_modifiers('ranking-page-table__column', 'rank-change-icon',
@endif
<td class="ranking-page-table__column">
<div class="ranking-page-table__user-link">
<a
href="{{ route('rankings', [
'mode' => $mode,
'type' => 'performance',
'country' => $score->user->country->acronym,
'variant' => $variant,
]) }}"
>
@include('objects._flag_country', [
'country' => $score->user->country,
'modifiers' => 'medium',
])
</a>
<span class="ranking-page-table__flags">
<a
class="u-contents"
href="{{ route('rankings', [
'mode' => $mode,
'type' => 'performance',
'country' => $score->user->country_acronym,
'variant' => $variant,
]) }}"
>
@include('objects._flag_country', [
'country' => $countries->byCode($score->user->country_acronym),
])
</a>
</span>
<a
href="{{ route('users.show', ['user' => $score->user_id, 'mode' => $mode]) }}"
class="ranking-page-table__user-link-text js-usercard"
Expand Down
20 changes: 14 additions & 6 deletions resources/views/rankings/score.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,27 @@
</tr>
</thead>
<tbody>
@php
$countries = app('countries');
@endphp
@foreach ($scores as $index => $score)
<tr class="ranking-page-table__row{{$score->user->isActive() ? '' : ' ranking-page-table__row--inactive'}}">
<td class="ranking-page-table__column ranking-page-table__column--rank">
#{{ $scores->firstItem() + $index }}
</td>
<td class="ranking-page-table__column">
<div class="ranking-page-table__user-link">
<a href="{{route('rankings', ['mode' => $mode, 'type' => 'performance', 'country' => $score->user->country->acronym])}}">
@include('objects._flag_country', [
'country' => $score->user->country,
'modifiers' => 'medium',
])
</a>
<span class="ranking-page-table__flags">
<a href="{{ route('rankings', [
'country' => $score->user->country_acronym,
'mode' => $mode,
'type' => 'performance',
]) }}">
@include('objects._flag_country', [
'country' => $countries->byCode($score->user->country_acronym),
])
</a>
</span>
<a
href="{{ route('users.show', ['user' => $score->user_id, 'mode' => $mode]) }}"
class="ranking-page-table__user-link-text js-usercard"
Expand Down

0 comments on commit 34535b4

Please sign in to comment.