Skip to content

Commit 3fd3c35

Browse files
authored
Merge pull request ppy#11073 from nanaya/rankings-route
Combine ranking url generation and order constant
2 parents 062cf8f + c191ef0 commit 3fd3c35

File tree

6 files changed

+39
-37
lines changed

6 files changed

+39
-37
lines changed

app/Http/Controllers/RankingController.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ class RankingController extends Controller
2727
private $params;
2828
private $friendsOnly;
2929

30-
const PAGE_SIZE = 50;
3130
const MAX_RESULTS = 10000;
31+
const PAGE_SIZE = 50;
3232
const RANKING_TYPES = ['performance', 'charts', 'score', 'country'];
3333
const SPOTLIGHT_TYPES = ['charts'];
34+
// in display order
35+
const TYPES = ['performance', 'score', 'country', 'multiplayer', 'seasons', 'charts', 'kudosu'];
3436

3537
public function __construct()
3638
{
@@ -103,6 +105,26 @@ public function __construct()
103105
}, ['except' => ['kudosu']]);
104106
}
105107

108+
public static function url(
109+
string $type,
110+
string $rulesetName,
111+
?Country $country = null,
112+
?Spotlight $spotlight = null,
113+
): string {
114+
return match ($type) {
115+
'country' => route('rankings', ['mode' => $rulesetName, 'type' => $type]),
116+
'kudosu' => route('rankings.kudosu'),
117+
'multiplayer' => route('multiplayer.rooms.show', ['room' => 'latest']),
118+
'seasons' => route('seasons.show', ['season' => 'latest']),
119+
default => route('rankings', [
120+
'country' => $country !== null && $type === 'performance' ? $country->getKey() : null,
121+
'mode' => $rulesetName,
122+
'spotlight' => $spotlight !== null && $type === 'charts' ? $spotlight->getKey() : null,
123+
'type' => $type,
124+
]),
125+
};
126+
}
127+
106128
/**
107129
* Get Ranking
108130
*

app/helpers.php

+4-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// See the LICENCE file in the repository root for full licence text.
55

66
use App\Exceptions\FastImagesizeFetchException;
7+
use App\Http\Controllers\RankingController;
78
use App\Libraries\Base64Url;
89
use App\Libraries\LocaleMeta;
910
use App\Models\LoginAttempt;
@@ -1131,15 +1132,9 @@ function nav_links()
11311132
'page_title.main.artists_controller._' => route('artists.index'),
11321133
'page_title.main.beatmap_packs_controller._' => route('packs.index'),
11331134
];
1134-
$links['rankings'] = [
1135-
'rankings.type.performance' => route('rankings', ['mode' => $defaultMode, 'type' => 'performance']),
1136-
'rankings.type.score' => route('rankings', ['mode' => $defaultMode, 'type' => 'score']),
1137-
'rankings.type.country' => route('rankings', ['mode' => $defaultMode, 'type' => 'country']),
1138-
'rankings.type.multiplayer' => route('multiplayer.rooms.show', ['room' => 'latest']),
1139-
'rankings.type.seasons' => route('seasons.show', ['season' => 'latest']),
1140-
'rankings.type.charts' => route('rankings', ['mode' => $defaultMode, 'type' => 'charts']),
1141-
'layout.menu.rankings.kudosu' => route('rankings.kudosu'),
1142-
];
1135+
foreach (RankingController::TYPES as $rankingType) {
1136+
$links['rankings']["rankings.type.{$rankingType}"] = RankingController::url($rankingType, $defaultMode);
1137+
}
11431138
$links['community'] = [
11441139
'page_title.forum._' => route('forum.forums.index'),
11451140
'page_title.main.chat_controller._' => route('chat.index'),

resources/lang/en/layout.php

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
],
8787
'rankings' => [
8888
'_' => 'rankings',
89-
'kudosu' => 'kudosu',
9089
],
9190
'store' => [
9291
'_' => 'store',

resources/views/multiplayer/rooms/show.blade.php

-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
$selectOptionTransformer = new SelectOptionTransformer();
99
@endphp
1010
@extends('rankings.index', [
11-
'country' => null,
1211
'hasFilter' => false,
1312
'hasMode' => false,
1413
'hasPager' => true,
15-
'spotlight' => null,
1614
'titlePrepend' => osu_trans('rankings.type.multiplayer').': '.$room->name,
1715
'type' => 'multiplayer',
1816
])

resources/views/rankings/_mode_selector.blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<li>
99
<a
1010
class="{{ class_with_modifiers('game-mode-link', ['active' => $mode === $tab ]) }}"
11-
href="{{ $route($tab, $type) }}"
11+
href="{{ $rankingUrl($type, $tab) }}"
1212
>
1313
<span
1414
class="fal fa-extra-mode-{{ $tab }}"

resources/views/rankings/index.blade.php

+11-23
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,25 @@
33
See the LICENCE file in the repository root for full licence text.
44
--}}
55
@php
6+
use App\Http\Controllers\RankingController;
7+
68
$mode ??= default_mode();
7-
$selectorParams = [
8-
'type' => $type,
9-
'mode' => $mode,
10-
'route' => fn ($routeMode, $routeType) => (
11-
match ($routeType) {
12-
'country' => route('rankings', ['mode' => $routeMode, 'type' => $routeType]),
13-
'multiplayer' => route('multiplayer.rooms.show', ['room' => 'latest']),
14-
'seasons' => route('seasons.show', ['season' => 'latest']),
15-
'kudosu' => route('rankings.kudosu'),
16-
default => trim(route('rankings', [
17-
'mode' => $routeMode,
18-
'type' => $routeType,
19-
'spotlight' => $routeType === 'charts' ? $spotlight ?? null : null,
20-
'country' => $routeType === 'performance' ? ($country['acronym'] ?? null) : null,
21-
]), '?')
22-
}
23-
)
24-
];
9+
$country ??= null;
10+
$spotlight ??= null;
11+
$rankingUrl = fn (string $type, string $rulesetName) =>
12+
RankingController::url($type, $rulesetName, $country, $spotlight);
2513
2614
$links = [];
27-
foreach (['performance', 'score', 'country', 'multiplayer', 'seasons', 'charts', 'kudosu'] as $tab) {
15+
foreach (RankingController::TYPES as $tab) {
2816
$links[] = [
2917
'active' => $tab === $type,
3018
'title' => osu_trans("rankings.type.{$tab}"),
31-
'url' => $selectorParams['route']($mode, $tab),
19+
'url' => $rankingUrl($tab, $mode),
3220
];
3321
}
3422
35-
$hasMode = $hasMode ?? true;
36-
$hasScores = $hasScores ?? true;
23+
$hasMode ??= true;
24+
$hasScores ??= true;
3725
@endphp
3826

3927
@extends('master', ['titlePrepend' => $titlePrepend ?? osu_trans("rankings.type.{$type}")])
@@ -45,7 +33,7 @@
4533
]])
4634
@slot('linksAppend')
4735
@if($hasMode)
48-
@include('rankings._mode_selector', $selectorParams)
36+
@include('rankings._mode_selector')
4937
@endif
5038

5139
@yield('additionalHeaderLinks')

0 commit comments

Comments
 (0)