Skip to content

Commit

Permalink
Merge pull request #10677 from nanaya/multibanner
Browse files Browse the repository at this point in the history
Support showing multiple tournament banners
  • Loading branch information
notbakaneko authored Oct 25, 2023
2 parents e7ac43b + a327a39 commit 594ca46
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 7 deletions.
23 changes: 23 additions & 0 deletions app/Models/ProfileBanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;

/**
* @property int $banner_id
* @property Country $country
Expand Down Expand Up @@ -47,6 +49,27 @@ public function macroActive()
};
}

public function scopeActiveOnly(Builder $query): Builder
{
$currentTournamentId = config('osu.tournament_banner.current.id');
if ($currentTournamentId !== null) {
$mayHaveTournamentBanner = true;
$query->where('tournament_id', $currentTournamentId);
}
$previousTournamentId = config('osu.tournament_banner.previous.id');
if ($previousTournamentId !== null) {
$mayHaveTournamentBanner = true;
$query->orWhere(fn ($q) => $q->where([
'tournament_id' => $previousTournamentId,
'country_acronym' => config('osu.tournament_banner.previous.winner_id'),
]));
}

return $mayHaveTournamentBanner ?? false
? $query
: $query->none();
}

public function image()
{
$period = $this->period();
Expand Down
10 changes: 10 additions & 0 deletions app/Transformers/UserCompactTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class UserCompactTransformer extends TransformerAbstract

const PROFILE_HEADER_INCLUDES = [
'active_tournament_banner',
'active_tournament_banners',
'badges',
'comments_count',
'follower_count',
Expand All @@ -47,6 +48,7 @@ class UserCompactTransformer extends TransformerAbstract
protected array $availableIncludes = [
'account_history',
'active_tournament_banner',
'active_tournament_banners',
'badges',
'beatmap_playcounts_count',
'blocks',
Expand Down Expand Up @@ -154,6 +156,14 @@ public function includeActiveTournamentBanner(User $user)
: $this->item($banner, new ProfileBannerTransformer());
}

public function includeActiveTournamentBanners(User $user)
{
return $this->collection(
$user->profileBanners()->activeOnly()->orderBy('banner_id')->get(),
new ProfileBannerTransformer(),
);
}

public function includeBadges(User $user)
{
return $this->collection(
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/profile-tournament-banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { route } from 'laroute';
import * as React from 'react';

interface Props {
banner?: ProfileBannerJson | null;
banner: ProfileBannerJson;
}

export default function ProfileTournamentBanner({ banner }: Props) {
if (banner == null || banner.image == null) return null;
if (banner.image == null) return null;

return (
<a
Expand Down
4 changes: 3 additions & 1 deletion resources/js/interfaces/user-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import UserStatisticsRulesetsJson from './user-statistics-rulesets-json';
interface UserJsonAvailableIncludes {
account_history: UserAccountHistoryJson[];
active_tournament_banner: ProfileBannerJson | null;
active_tournament_banners: ProfileBannerJson[];
badges: UserBadgeJson[];
beatmap_playcounts_count: number;
blocks: UserRelationJson[];
Expand Down Expand Up @@ -85,7 +86,8 @@ interface UserJsonDefaultAttributes {
}

export type ProfileHeaderIncludes =
'active_tournament_banner'
| 'active_tournament_banner'
| 'active_tournament_banners'
| 'badges'
| 'comments_count'
| 'follower_count'
Expand Down
4 changes: 3 additions & 1 deletion resources/js/modding-profile/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ export default class Main extends React.Component<Props> {
<Badges badges={this.props.user.badges} />
{!this.props.user.is_bot && (
<>
<ProfileTournamentBanner banner={this.props.user.active_tournament_banner} />
{this.props.user.active_tournament_banners.map((banner) => (
<ProfileTournamentBanner key={banner.id} banner={banner} />
))}
<div className='profile-detail'>
<Stats user={this.props.user} />
</div>
Expand Down
4 changes: 3 additions & 1 deletion resources/js/profile-page/detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export default class Detail extends React.Component<Props> {
user={this.user}
/>

<ProfileTournamentBanner banner={this.user.active_tournament_banner} />
{this.user.active_tournament_banners.map((banner) => (
<ProfileTournamentBanner key={banner.id} banner={banner} />
))}

<Badges badges={this.user.badges} />

Expand Down
7 changes: 5 additions & 2 deletions resources/js/user-multiplayer-index/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ProfileTournamentBanner from 'components/profile-tournament-banner';
import RoomList from 'components/room-list';
import UserProfileContainer from 'components/user-profile-container';
import UserExtendedJson from 'interfaces/user-extended-json';
import { ProfileHeaderIncludes } from 'interfaces/user-json';
import { MultiplayerTypeGroup } from 'interfaces/user-multiplayer-history-json';
import { route } from 'laroute';
import core from 'osu-core-singleton';
Expand All @@ -20,7 +21,7 @@ import { trans } from 'utils/lang';
interface Props {
store: RoomListStore;
typeGroup: MultiplayerTypeGroup;
user: UserExtendedJson;
user: UserExtendedJson & Required<Pick<UserExtendedJson, ProfileHeaderIncludes>>;
}

export default function Main(props: Props) {
Expand All @@ -37,7 +38,9 @@ export default function Main(props: Props) {
<div className='osu-page osu-page--generic-compact'>
<Cover coverUrl={props.user.cover.url} currentMode={props.user.playmode} modifiers='multiplayer' user={props.user} />

<ProfileTournamentBanner banner={props.user.active_tournament_banner} />
{props.user.active_tournament_banners.map((banner) => (
<ProfileTournamentBanner key={banner.id} banner={banner} />
))}

<Badges badges={props.user.badges} modifiers='multiplayer' />

Expand Down

0 comments on commit 594ca46

Please sign in to comment.