Skip to content

Commit d6c884b

Browse files
committed
update friend button to handle being blocked
1 parent 98d4121 commit d6c884b

5 files changed

Lines changed: 20 additions & 2 deletions

File tree

app/Http/Controllers/UsersController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,7 @@ private function showUserIncludes()
956956
...UserTransformer::PROFILE_HEADER_INCLUDES,
957957
'account_history',
958958
'current_season_stats',
959+
'current_user_attributes',
959960
'daily_challenge_user_stats',
960961
'matchmaking_stats.pool',
961962
'page',

app/Transformers/UserCompactTransformer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class UserCompactTransformer extends TransformerAbstract
6262
'country',
6363
'cover',
6464
'current_season_stats',
65+
'current_user_attributes',
6566
'daily_challenge_user_stats',
6667
'favourite_beatmapset_count',
6768
'follow_user_mapping',
@@ -244,6 +245,14 @@ public function includeCurrentSeasonStats(User $user): Primitive
244245
: $this->primitive((new SeasonStats($user, $season))->get());
245246
}
246247

248+
public function includeCurrentUserAttributes(User $user): Primitive
249+
{
250+
$currentUser = \Auth::user();
251+
return $this->primitive($currentUser === null ? null : [
252+
'has_blocked' => $user->hasBlocked($currentUser),
253+
]);
254+
}
255+
247256
public function includeDailyChallengeUserStats(User $user)
248257
{
249258
return $this->item(

resources/js/components/friend-button.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const bn = 'user-action-button';
1919

2020
interface Props {
2121
alwaysVisible: boolean;
22-
container?: HTMLElement;
22+
blocked?: boolean;
2323
followers?: number;
2424
modifiers?: Modifiers;
2525
userId: number;
@@ -74,6 +74,10 @@ export default class FriendButton extends React.Component<Props> {
7474

7575
@computed
7676
private get title() {
77+
if (this.props.blocked) {
78+
return trans('friends.blocked');
79+
}
80+
7781
if (!this.isVisible) {
7882
return trans('friends.buttons.disabled');
7983
}
@@ -119,7 +123,7 @@ export default class FriendButton extends React.Component<Props> {
119123
: (this.friend.mutual ? 'mutual' : 'friend');
120124

121125
const blockClass = classWithModifiers(bn, this.props.modifiers, extraModifier);
122-
const disabled = !this.isVisible || this.loading || this.isFriendLimit && this.friend == null;
126+
const disabled = !this.isVisible || this.loading || this.props.blocked || this.isFriendLimit && this.friend == null;
123127

124128
return (
125129
<div title={this.title}>

resources/js/interfaces/user-json.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ interface UserJsonAvailableIncludes {
3232
country: CountryJson | null;
3333
cover: UserCoverJson;
3434
current_season_stats: SeasonStatsJson | null;
35+
current_user_attributes: {
36+
has_blocked: boolean;
37+
} | null;
3538
daily_challenge_user_stats: DailyChallengeUserStatsJson;
3639
favourite_beatmapset_count: number;
3740
follow_user_mapping: number[];

resources/js/profile-page/detail-bar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default class DetailBar extends React.Component<Props> {
2929
<div className='profile-detail-bar'>
3030
<FriendButton
3131
alwaysVisible
32+
blocked={this.props.user.current_user_attributes?.has_blocked}
3233
followers={this.props.user.follower_count}
3334
modifiers='profile-page'
3435
userId={this.props.user.id}

0 commit comments

Comments
 (0)