Skip to content

Commit

Permalink
Merge pull request #11505 from nanaya/user-card-api
Browse files Browse the repository at this point in the history
Remove redundant user card endpoint
  • Loading branch information
notbakaneko authored Sep 26, 2024
2 parents a08ae89 + b1c327b commit 9368487
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 80 deletions.
13 changes: 0 additions & 13 deletions app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
namespace App\Http\Controllers;

use App\Exceptions\ModelNotSavedException;
use App\Exceptions\UserProfilePageLookupException;
use App\Exceptions\ValidationException;
use App\Http\Middleware\RequestCost;
use App\Libraries\ClientCheck;
Expand All @@ -24,7 +23,6 @@
use App\Models\Solo\Score as SoloScore;
use App\Models\User;
use App\Models\UserAccountHistory;
use App\Models\UserNotFound;
use App\Transformers\CurrentUserTransformer;
use App\Transformers\ScoreTransformer;
use App\Transformers\UserCompactTransformer;
Expand Down Expand Up @@ -114,17 +112,6 @@ private static function storeClientDisabledError()
], 403);
}

public function card($id)
{
try {
$user = FindForProfilePage::find($id, null, false);
} catch (UserProfilePageLookupException $e) {
$user = UserNotFound::instance();
}

return json_item($user, 'UserCompact', UserCompactTransformer::CARD_INCLUDES);
}

public function create()
{
if (!$GLOBALS['cfg']['osu']['user']['registration_mode']['web']) {
Expand Down
41 changes: 0 additions & 41 deletions app/Models/UserNotFound.php

This file was deleted.

17 changes: 4 additions & 13 deletions resources/js/components/user-card-tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

import Reportable from 'interfaces/reportable';
import UserJson from 'interfaces/user-json';
import { route } from 'laroute';
import * as _ from 'lodash';
import { userNotFoundJson } from 'models/user';
import core from 'osu-core-singleton';
import * as React from 'react';
import { unmountComponentAtNode } from 'react-dom';
import { renderToStaticMarkup } from 'react-dom/server';
import { activeKeyDidChange as contextActiveKeyDidChange, ContainerContext, KeyContext, State as ActiveKeyState } from 'stateful-activation-context';
import { TooltipContext } from 'tooltip-context';
import { presence } from 'utils/string';
import { apiLookupUsers } from 'utils/user';
import { UserCard } from './user-card';

interface Props {
Expand Down Expand Up @@ -224,21 +225,11 @@ export class UserCardTooltip extends React.PureComponent<Props, State> {
}

componentDidMount() {
this.getUser().then((user) => {
this.setState({ user });
apiLookupUsers([this.props.lookup]).done((response) => {
this.setState({ user: response.users[0] ?? userNotFoundJson });
});
}

getUser() {
const url = route('users.card', { user: this.props.lookup });

return $.ajax({
dataType: 'json',
type: 'GET',
url,
}) as JQuery.jqXHR<UserJson>;
}

render() {
const activated = this.state.activeKey === this.props.lookup;

Expand Down
13 changes: 7 additions & 6 deletions resources/js/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ export default class User {
}
}

const deletedUser = new User(-1);
export const deletedUser = new User(-1);
deletedUser.isDeleted = true;
deletedUser.username = trans('users.deleted');
Object.freeze(deletedUser);

const deletedUserJson = Object.freeze(deletedUser.toJson());
export const deletedUserJson = Object.freeze(deletedUser.toJson());

export {
deletedUser,
deletedUserJson,
};
const userNotFound = new User(-1);
userNotFound.username = trans('supporter_tag.user_search.not_found');
Object.freeze(userNotFound);

export const userNotFoundJson = Object.freeze(userNotFound.toJson());
7 changes: 1 addition & 6 deletions resources/js/store/store-supporter-tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import UserJson from 'interfaces/user-json';
import { debounce } from 'lodash';
import { action, autorun, computed, makeObservable, observable, runInAction } from 'mobx';
import { disposeOnUnmount, observer } from 'mobx-react';
import User from 'models/user';
import { userNotFoundJson } from 'models/user';
import core from 'osu-core-singleton';
import React from 'react';
import { onError } from 'utils/ajax';
Expand All @@ -22,11 +22,6 @@ const jsonId = 'json-store-supporter-tag';
const maxValue = 52;
const minValue = 4;

const userNotFound = new User(-1);
userNotFound.username = trans('supporter_tag.user_search.not_found');

const userNotFoundJson = Object.freeze(userNotFound.toJson());

interface Props {
maxMessageLength: number;
}
Expand Down
1 change: 0 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@
Route::post('users/store-web', 'UsersController@storeWeb')->name('users.store-web');

Route::group(['as' => 'users.', 'prefix' => 'users/{user}'], function () {
Route::get('card', 'UsersController@card')->name('card');
Route::get('extra-pages/{page}', 'UsersController@extraPages')->name('extra-page');
Route::put('page', 'UsersController@updatePage')->name('page');
Route::group(['namespace' => 'Users'], function () {
Expand Down

0 comments on commit 9368487

Please sign in to comment.